use of org.folio.orders.utils.ResourcePathResolver.PURCHASE_ORDER_STORAGE 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.orders.utils.ResourcePathResolver.PURCHASE_ORDER_STORAGE in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testPutOrdersByIdTotalPiecesEqualsTotalQuantityWhenCreateInventoryIsFalse.
@Test
@Disabled
// TODO must be fixed in scope of https://issues.folio.org/browse/MODORDERS-587
void testPutOrdersByIdTotalPiecesEqualsTotalQuantityWhenCreateInventoryIsFalse() throws Exception {
logger.info("=== Test Put Order By Id create Pieces when Item record does not exist ===");
CompositePurchaseOrder reqData = getMockDraftOrder().mapTo(CompositePurchaseOrder.class);
reqData.setId(ID_FOR_PRINT_MONOGRAPH_ORDER);
// Make sure that mock PO has 2 po lines
assertThat(reqData.getCompositePoLines(), hasSize(2));
MockServer.addMockTitles(reqData.getCompositePoLines());
CompositePoLine line1 = reqData.getCompositePoLines().get(0);
CompositePoLine line2 = reqData.getCompositePoLines().get(1);
line2.getEresource().setCreateInventory(Eresource.CreateInventory.NONE);
reqData.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN);
preparePiecesForCompositePo(reqData);
verifyPut(String.format(COMPOSITE_ORDERS_BY_ID_PATH, reqData.getId()), JsonObject.mapFrom(reqData), "", 204);
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)).filter(line -> Objects.nonNull(line.getLocations().get(0).getHoldingId())).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));
List<JsonObject> items = joinExistingAndNewItems();
List<JsonObject> createdPieces = getCreatedPieces();
verifyPiecesQuantityForSuccessCase(compPo.getCompositePoLines(), createdPieces);
verifyOpenOrderPiecesCreated(items, compPo.getCompositePoLines(), createdPieces, 0);
}
use of org.folio.orders.utils.ResourcePathResolver.PURCHASE_ORDER_STORAGE in project mod-orders by folio-org.
the class ReceivingCheckinProtectionTest method testCheckInCompositeFlow.
@Test
void testCheckInCompositeFlow() {
addMockEntry(PURCHASE_ORDER_STORAGE, JsonObject.mapFrom(getMinimalContentCompositePurchaseOrder().withAcqUnitIds(NOT_PROTECTED_UNITS).withId(ORDER_WITH_NOT_PROTECTED_UNITS_ID)));
addMockEntry(PURCHASE_ORDER_STORAGE, JsonObject.mapFrom(getMinimalContentCompositePurchaseOrder().withAcqUnitIds(PROTECTED_UNITS).withId(ORDER_WITH_PROTECTED_UNITS_ID)));
List<CompositePoLine> poLines = new ArrayList<>();
poLines.add(getMinimalContentCompositePoLine(ORDER_WITH_NOT_PROTECTED_UNITS_ID).withId(EXPECTED_FLOW_PO_LINE_ID));
poLines.add(getMinimalContentCompositePoLine(ORDER_WITH_NOT_PROTECTED_UNITS_ID).withId(RANDOM_PO_LINE_ID_1));
poLines.add(getMinimalContentCompositePoLine(ORDER_WITH_PROTECTED_UNITS_ID).withId(RANDOM_PO_LINE_ID_2));
poLines.forEach(line -> addMockEntry(PO_LINES_STORAGE, JsonObject.mapFrom(line)));
MockServer.addMockTitles(poLines);
CheckinCollection toBeCheckedInRq = new CheckinCollection();
List<ToBeCheckedIn> toBeCheckedInList = new ArrayList<>();
toBeCheckedInList.add(getToBeCheckedIn(EXPECTED_FLOW_PO_LINE_ID, EXPECTED_FLOW_PIECE_ID_1));
toBeCheckedInList.add(getToBeCheckedIn(RANDOM_PO_LINE_ID_1, getRandomId()));
toBeCheckedInList.add(getToBeCheckedIn(RANDOM_PO_LINE_ID_2, getRandomId()));
toBeCheckedInList.add(getToBeCheckedIn(EXPECTED_FLOW_PO_LINE_ID, getRandomId()));
toBeCheckedInRq.setToBeCheckedIn(toBeCheckedInList);
toBeCheckedInRq.setTotalRecords(toBeCheckedInList.size());
ReceivingResults results = verifyPostResponse(Entities.CHECK_IN.getEndpoint(), JsonObject.mapFrom(toBeCheckedInRq).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_WITH_UNITS_NOT_ASSIGNED_TO_ORDER), APPLICATION_JSON, HttpStatus.HTTP_OK.toInt()).as(ReceivingResults.class);
List<ProcessingStatus> result = results.getReceivingResults().stream().flatMap(r -> r.getReceivingItemResults().stream().map(ReceivingItemResult::getProcessingStatus)).filter(s -> Objects.isNull(s.getError())).collect(Collectors.toList());
assertThat(result, hasSize(1));
List<Error> errors = results.getReceivingResults().stream().flatMap(r -> r.getReceivingItemResults().stream().map(e -> e.getProcessingStatus().getError())).filter(Objects::nonNull).collect(Collectors.toList());
assertThat(errors, hasSize(toBeCheckedInList.size() - 1));
assertThat(errors.stream().filter(e -> e.getCode().equals(PIECE_NOT_FOUND.getCode())).count(), is(2L));
assertThat(errors.stream().filter(e -> e.getCode().equals(USER_HAS_NO_PERMISSIONS.getCode())).count(), is(1L));
}
use of org.folio.orders.utils.ResourcePathResolver.PURCHASE_ORDER_STORAGE in project mod-orders by folio-org.
the class ReceivingCheckinProtectionTest method testReceivingCompositeFlow.
@Test
void testReceivingCompositeFlow() {
addMockEntry(PURCHASE_ORDER_STORAGE, JsonObject.mapFrom(getMinimalContentCompositePurchaseOrder().withAcqUnitIds(NOT_PROTECTED_UNITS).withId(ORDER_WITH_NOT_PROTECTED_UNITS_ID)));
addMockEntry(PURCHASE_ORDER_STORAGE, JsonObject.mapFrom(getMinimalContentCompositePurchaseOrder().withAcqUnitIds(PROTECTED_UNITS).withId(ORDER_WITH_PROTECTED_UNITS_ID)));
List<CompositePoLine> poLines = new ArrayList<>();
poLines.add(getMinimalContentCompositePoLine(ORDER_WITH_NOT_PROTECTED_UNITS_ID).withId(EXPECTED_FLOW_PO_LINE_ID));
poLines.add(getMinimalContentCompositePoLine(ORDER_WITH_NOT_PROTECTED_UNITS_ID).withId(RANDOM_PO_LINE_ID_1));
poLines.add(getMinimalContentCompositePoLine(ORDER_WITH_PROTECTED_UNITS_ID).withId(RANDOM_PO_LINE_ID_2));
poLines.forEach(line -> addMockEntry(PO_LINES_STORAGE, JsonObject.mapFrom(line)));
MockServer.addMockTitles(poLines);
ReceivingCollection toBeReceivedRq = new ReceivingCollection();
List<ToBeReceived> toBeReceivedList = new ArrayList<>();
toBeReceivedList.add(getToBeReceived(EXPECTED_FLOW_PO_LINE_ID, EXPECTED_FLOW_PIECE_ID_1));
toBeReceivedList.add(getToBeReceived(RANDOM_PO_LINE_ID_1, getRandomId()));
toBeReceivedList.add(getToBeReceived(RANDOM_PO_LINE_ID_2, getRandomId()));
toBeReceivedList.add(getToBeReceived(EXPECTED_FLOW_PO_LINE_ID, getRandomId()));
toBeReceivedRq.setToBeReceived(toBeReceivedList);
toBeReceivedRq.setTotalRecords(toBeReceivedList.size());
ReceivingResults results = verifyPostResponse(Entities.RECEIVING.getEndpoint(), JsonObject.mapFrom(toBeReceivedRq).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_WITH_UNITS_NOT_ASSIGNED_TO_ORDER), APPLICATION_JSON, HttpStatus.HTTP_OK.toInt()).as(ReceivingResults.class);
List<ProcessingStatus> result = results.getReceivingResults().stream().flatMap(r -> r.getReceivingItemResults().stream().map(ReceivingItemResult::getProcessingStatus)).filter(s -> Objects.isNull(s.getError())).collect(Collectors.toList());
assertThat(result, hasSize(1));
List<Error> errors = results.getReceivingResults().stream().flatMap(r -> r.getReceivingItemResults().stream().map(e -> e.getProcessingStatus().getError())).filter(Objects::nonNull).collect(Collectors.toList());
assertThat(errors, hasSize(toBeReceivedList.size() - 1));
assertThat(errors.stream().filter(e -> e.getCode().equals(PIECE_NOT_FOUND.getCode())).count(), is(2L));
assertThat(errors.stream().filter(e -> e.getCode().equals(USER_HAS_NO_PERMISSIONS.getCode())).count(), is(1L));
}
use of org.folio.orders.utils.ResourcePathResolver.PURCHASE_ORDER_STORAGE in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testPutOrdersByIdPEMixFormat.
@Test
@Disabled
// TODO must be fixed in scoupe of https://issues.folio.org/browse/MODORDERS-587
void testPutOrdersByIdPEMixFormat() {
logger.info("=== Test Put Order By Id create Pieces with P/E Mix format ===");
CompositePurchaseOrder reqData = getMockAsJson(PE_MIX_PATH).mapTo(CompositePurchaseOrder.class);
reqData.setId(ID_FOR_PRINT_MONOGRAPH_ORDER);
reqData.setReEncumber(null);
// Make sure that mock PO has 1 po line
assertThat(reqData.getCompositePoLines(), hasSize(1));
reqData.setManualPo(false);
CompositePoLine compositePoLine = reqData.getCompositePoLines().get(0);
compositePoLine.setId(PO_LINE_ID_FOR_SUCCESS_CASE);
compositePoLine.getEresource().setCreateInventory(Eresource.CreateInventory.NONE);
compositePoLine.setPhysical(new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM).withMaterialType("4b93736c-8731-46cd-9d6e-f9dce0f63bcd"));
compositePoLine.getCost().setQuantityPhysical(3);
compositePoLine.getCost().setQuantityElectronic(2);
compositePoLine.setOrderFormat(OrderFormat.P_E_MIX);
Transaction encumbrance = getMockAsJson(ENCUMBRANCE_PATH).getJsonArray("transactions").getJsonObject(0).mapTo(Transaction.class);
compositePoLine.getFundDistribution().get(0).setEncumbrance(encumbrance.getId());
compositePoLine.getFundDistribution().get(0).setFundId(encumbrance.getFromFundId());
encumbrance.getEncumbrance().setSourcePoLineId(compositePoLine.getId());
encumbrance.getEncumbrance().setSourcePurchaseOrderId(compositePoLine.getPurchaseOrderId());
compositePoLine.getLocations().stream().filter(location -> ObjectUtils.defaultIfNull(location.getQuantityPhysical(), 0) > 0).forEach(location -> location.setQuantityElectronic(null));
// MODORDERS-243
removeAllEncumbranceLinks(reqData);
reqData.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN);
MockServer.addMockTitles(reqData.getCompositePoLines());
preparePiecesForCompositePo(reqData);
verifyPut(String.format(COMPOSITE_ORDERS_BY_ID_PATH, reqData.getId()), JsonObject.mapFrom(reqData), "", 204);
List<JsonObject> respOrder = MockServer.serverRqRs.get(PURCHASE_ORDER_STORAGE, HttpMethod.PUT);
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(compositePoLine.getId())).peek(line -> line.remove("reportingCodes")).map(line -> line.mapTo(CompositePoLine.class)).filter(line -> line.getLocations().stream().filter(loc -> Objects.nonNull(loc.getHoldingId())).findFirst().isPresent()).distinct().findAny().get();
compPo.setCompositePoLines(List.of(respLine1));
List<JsonObject> createdPieces = getCreatedPieces();
List<JsonObject> createdItems = getCreatedItems();
assertThat(createdItems, notNullValue());
assertThat(createdPieces, notNullValue());
int piecesSize = createdPieces.size();
logger.debug("------------------- piecesSize, itemSize --------------------\n" + piecesSize + " " + createdItems.size());
// Verify total number of pieces created should be equal to total quantity
assertEquals(calculateTotalQuantity(respLine1), piecesSize);
verifyOpenOrderPiecesCreated(createdItems, compPo.getCompositePoLines(), createdPieces, 0);
verifyEncumbrancesOnPoUpdate(compPo);
assertTrue(getExistingOrderSummaries().size() > 0);
}
Aggregations