use of org.folio.rest.jaxrs.model.CompositePurchaseOrder 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.rest.jaxrs.model.CompositePurchaseOrder in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method verifyMissingInventoryEntryErrorHandling.
private Error verifyMissingInventoryEntryErrorHandling(Header header) throws Exception {
CompositePurchaseOrder reqData = getMockDraftOrder().mapTo(CompositePurchaseOrder.class);
reqData.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN);
MockServer.addMockTitles(reqData.getCompositePoLines());
reqData.getCompositePoLines().remove(1);
assertThat(reqData.getCompositePoLines(), hasSize(1));
Headers headers = prepareHeaders(header, X_OKAPI_USER_ID, APPROVAL_PERMISSIONS_HEADER);
Response resp = verifyPostResponse(COMPOSITE_ORDERS_PATH, JsonObject.mapFrom(reqData).encodePrettily(), headers, APPLICATION_JSON, 500);
int expectedContributorNameTypesSearches = Math.toIntExact(reqData.getCompositePoLines().get(0).getContributors().stream().map(Contributor::getContributorNameTypeId).distinct().count() / MAX_IDS_FOR_GET_RQ + 1);
assertThat(getContributorNameTypesSearches(), hasSize(expectedContributorNameTypesSearches));
assertThat(getInstanceStatusesSearches(), hasSize(1));
assertThat(getInstanceTypesSearches(), hasSize(1));
return resp.getBody().as(Errors.class).getErrors().get(0);
}
use of org.folio.rest.jaxrs.model.CompositePurchaseOrder in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testPutOrdersWithPackagePolinesAndInstanceIdSpecified.
@Test
void testPutOrdersWithPackagePolinesAndInstanceIdSpecified() throws Exception {
CompositePurchaseOrder reqData = getMockDraftOrder().mapTo(CompositePurchaseOrder.class);
reqData.setId(ID_FOR_PRINT_MONOGRAPH_ORDER);
reqData.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.PENDING);
reqData.getCompositePoLines().forEach(p -> {
p.setInstanceId(UUID.randomUUID().toString());
p.setIsPackage(true);
});
// Update order
Errors errors = verifyPut(String.format(COMPOSITE_ORDERS_BY_ID_PATH, reqData.getId()), JsonObject.mapFrom(reqData), "", 422).then().extract().as(Errors.class);
assertEquals(INSTANCE_ID_NOT_ALLOWED_FOR_PACKAGE_POLINE.getCode(), errors.getErrors().get(0).getCode());
// test with transition to open
reqData.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN);
errors = verifyPut(String.format(COMPOSITE_ORDERS_BY_ID_PATH, reqData.getId()), JsonObject.mapFrom(reqData), "", 422).then().extract().as(Errors.class);
assertEquals(INSTANCE_ID_NOT_ALLOWED_FOR_PACKAGE_POLINE.getCode(), errors.getErrors().get(0).getCode());
}
use of org.folio.rest.jaxrs.model.CompositePurchaseOrder in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testUpdateNotRequiredForOpenOrder.
@Test
void testUpdateNotRequiredForOpenOrder() {
logger.info("=== Test case when no workflowStatus update is expected for Open order ===");
CompositePurchaseOrder reqData = getMockAsJson(COMP_ORDER_MOCK_DATA_PATH, PO_ID_OPEN_STATUS).mapTo(CompositePurchaseOrder.class);
assertThat(reqData.getWorkflowStatus(), is(CompositePurchaseOrder.WorkflowStatus.OPEN));
verifyPut(String.format(COMPOSITE_ORDERS_BY_ID_PATH, reqData.getId()), JsonObject.mapFrom(reqData), EMPTY, 204);
assertThat(getPurchaseOrderUpdates().get(0).mapTo(PurchaseOrder.class).getWorkflowStatus(), is(PurchaseOrder.WorkflowStatus.OPEN));
}
use of org.folio.rest.jaxrs.model.CompositePurchaseOrder in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testPostOrdersInventoryInteractionWithReceiptNotRequired.
@Test
void testPostOrdersInventoryInteractionWithReceiptNotRequired() throws Exception {
logger.info("=== Test POST electronic PO, to create Instance and Holding even if receipt not required==");
JsonObject order = new JsonObject(getMockData(ELECTRONIC_FOR_CREATE_INVENTORY_TEST));
CompositePurchaseOrder reqData = order.mapTo(CompositePurchaseOrder.class);
// Make sure that Order is Open
reqData.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN);
MockServer.addMockTitles(reqData.getCompositePoLines());
// Set CreateInventory value to create inventory instances and holdings
reqData.getCompositePoLines().get(0).getEresource().setCreateInventory(Eresource.CreateInventory.INSTANCE_HOLDING);
reqData.getCompositePoLines().get(0).setReceiptStatus(ReceiptStatus.RECEIPT_NOT_REQUIRED);
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);
assertNotNull(getCreatedInstances());
assertNotNull(getCreatedHoldings());
assertNull(getItemsSearches());
assertNull(getCreatedPieces());
}
Aggregations