use of org.folio.TestConstants.EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10 in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testPostListedPrintSerialInOpenStatus.
@Test
@Disabled
// TODO Must be fixed in scope of https://issues.folio.org/browse/MODORDERS-587
void testPostListedPrintSerialInOpenStatus() throws Exception {
logger.info("=== Test Listed Print Monograph in Open status ===");
CompositePurchaseOrder reqData = new JsonObject(getMockData(LISTED_PRINT_SERIAL_PATH)).mapTo(CompositePurchaseOrder.class);
String orderId = UUID.randomUUID().toString();
reqData.setWorkflowStatus(WorkflowStatus.OPEN);
MockServer.addMockTitles(reqData.getCompositePoLines());
prepareOrderForPostRequest(reqData);
reqData.setId(orderId);
reqData.getCompositePoLines().forEach(poLine -> {
poLine.setPaymentStatus(CompositePoLine.PaymentStatus.PENDING);
poLine.setReceiptStatus(ReceiptStatus.PENDING);
});
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()));
logger.info(JsonObject.mapFrom(resp));
String poId = resp.getId();
String poNumber = resp.getPoNumber();
assertNotNull(poId);
assertNotNull(poNumber);
assertEquals(reqData.getCompositePoLines().size(), resp.getCompositePoLines().size());
for (int i = 0; i < resp.getCompositePoLines().size(); i++) {
CompositePoLine line = resp.getCompositePoLines().get(i);
String polNumber = line.getPoLineNumber();
String polId = line.getId();
assertEquals(poId, line.getPurchaseOrderId());
assertNotNull(polId);
assertNotNull(polNumber);
assertTrue(polNumber.startsWith(poNumber));
assertNotNull(line.getInstanceId());
line.getLocations().forEach(location -> verifyLocationQuantity(location, line.getOrderFormat()));
line.getLocations().forEach(location -> {
assertNull(location.getLocationId());
assertNotNull(location.getHoldingId());
});
}
int polCount = resp.getCompositePoLines().size();
List<JsonObject> instancesSearches = getInstancesSearches();
assertNotNull(instancesSearches);
assertEquals(polCount, instancesSearches.size());
CompositePoLine respLine1 = resp.getCompositePoLines().get(0);
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());
List<JsonObject> createdHoldings = getCreatedHoldings();
assertEquals(1, createdHoldings.size(), "Quantity of created holding must be depended of quantity in the locations and create inventory include holding");
verifyHoldingsCreated(1, createdHoldings, respLine1);
// All existing and created items
List<JsonObject> items = joinExistingAndNewItems();
verifyItemsCreated(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, 1, items, respLine1);
List<JsonObject> createdPieces = getCreatedPieces();
verifyOpenOrderPiecesCreated(items, resp.getCompositePoLines(), createdPieces, 0);
createdPieces.stream().map(json -> json.mapTo(Piece.class)).filter(piece -> PHYSICAL.equals(piece.getFormat())).forEach(piece -> {
assertNull(piece.getLocationId());
assertNotNull(piece.getHoldingId());
});
createdPieces.stream().map(json -> json.mapTo(Piece.class)).filter(piece -> ELECTRONIC.equals(piece.getFormat())).forEach(piece -> {
assertNotNull(piece.getLocationId());
assertNull(piece.getHoldingId());
});
verifyEncumbrancesOnPoCreation(reqData, resp);
assertThat(getExistingOrderSummaries(), hasSize(0));
verifyCalculatedData(resp);
// MODORDERS-459 - check status changed to ONGOING
verifyReceiptStatusChangedTo(ReceiptStatus.ONGOING.value(), reqData.getCompositePoLines().size());
verifyPaymentStatusChangedTo(CompositePoLine.PaymentStatus.ONGOING.value(), reqData.getCompositePoLines().size());
}
use of org.folio.TestConstants.EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10 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.TestConstants.EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10 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.TestConstants.EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10 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.TestConstants.EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10 in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testPutOrdersByIdToChangeStatusToOpenWithCheckinItems.
@Test
void testPutOrdersByIdToChangeStatusToOpenWithCheckinItems() throws Exception {
logger.info("=== Test Put Order By Id to change status of Order to Open ===");
// Get Open Order
CompositePurchaseOrder reqData = getMockDraftOrder().mapTo(CompositePurchaseOrder.class);
reqData.setId(ID_FOR_PRINT_MONOGRAPH_ORDER);
MockServer.addMockTitles(reqData.getCompositePoLines());
// Make sure that mock PO has 2 po lines
assertThat(reqData.getCompositePoLines(), hasSize(2));
reqData.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN);
// MODORDERS-183 Set the second POLine checkinItems true
CompositePoLine line1 = reqData.getCompositePoLines().get(0);
CompositePoLine line2 = reqData.getCompositePoLines().get(1);
line2.setCheckinItems(true);
reqData.getCompositePoLines().forEach(s -> s.setReceiptStatus(CompositePoLine.ReceiptStatus.PENDING));
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)).filter(line -> Objects.nonNull(line.getLocations().get(0).getHoldingId())).findAny().get();
compPo.setCompositePoLines(List.of(respLine1, respLine2));
int polCount = compPo.getCompositePoLines().size();
List<JsonObject> createdInstances = getCreatedInstances();
assertEquals(2, 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(5, createdHoldings.size(), "Quantity of created instance must be depended of quantity in the locations and create inventory include holding");
verifyHoldingsCreated(3, createdHoldings, respLine1);
verifyHoldingsCreated(2, 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();
verifyOpenOrderPiecesCreated(items, compPo.getCompositePoLines(), createdPieces, 0);
verifyReceiptStatusChangedTo(CompositePoLine.ReceiptStatus.AWAITING_RECEIPT.value(), compPo.getCompositePoLines().size());
verifyPaymentStatusChangedTo(CompositePoLine.PaymentStatus.AWAITING_PAYMENT.value(), compPo.getCompositePoLines().size());
}
Aggregations