use of org.folio.rest.jaxrs.model.ReceivingResults 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.rest.jaxrs.model.ReceivingResults in project mod-orders by folio-org.
the class ReceivingCheckinProtectionTest method testFlowWithNonExistedUnits.
@ParameterizedTest
@EnumSource(value = Entities.class)
void testFlowWithNonExistedUnits(Entities entity) {
logger.info("=== Test check-in/receiving flow - non-existing units ===");
ReceivingResults results = verifyPostResponse(entity.getEndpoint(), entity.getJsonRequest(NON_EXISTENT_UNITS), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID), APPLICATION_JSON, HttpStatus.HTTP_OK.toInt()).as(ReceivingResults.class);
verifyRestrictedCase(results);
validateNumberOfRequests(1, 0);
}
use of org.folio.rest.jaxrs.model.ReceivingResults 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.rest.jaxrs.model.ReceivingResults in project mod-orders by folio-org.
the class ReceivingCheckinProtectionTest method testFlowWithAllowedUnits.
@ParameterizedTest
@EnumSource(value = Entities.class)
void testFlowWithAllowedUnits(Entities entity) {
logger.info("=== Test check-in/receiving flow - not-protecting units ===");
ReceivingResults results = verifyPostResponse(entity.getEndpoint(), entity.getJsonRequest(NOT_PROTECTED_UNITS), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID), APPLICATION_JSON, HttpStatus.HTTP_OK.toInt()).as(ReceivingResults.class);
verifyAllowedCase(results);
validateNumberOfRequests(1, 0);
}
use of org.folio.rest.jaxrs.model.ReceivingResults in project mod-orders by folio-org.
the class ReceivingCheckinProtectionTest method testCheckInWithProtectedUnitsAndForbiddenUser.
@ParameterizedTest
@EnumSource(value = Entities.class)
void testCheckInWithProtectedUnitsAndForbiddenUser(Entities entity) {
logger.info("=== Test check-in/receiving flow - protecting units and forbidden user ===");
ReceivingResults results = verifyPostResponse(entity.getEndpoint(), entity.getJsonRequest(PROTECTED_UNITS), 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);
verifyRestrictedCase(results);
validateNumberOfRequests(1, 1);
}
Aggregations