Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unit test for itemstock #109

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7279d5a
feat: initial commit
eschrewe Nov 29, 2023
b991afc
Merge branch 'refactor/merge_0.5.x_with_security_feat_branch' into fe…
eschrewe Nov 29, 2023
b21077d
feat: added itemstocktest
eschrewe Dec 1, 2023
e7d73d7
Merge branch 'refactor/migrate_to_edc_0.5.x' into feat/itemstock
eschrewe Dec 1, 2023
be348f6
fix: some fixes
eschrewe Dec 4, 2023
11840a1
fix: fixed itemstockservicetest
eschrewe Dec 4, 2023
825ac78
feat: added itemstocksamm and tests
eschrewe Dec 5, 2023
5ceb429
chore: added license headers
eschrewe Dec 5, 2023
0dea5e0
Merge branch 'main' into feat/itemstock
eschrewe Dec 5, 2023
65144e1
chore: edited commandlinerunner
eschrewe Dec 5, 2023
9f2147f
chore: updated dependencies
eschrewe Dec 5, 2023
76eaff8
chore: updated dependencies
eschrewe Dec 5, 2023
6074394
fix: removed esmf dependencies
eschrewe Dec 6, 2023
d9fd0a8
Merge branch 'main' into feat/itemstock
eschrewe Dec 6, 2023
36f19d5
Merge branch 'feat/itemstock' into feat/unittest_for_itemstock
eschrewe Dec 6, 2023
0046fa1
fix: some cleanup
eschrewe Dec 6, 2023
246346a
Merge branch 'feat/itemstock' into feat/unittest_for_itemstock
eschrewe Dec 6, 2023
7b7b561
fix: removed jsoncreator
eschrewe Dec 6, 2023
9d5e58d
Merge branch 'feat/itemstock' into feat/unittest_for_itemstock
eschrewe Dec 6, 2023
e75617c
chore: removed tests
eschrewe Dec 6, 2023
4028672
Merge branch 'feat/itemstock' into feat/unittest_for_itemstock
eschrewe Dec 6, 2023
dcc7e4b
feat: added tests
eschrewe Dec 6, 2023
3f44f45
chore: updated dependencies
eschrewe Dec 6, 2023
e6d7156
fix: itemstock now contains partner and material
eschrewe Dec 6, 2023
d177469
fix: edited license headers as ordered
eschrewe Dec 6, 2023
726d28f
fix: validation check generates more verbose output
eschrewe Dec 6, 2023
5a2fd2e
feat: current working status
eschrewe Dec 13, 2023
23c66ed
refactor: refactored itemstock and its variants
eschrewe Dec 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@
import org.eclipse.tractusx.puris.backend.stock.domain.model.*;
import org.eclipse.tractusx.puris.backend.stock.domain.model.measurement.MeasurementUnit;
import org.eclipse.tractusx.puris.backend.stock.logic.adapter.ProductStockSammMapper;
import org.eclipse.tractusx.puris.backend.stock.logic.dto.itemstocksamm.ItemUnitEnumeration;
import org.eclipse.tractusx.puris.backend.stock.logic.dto.samm.LocationIdTypeEnum;
import org.eclipse.tractusx.puris.backend.stock.logic.dto.samm.ProductStockSammDto;
import org.eclipse.tractusx.puris.backend.stock.logic.service.MaterialStockService;
import org.eclipse.tractusx.puris.backend.stock.logic.service.PartnerProductStockService;
import org.eclipse.tractusx.puris.backend.stock.logic.service.ProductStockRequestService;
import org.eclipse.tractusx.puris.backend.stock.logic.service.ProductStockService;
import org.eclipse.tractusx.puris.backend.stock.logic.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -70,6 +68,11 @@
@Autowired
private ProductStockService productStockService;

@Autowired
private MaterialItemStockService materialItemStockService;
@Autowired
private ReportedMaterialItemStockService reportedMaterialItemStockService;

@Autowired
private PartnerProductStockService partnerProductStockService;

Expand Down Expand Up @@ -113,7 +116,7 @@
*/
private void createOwnPartnerEntity() {
Partner mySelf;
if(variablesService.getOwnDefaultBpns()!= null && variablesService.getOwnDefaultBpns().length()!=0) {
if (variablesService.getOwnDefaultBpns() != null && variablesService.getOwnDefaultBpns().length() != 0) {
mySelf = new Partner(variablesService.getOwnName(),
variablesService.getEdcProtocolUrl(),
variablesService.getOwnBpnl(),
Expand All @@ -134,8 +137,8 @@
);
}
mySelf = partnerService.create(mySelf);
log.info("Successfully created own Partner Entity: " + (partnerService.findByBpnl(mySelf.getBpnl()) != null));

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning

Variable
mySelf
may be null at this access as suggested by
this
null guard.
if(mySelf != null) {
if (mySelf != null) {
log.info(mySelf.toString());
}
}
Expand Down Expand Up @@ -219,6 +222,34 @@
log.info("SAMM-DTO:\n" + objectMapper.writeValueAsString(productStockSammDto));

log.info("Own Street and Number: " + variablesService.getOwnDefaultStreetAndNumber());
Partner mySelf = partnerService.getOwnPartnerEntity();
var builder = MaterialItemStock.builder();
var materialItemStock = builder.partner(supplierPartner)
.material(semiconductorMaterial)
.lastUpdatedOnDateTime(new Date())
.locationBpna(mySelf.getSites().first().getAddresses().first().getBpna())
.locationBpns(mySelf.getSites().first().getBpns())
.measurementUnit(ItemUnitEnumeration.UNIT_PIECE)
.quantity(20)
.build();
var createdMaterialItemStock = materialItemStockService.create(materialItemStock);
log.info("Created MaterialItemStock: \n" + createdMaterialItemStock.toString());

var builder2 = ReportedMaterialItemStock.builder();
var reportedMaterialItemStock =
builder2
.material(semiconductorMaterial)
.partner(supplierPartner)
.lastUpdatedOnDateTime(new Date())
.locationBpns(supplierPartner.getSites().first().getBpns())
.locationBpna(supplierPartner.getSites().first().getAddresses().first().getBpna())
.measurementUnit(ItemUnitEnumeration.UNIT_PIECE)
.quantity(50)
.build();

var createdReportedMaterialItemStock = reportedMaterialItemStockService.create(reportedMaterialItemStock);
log.info("Created ReportedMaterialItemStock: \n" + createdReportedMaterialItemStock);

}

/**
Expand Down Expand Up @@ -266,7 +297,6 @@
"bpnl: %s", foundProductStocks));
}


/**
* creates a new customer Partner entity, stores it to
* the database and returns this entity.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (c) 2023 Volkswagen AG
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

package org.eclipse.tractusx.puris.backend.stock.domain.model;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Material;
import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Partner;
import org.eclipse.tractusx.puris.backend.stock.logic.dto.itemstocksamm.ItemUnitEnumeration;

import java.util.Date;
import java.util.UUID;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@SuperBuilder
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Entity
@ToString
public abstract class ItemStock {

static final String ORDER_ID_REGEX = "^[a-zA-Z0-9\\-\\.]{1,255}$";

@Id
@GeneratedValue
protected UUID uuid;

@ManyToOne()
@JoinColumn(name = "partner_uuid")
@ToString.Exclude
@NotNull
protected Partner partner;
@ManyToOne()
@JoinColumn(name = "material_ownMaterialNumber")
@ToString.Exclude
@NotNull
protected Material material;

protected double quantity;
@NotNull
protected ItemUnitEnumeration measurementUnit;
@NotNull
protected String locationBpna;
@NotNull
protected String locationBpns;
@NotNull
protected Date lastUpdatedOnDateTime;

protected boolean isBlocked;
@Pattern(regexp = ORDER_ID_REGEX)
protected String supplierOrderId;
@Pattern(regexp = ORDER_ID_REGEX)
protected String customerOrderId;
@Pattern(regexp = ORDER_ID_REGEX)
protected String customerOrderPositionId;

@ToString.Include
private String material_ownMaterialNumber(){
return material.getOwnMaterialNumber();
}

@ToString.Include
private String partner_partnerBpnl(){
return partner.getBpnl();
}

}



Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.eclipse.tractusx.puris.backend.stock.domain.model;

import jakarta.persistence.Entity;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

@Entity
@SuperBuilder
@NoArgsConstructor
@ToString(callSuper = true)
public class MaterialItemStock extends ItemStock {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.eclipse.tractusx.puris.backend.stock.domain.model;

import jakarta.persistence.Entity;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

@Entity
@SuperBuilder
@NoArgsConstructor
@ToString(callSuper = true)
public class ProductItemStock extends ItemStock {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.eclipse.tractusx.puris.backend.stock.domain.model;

import jakarta.persistence.Entity;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

@Entity
@SuperBuilder
@NoArgsConstructor
@ToString(callSuper = true)
public class ReportedMaterialItemStock extends ItemStock {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.eclipse.tractusx.puris.backend.stock.domain.model;

import jakarta.persistence.Entity;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

@Entity
@SuperBuilder
@NoArgsConstructor
@ToString(callSuper = true)
public class ReportedProductItemStock extends ItemStock {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.eclipse.tractusx.puris.backend.stock.domain.repository;

import org.eclipse.tractusx.puris.backend.stock.domain.model.MaterialItemStock;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.UUID;
@Repository
public interface MaterialItemStockRepository extends JpaRepository<MaterialItemStock, UUID> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.eclipse.tractusx.puris.backend.stock.domain.repository;

import org.eclipse.tractusx.puris.backend.stock.domain.model.ProductItemStock;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.UUID;
@Repository
public interface ProductItemStockRepository extends JpaRepository<ProductItemStock, UUID> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.eclipse.tractusx.puris.backend.stock.domain.repository;

import org.eclipse.tractusx.puris.backend.stock.domain.model.ReportedMaterialItemStock;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.UUID;
@Repository
public interface ReportedMaterialItemStockRepository extends JpaRepository<ReportedMaterialItemStock, UUID> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.eclipse.tractusx.puris.backend.stock.domain.repository;

import org.eclipse.tractusx.puris.backend.stock.domain.model.ReportedProductItemStock;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.UUID;
@Repository
public interface ReportedProductItemStockRepository extends JpaRepository<ReportedProductItemStock, UUID> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2023 Volkswagen AG
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.eclipse.tractusx.puris.backend.stock.logic.dto.itemstocksamm;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.Getter;
import lombok.Setter;

import java.util.Objects;

/**
* Generated class for Stock Allocated to a Partner. This is the quantity of
* items on stock at a location. A stock can either be - from a certain supplier
* and ready to be consumed by a customer or - from a supplier and ready to be
* shipped to a certain customer.
*
* In case of stocks "from a supplier ready to be shipped to a certain
* customer", the stock may refer to an order position of a customer. This stock
* consists only of the good-finished items.
*/
@Getter
@Setter
public class AllocatedStock {

@NotNull
private ItemQuantityEntity quantityOnAllocatedStock;

@NotNull
@Pattern(regexp = "^BPNS[0-9]{8}[a-zA-Z0-9]{4}$")

private String stockLocationBPNS;

@NotNull
private Boolean isBlocked;

@NotNull
@Pattern(regexp = "^BPNA[0-9]{8}[a-zA-Z0-9]{4}$")

private String stockLocationBPNA;

@JsonCreator
public AllocatedStock(@JsonProperty(value = "quantityOnAllocatedStock") ItemQuantityEntity quantityOnAllocatedStock,
@JsonProperty(value = "stockLocationBPNS") String stockLocationBPNS,
@JsonProperty(value = "isBlocked") Boolean isBlocked,
@JsonProperty(value = "stockLocationBPNA") String stockLocationBPNA) {
super(

);
this.quantityOnAllocatedStock = quantityOnAllocatedStock;
this.stockLocationBPNS = stockLocationBPNS;
this.isBlocked = isBlocked;
this.stockLocationBPNA = stockLocationBPNA;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

final AllocatedStock that = (AllocatedStock) o;
return Objects.equals(quantityOnAllocatedStock, that.quantityOnAllocatedStock)
&& Objects.equals(stockLocationBPNS, that.stockLocationBPNS)
&& Objects.equals(isBlocked, that.isBlocked)
&& Objects.equals(stockLocationBPNA, that.stockLocationBPNA);
}

@Override
public int hashCode() {
return Objects.hash(quantityOnAllocatedStock, stockLocationBPNS, isBlocked, stockLocationBPNA);
}
}
Loading
Loading