use of org.folio.TestConstants.ID_FOR_INTERNAL_SERVER_ERROR in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testPutOrdersByIdToChangeStatusToOpenButWithErrorCreatingItemsForSecondPOL.
@Test
void testPutOrdersByIdToChangeStatusToOpenButWithErrorCreatingItemsForSecondPOL() throws Exception {
logger.info("=== Test Put Order By Id to change Order's status to Open - Inventory errors expected on items creation for second POL ===");
/*============== Preparation ==============*/
// Get Open Order
CompositePurchaseOrder reqData = getMockDraftOrder().mapTo(CompositePurchaseOrder.class);
reqData.setId(ID_FOR_PRINT_MONOGRAPH_ORDER);
reqData.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN);
MockServer.addMockTitles(reqData.getCompositePoLines());
int polCount = reqData.getCompositePoLines().size();
// Make sure that mock PO has 2 lines
assertThat(reqData.getCompositePoLines(), hasSize(2));
// Make sure that inventory interaction is expected for each PO line
for (CompositePoLine pol : reqData.getCompositePoLines()) {
assertTrue(calculateInventoryItemsQuantity(pol) > 0);
}
// Set location ids to one which emulates item creation failure
CompositePoLine line1 = reqData.getCompositePoLines().get(0);
CompositePoLine line2 = reqData.getCompositePoLines().get(1);
reqData.getCompositePoLines().get(1).getLocations().forEach(location -> location.withLocationId(ID_FOR_INTERNAL_SERVER_ERROR));
reqData.getCompositePoLines().get(1).getLocations().get(0).setLocationId(UUID.randomUUID().toString());
preparePiecesForCompositePo(reqData);
String path = String.format(COMPOSITE_ORDERS_BY_ID_PATH, reqData.getId());
/*============== Assert result ==============*/
// Server Error expected as a result because not all items created
verifyPut(path, JsonObject.mapFrom(reqData), APPLICATION_JSON, 500);
List<JsonObject> respOrder = MockServer.serverRqRs.get(PURCHASE_ORDER_STORAGE, HttpMethod.GET);
CompositePurchaseOrder compPo = respOrder.get(0).mapTo(CompositePurchaseOrder.class);
List<JsonObject> respLines = MockServer.serverRqRs.get(PO_LINES_STORAGE, HttpMethod.PUT);
CompositePoLine respLine1 = respLines.stream().filter(line -> line.getString(ID).equals(line1.getId())).peek(line -> line.remove("reportingCodes")).map(line -> line.mapTo(CompositePoLine.class)).distinct().findAny().get();
CompositePoLine respLine2 = respLines.stream().filter(line -> line.getString(ID).equals(line2.getId())).peek(line -> line.remove("reportingCodes")).map(line -> line.mapTo(CompositePoLine.class)).findAny().get();
compPo.setCompositePoLines(List.of(respLine1, respLine2));
// Check that search of the existing instances and items was done for each PO line
List<JsonObject> instancesSearches = getInstancesSearches();
assertNotNull(instancesSearches);
assertNotNull(getItemsSearches());
assertNotNull(getPieceSearches());
assertEquals(polCount, instancesSearches.size());
// Check that 2 new instances created and items created successfully only for first POL
List<JsonObject> createdInstances = getCreatedInstances();
List<JsonObject> createdPieces = getCreatedPieces();
assertNotNull(createdInstances);
assertNotNull(getCreatedItems());
assertNotNull(createdPieces);
assertEquals(polCount, createdInstances.size());
List<JsonObject> items = joinExistingAndNewItems();
// Check instance Ids not exist for polines
verifyInstanceLinksNotCreatedForPoLine();
// Verify pieces were created
assertEquals(calculateTotalQuantity(compPo.getCompositePoLines().get(0)) + calculateTotalQuantity(compPo.getCompositePoLines().get(1)) - 1, createdPieces.size());
// Effectively remove non-processed locations with ID_FOR_INTERNAL_SERVER_ERROR to exclude them from
// created pieces verification
compPo.getCompositePoLines().forEach(poLine -> poLine.getLocations().removeIf(l -> {
if (l.getLocationId().equals(ID_FOR_INTERNAL_SERVER_ERROR)) {
if (poLine.getCost().getQuantityElectronic() != null) {
poLine.getCost().setQuantityElectronic(poLine.getCost().getQuantityElectronic() - l.getQuantityElectronic());
}
if (poLine.getCost().getQuantityPhysical() != null) {
poLine.getCost().setQuantityPhysical(poLine.getCost().getQuantityPhysical() - l.getQuantityPhysical());
}
return true;
} else {
return false;
}
}));
verifyPiecesCreated(items, compPo.getCompositePoLines(), createdPieces);
}
use of org.folio.TestConstants.ID_FOR_INTERNAL_SERVER_ERROR in project mod-orders by folio-org.
the class InventoryInteractionTestHelper method verifyOpenOrderPiecesCreated.
public static void verifyOpenOrderPiecesCreated(List<JsonObject> inventoryItems, List<CompositePoLine> compositePoLines, List<JsonObject> pieceJsons, int expectedWithItemQty) {
// Collect all item id's
List<String> itemIds = inventoryItems.stream().map(item -> item.getString(ID)).collect(Collectors.toList());
List<Piece> pieces = pieceJsons.stream().map(pieceObj -> pieceObj.mapTo(Piece.class)).collect(Collectors.toList());
// Verify quantity of created pieces
int totalForAllPoLines = 0;
for (CompositePoLine poLine : compositePoLines) {
Map<String, List<JsonObject>> createdHoldingsByLocationId = getCreatedHoldings().stream().filter(json -> json.getString("instanceId").equals(poLine.getInstanceId())).collect(groupingBy(json -> json.getString(HOLDING_PERMANENT_LOCATION_ID)));
List<Location> locations = poLine.getLocations().stream().filter(location -> PoLineCommonUtil.isHoldingCreationRequiredForLocation(poLine, location) && !Objects.equals(location.getLocationId(), ID_FOR_INTERNAL_SERVER_ERROR)).collect(Collectors.toList());
// Prepare data first
// Calculated quantities
int expectedElQty = 0;
int expectedPhysQty = 0;
int expectedOthQty = 0;
if (poLine.getCheckinItems() == null || !poLine.getCheckinItems()) {
if (poLine.getOrderFormat() == CompositePoLine.OrderFormat.OTHER) {
// calculatePiecesQuantity(Piece.Format.OTHER, locations);
expectedOthQty += getPhysicalCostQuantity(poLine);
} else {
// calculatePiecesQuantity(Piece.Format.PHYSICAL, locations);
expectedPhysQty += getPhysicalCostQuantity(poLine);
}
// calculatePiecesQuantity(Piece.Format.ELECTRONIC, locations);
expectedElQty = getElectronicCostQuantity(poLine);
}
int expectedWithoutItemQty = calculateInventoryItemsQuantity(poLine, locations);
int expectedWithoutLocation = calculatePiecesQuantityWithoutLocation(poLine).values().stream().mapToInt(Integer::intValue).sum();
// Prepare pieces for PO Line
List<Piece> poLinePieces = pieces.stream().filter(piece -> piece.getPoLineId().equals(poLine.getId())).collect(Collectors.toList());
Map<String, Long> piecesByLocationIdQuantity = poLinePieces.stream().filter(piece -> Objects.nonNull(piece.getLocationId())).collect(groupingBy(Piece::getLocationId, Collectors.counting()));
int expectedTotal = expectedWithItemQty + expectedWithoutItemQty + expectedWithoutLocation;
// Make sure that quantities by piece type and by item presence are the same
assertThat(expectedPhysQty + expectedElQty + expectedOthQty, is(expectedTotal));
assertThat(poLinePieces, hasSize(expectedTotal));
// Verify each piece individually
poLinePieces.forEach(piece -> {
// Check if itemId in inventoryItems match itemId in piece record
if (poLine.getCheckinItems() != null && Boolean.FALSE.equals(poLine.getCheckinItems())) {
if (piece.getLocationId() != null) {
String pieceLocationId = piece.getLocationId();
List<JsonObject> createdHoldingsForLocation = createdHoldingsByLocationId.get(pieceLocationId);
assertNotNull(createdHoldingsForLocation);
}
}
assertThat(piece.getReceivingStatus(), equalTo(Piece.ReceivingStatus.EXPECTED));
if (piece.getItemId() != null) {
assertThat(itemIds, hasItem(piece.getItemId()));
}
assertThat(piece.getFormat(), notNullValue());
});
totalForAllPoLines += expectedTotal;
}
// Make sure that none of pieces missed
assertThat(pieceJsons, hasSize(totalForAllPoLines));
}
use of org.folio.TestConstants.ID_FOR_INTERNAL_SERVER_ERROR in project mod-orders by folio-org.
the class InventoryInteractionTestHelper method verifyPiecesCreated.
public static void verifyPiecesCreated(List<JsonObject> inventoryItems, List<CompositePoLine> compositePoLines, List<JsonObject> pieceJsons) {
// Collect all item id's
List<String> itemIds = inventoryItems.stream().map(item -> item.getString(ID)).collect(Collectors.toList());
List<Piece> pieces = pieceJsons.stream().map(pieceObj -> pieceObj.mapTo(Piece.class)).collect(Collectors.toList());
// Verify quantity of created pieces
int totalForAllPoLines = 0;
for (CompositePoLine poLine : compositePoLines) {
List<Location> locations = poLine.getLocations().stream().filter(location -> PoLineCommonUtil.isHoldingCreationRequiredForLocation(poLine, location) && !Objects.equals(location.getLocationId(), ID_FOR_INTERNAL_SERVER_ERROR)).collect(Collectors.toList());
// Prepare data first
// Calculated quantities
int expectedElQty = 0;
int expectedPhysQty = 0;
int expectedOthQty = 0;
if (poLine.getCheckinItems() == null || !poLine.getCheckinItems()) {
if (poLine.getOrderFormat() == CompositePoLine.OrderFormat.OTHER) {
// calculatePiecesQuantity(Piece.Format.OTHER, locations);
expectedOthQty += getPhysicalCostQuantity(poLine);
} else {
// calculatePiecesQuantity(Piece.Format.PHYSICAL, locations);
expectedPhysQty += getPhysicalCostQuantity(poLine);
}
// calculatePiecesQuantity(Piece.Format.ELECTRONIC, locations);
expectedElQty = getElectronicCostQuantity(poLine);
}
int expectedWithItemQty = 0;
int expectedWithoutItemQty = calculateInventoryItemsQuantity(poLine, locations);
int expectedWithoutLocation = calculatePiecesQuantityWithoutLocation(poLine).values().stream().mapToInt(Integer::intValue).sum();
// Prepare pieces for PO Line
List<Piece> piecesByPoLine = pieces.stream().filter(piece -> piece.getPoLineId().equals(poLine.getId())).collect(Collectors.toList());
// Get all PO Line's locations' ids
List<String> locationIds = locations.stream().map(Location::getLocationId).distinct().collect(Collectors.toList());
int expectedTotal = expectedWithItemQty + expectedWithoutItemQty + expectedWithoutLocation;
// Make sure that quantities by piece type and by item presence are the same
assertThat(expectedPhysQty + expectedElQty + expectedOthQty, is(expectedTotal));
assertThat(piecesByPoLine, hasSize(expectedTotal));
// Verify each piece individually
piecesByPoLine.forEach(piece -> {
// Check if itemId in inventoryItems match itemId in piece record
if (piece.getLocationId() != null) {
assertThat(locationIds, hasItem(piece.getLocationId()));
}
assertThat(piece.getReceivingStatus(), equalTo(Piece.ReceivingStatus.EXPECTED));
if (piece.getItemId() != null) {
assertThat(itemIds, hasItem(piece.getItemId()));
}
assertThat(piece.getFormat(), notNullValue());
});
totalForAllPoLines += expectedTotal;
}
// Make sure that none of pieces missed
assertThat(pieceJsons, hasSize(totalForAllPoLines));
}
Aggregations