use of org.folio.rest.jaxrs.model.CompositePoLine.OrderFormat in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testPostOpenOrderInventoryUpdateWithOrderFormatOther.
@Test
@Disabled
// TODO must be fixed in scope of https://issues.folio.org/browse/MODORDERS-587
void testPostOpenOrderInventoryUpdateWithOrderFormatOther() throws Exception {
logger.info("=== Test POST Order By Id to change status of Order to Open - inventory interaction required only for first POL ===");
// Get Open Order
CompositePurchaseOrder reqData = getMockDraftOrder().mapTo(CompositePurchaseOrder.class);
MockServer.addMockTitles(reqData.getCompositePoLines());
// Make sure that mock po has 2 po lines
assertThat(reqData.getCompositePoLines(), hasSize(2));
// Make sure that mock po has the first PO line with 3 locations
assertThat(reqData.getCompositePoLines().get(0).getLocations(), hasSize(3));
// Make sure that Order moves to Open
reqData.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN);
// Prepare second POL
CompositePoLine secondPol = reqData.getCompositePoLines().get(1);
List<Location> secondPolLocations = secondPol.getLocations();
// MODORDERS-117 Setting OrderFormat to OTHER which means it behaves similar
// to Physical order
secondPol.setOrderFormat(CompositePoLine.OrderFormat.OTHER);
Physical physical = new Physical();
physical.setCreateInventory(CreateInventory.NONE);
secondPol.setPhysical(physical);
// Specify correct quantities for OTHER format
secondPol.getCost().setQuantityElectronic(0);
secondPol.getCost().setListUnitPriceElectronic(null);
secondPol.getCost().setListUnitPrice(10d);
secondPol.getCost().setQuantityPhysical(secondPolLocations.size());
secondPol.setEresource(null);
secondPolLocations.forEach(location -> {
location.setQuantityElectronic(0);
location.setQuantityPhysical(1);
});
LocalDate now = LocalDate.now();
final CompositePurchaseOrder resp = verifyPostResponse(COMPOSITE_ORDERS_PATH, JsonObject.mapFrom(reqData).toString(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID), APPLICATION_JSON, 201).as(CompositePurchaseOrder.class);
LocalDate dateOrdered = resp.getDateOrdered().toInstant().atZone(ZoneId.of(ZoneOffset.UTC.getId())).toLocalDate();
assertThat(dateOrdered.getMonth(), equalTo(now.getMonth()));
assertThat(dateOrdered.getYear(), equalTo(now.getYear()));
// Check that search of the existing instances and items was done for first PO line only
List<JsonObject> instancesSearches = getInstancesSearches();
List<JsonObject> holdingsSearches = getHoldingsSearches();
List<JsonObject> itemsSearches = getItemsSearches();
assertNotNull(instancesSearches);
assertNull(holdingsSearches);
assertNotNull(itemsSearches);
assertEquals(1, instancesSearches.size());
CompositePoLine respLine1 = resp.getCompositePoLines().get(0);
respLine1.getLocations().forEach(location -> {
assertNull(location.getLocationId());
assertNotNull(location.getHoldingId());
});
CompositePoLine respLine2 = resp.getCompositePoLines().get(1);
respLine2.getLocations().forEach(location -> {
assertNotNull(location.getLocationId());
assertNull(location.getHoldingId());
});
List<JsonObject> createdInstances = getCreatedInstances();
assertEquals(1, createdInstances.size(), "Quantity of created instance must be equal of line, if create inventory include instance");
assertNotNull("Line must be connected to instance, if create inventory include instance", respLine1.getInstanceId());
assertNotNull("Line must be connected to instance, if create inventory include instance", respLine2.getInstanceId());
List<JsonObject> createdHoldings = getCreatedHoldings();
assertEquals(3, createdHoldings.size(), "Quantity of created instance must be depended of quantity in the locations and create inventory include holding");
verifyHoldingsCreated(3, createdHoldings, respLine1);
verifyHoldingsCreated(0, createdHoldings, respLine2);
// All existing and created items
List<JsonObject> items = joinExistingAndNewItems();
verifyItemsCreated(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, 4, items, respLine1);
verifyItemsCreated(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, 0, items, respLine2);
List<JsonObject> createdPieces = getCreatedPieces();
createdPieces.stream().map(json -> json.mapTo(Piece.class)).filter(piece -> !OTHER.equals(piece.getFormat())).forEach(piece -> {
assertNull(piece.getLocationId());
assertNotNull(piece.getHoldingId());
});
createdPieces.stream().map(json -> json.mapTo(Piece.class)).filter(piece -> OTHER.equals(piece.getFormat())).forEach(piece -> {
assertNotNull(piece.getLocationId());
assertNull(piece.getHoldingId());
});
verifyOpenOrderPiecesCreated(items, resp.getCompositePoLines(), createdPieces, 4);
verifyCalculatedData(resp);
}
use of org.folio.rest.jaxrs.model.CompositePoLine.OrderFormat in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testPostOpenOrderInventoryUpdateOnlyForFirstPOL.
@Test
void testPostOpenOrderInventoryUpdateOnlyForFirstPOL() throws Exception {
logger.info("=== Test POST Order By Id to change status of Order to Open - inventory interaction required only for first POL ===");
// Get Open Order
CompositePurchaseOrder reqData = getMockDraftOrder().mapTo(CompositePurchaseOrder.class);
MockServer.addMockTitles(reqData.getCompositePoLines());
// Make sure that mock po has 2 po lines
assertThat(reqData.getCompositePoLines(), hasSize(2));
// Make sure that mock po has the first PO line with 3 locations
assertThat(reqData.getCompositePoLines().get(0).getLocations(), hasSize(3));
// Make sure that Order moves to Open
reqData.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN);
// Prepare second POL
CompositePoLine secondPol = reqData.getCompositePoLines().get(1);
// MODORDERS-117 Setting OrderFormat to OTHER which means create nothing in inventory for the second PO Line
secondPol.setOrderFormat(CompositePoLine.OrderFormat.OTHER);
// Specify correct quantities for OTHER format
secondPol.getCost().setQuantityElectronic(0);
secondPol.getCost().setListUnitPriceElectronic(null);
secondPol.getCost().setListUnitPrice(10d);
secondPol.getCost().setQuantityPhysical(3);
secondPol.setPhysical(new Physical());
secondPol.getPhysical().setCreateInventory(Physical.CreateInventory.NONE);
secondPol.setEresource(null);
secondPol.getLocations().clear();
LocalDate now = LocalDate.now();
final CompositePurchaseOrder resp = verifyPostResponse(COMPOSITE_ORDERS_PATH, JsonObject.mapFrom(reqData).toString(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID), APPLICATION_JSON, 201).as(CompositePurchaseOrder.class);
LocalDate dateOrdered = resp.getDateOrdered().toInstant().atZone(ZoneId.of(ZoneOffset.UTC.getId())).toLocalDate();
assertThat(dateOrdered.getMonth(), equalTo(now.getMonth()));
assertThat(dateOrdered.getYear(), equalTo(now.getYear()));
// Check that search of the existing instances and items was done for first PO line only
List<JsonObject> instancesSearches = getInstancesSearches();
List<JsonObject> holdingsSearches = getHoldingsSearches();
List<JsonObject> itemsSearches = getItemsSearches();
assertNotNull(instancesSearches);
assertNull(holdingsSearches);
assertNotNull(itemsSearches);
assertEquals(1, instancesSearches.size());
CompositePoLine respLine1 = resp.getCompositePoLines().get(0);
respLine1.getLocations().forEach(location -> {
assertNull(location.getLocationId());
assertNotNull(location.getHoldingId());
});
CompositePoLine respLine2 = resp.getCompositePoLines().get(1);
respLine2.getLocations().forEach(location -> {
assertNull(location.getLocationId());
assertNull(location.getHoldingId());
});
List<JsonObject> createdInstances = getCreatedInstances();
assertEquals(1, createdInstances.size(), "Quantity of created instance must be equal of line, if create inventory include instance");
assertNotNull("Line must be connected to instance, if create inventory include instance", respLine1.getInstanceId());
assertNotNull("Line must be connected to instance, if create inventory include instance", respLine2.getInstanceId());
List<JsonObject> createdHoldings = getCreatedHoldings();
assertEquals(3, createdHoldings.size(), "Quantity of created holding must be depended of quantity in the locations and create inventory include holding");
verifyHoldingsCreated(3, createdHoldings, respLine1);
verifyHoldingsCreated(0, createdHoldings, respLine2);
// All existing and created items
List<JsonObject> items = joinExistingAndNewItems();
verifyItemsCreated(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, 4, items, respLine1);
verifyItemsCreated(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, 0, items, respLine2);
List<JsonObject> createdPieces = getCreatedPieces();
createdPieces.stream().map(json -> json.mapTo(Piece.class)).filter(piece -> !OTHER.equals(piece.getFormat())).forEach(piece -> {
assertNull(piece.getLocationId());
assertNotNull(piece.getHoldingId());
});
createdPieces.stream().map(json -> json.mapTo(Piece.class)).filter(piece -> OTHER.equals(piece.getFormat())).forEach(piece -> {
assertNull(piece.getLocationId());
assertNull(piece.getHoldingId());
});
verifyOpenOrderPiecesCreated(items, resp.getCompositePoLines(), createdPieces, 0);
verifyCalculatedData(resp);
}
Aggregations