Search in sources :

Example 6 with ReceivingResults

use of org.folio.rest.jaxrs.model.ReceivingResults in project mod-orders by folio-org.

the class CheckinReceivingApiTest method testPostCheckInElectronicWithNoItems.

@Test
void testPostCheckInElectronicWithNoItems() {
    logger.info("=== Test POST Checkin - CheckIn Electronic resource");
    CompositePoLine poLines = getMockAsJson(POLINES_COLLECTION).getJsonArray("poLines").getJsonObject(7).mapTo(CompositePoLine.class);
    MockServer.addMockTitles(Collections.singletonList(poLines));
    CheckinCollection checkInRq = getMockAsJson(CHECKIN_RQ_MOCK_DATA_PATH + "checkin-pe-mix-2-electronic-resources.json").mapTo(CheckinCollection.class);
    ReceivingResults results = verifyPostResponse(ORDERS_CHECKIN_ENDPOINT, JsonObject.mapFrom(checkInRq).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10), APPLICATION_JSON, 200).as(ReceivingResults.class);
    assertThat(results.getTotalRecords(), equalTo(checkInRq.getTotalRecords()));
    Map<String, Set<String>> pieceIdsByPol = verifyReceivingSuccessRs(results);
    List<JsonObject> pieceSearches = getPieceSearches();
    List<JsonObject> pieceUpdates = getPieceUpdates();
    List<JsonObject> polSearches = getPoLineSearches();
    List<JsonObject> polUpdates = getPoLineUpdates();
    assertThat(pieceSearches, not(nullValue()));
    assertThat(pieceUpdates, not(nullValue()));
    assertThat(getItemsSearches(), is(nullValue()));
    assertThat(getItemUpdates(), is(nullValue()));
    assertThat(polSearches, not(nullValue()));
    assertThat(polUpdates, not(nullValue()));
    int expectedSearchRqQty = Math.floorDiv(checkInRq.getTotalRecords(), MAX_IDS_FOR_GET_RQ) + 1;
    // The piece searches should be made 2 times: 1st time to get all required piece records, 2nd time to calculate expected PO Line status
    assertThat(pieceSearches, hasSize(expectedSearchRqQty + pieceIdsByPol.size()));
    assertThat(pieceUpdates, hasSize(checkInRq.getTotalRecords()));
    assertThat(polSearches, hasSize(pieceIdsByPol.size()));
    assertThat(polUpdates, hasSize(pieceIdsByPol.size()));
    polUpdates.forEach(pol -> {
        PoLine poLine = pol.mapTo(PoLine.class);
        assertThat(poLine.getCheckinItems(), is(true));
        assertThat(poLine.getReceiptStatus(), is(PoLine.ReceiptStatus.PARTIALLY_RECEIVED));
        assertThat(poLine.getReceiptDate(), is(notNullValue()));
    });
    // Verify message is sent via event bus
    verifyCheckinOrderStatusUpdateEvent(1);
}
Also used : CheckinCollection(org.folio.rest.jaxrs.model.CheckinCollection) Set(java.util.Set) HashSet(java.util.HashSet) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) PoLine(org.folio.rest.jaxrs.model.PoLine) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) JsonObject(io.vertx.core.json.JsonObject) Matchers.emptyString(org.hamcrest.Matchers.emptyString) ReceivingResults(org.folio.rest.jaxrs.model.ReceivingResults) Test(org.junit.jupiter.api.Test)

Example 7 with ReceivingResults

use of org.folio.rest.jaxrs.model.ReceivingResults in project mod-orders by folio-org.

the class CheckinReceivingApiTest method testReceiveOngoingOrder.

@Test
void testReceiveOngoingOrder() {
    logger.info("=== Test POST Receive - Ongoing PO Lines");
    CompositePoLine poLines = getMockAsJson(POLINES_COLLECTION).getJsonArray("poLines").getJsonObject(9).mapTo(CompositePoLine.class);
    MockServer.addMockTitles(Collections.singletonList(poLines));
    ReceivingCollection receivingRq = getMockAsJson(RECEIVING_RQ_MOCK_DATA_PATH + "receive-physical-ongoing.json").mapTo(ReceivingCollection.class);
    receivingRq.getToBeReceived().get(0).setPoLineId(COMPOSITE_POLINE_ONGOING_ID);
    ReceivingResults results = verifyPostResponse(ORDERS_RECEIVING_ENDPOINT, JsonObject.mapFrom(receivingRq).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10), APPLICATION_JSON, 200).as(ReceivingResults.class);
    assertThat(results.getTotalRecords(), equalTo(receivingRq.getTotalRecords()));
    Map<String, Set<String>> pieceIdsByPol = verifyReceivingSuccessRs(results);
    List<JsonObject> pieceSearches = getPieceSearches();
    List<JsonObject> pieceUpdates = getPieceUpdates();
    List<JsonObject> polSearches = getPoLineSearches();
    List<JsonObject> polUpdates = getPoLineUpdates();
    assertThat(pieceSearches, not(nullValue()));
    assertThat(pieceUpdates, not(nullValue()));
    assertThat(polSearches, not(nullValue()));
    int expectedSearchRqQty = Math.floorDiv(receivingRq.getTotalRecords(), MAX_IDS_FOR_GET_RQ) + 1;
    // The piece searches should be made 1 time: 1st time to get all required piece records
    assertThat(pieceSearches, hasSize(expectedSearchRqQty));
    assertThat(pieceUpdates, hasSize(receivingRq.getTotalRecords()));
    assertThat(polSearches, hasSize(pieceIdsByPol.size()));
    // check no status updates were performed
    assertThat(polUpdates, nullValue());
    // Verify no status updated for ongoing order
    verifyOrderStatusUpdateEvent(0);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ReceivingCollection(org.folio.rest.jaxrs.model.ReceivingCollection) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) JsonObject(io.vertx.core.json.JsonObject) Matchers.emptyString(org.hamcrest.Matchers.emptyString) ReceivingResults(org.folio.rest.jaxrs.model.ReceivingResults) Test(org.junit.jupiter.api.Test)

Example 8 with ReceivingResults

use of org.folio.rest.jaxrs.model.ReceivingResults in project mod-orders by folio-org.

the class CheckinReceivingApiTest method testPostReceivingPhysicalWithErrors.

@Test
void testPostReceivingPhysicalWithErrors() throws IOException {
    logger.info("=== Test POST Receiving - Receive physical resources with different errors");
    ReceivingCollection receivingRq = getMockAsJson(RECEIVING_RQ_MOCK_DATA_PATH + "receive-physical-resources-6-of-10-with-errors.json").mapTo(ReceivingCollection.class);
    CompositePoLine poLines = getMockAsJson(POLINES_COLLECTION).getJsonArray("poLines").getJsonObject(3).mapTo(CompositePoLine.class);
    MockServer.addMockTitles(Collections.singletonList(poLines));
    ReceivingResults results = verifyPostResponse(ORDERS_RECEIVING_ENDPOINT, JsonObject.mapFrom(receivingRq).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10), APPLICATION_JSON, 200).as(ReceivingResults.class);
    assertThat(results.getTotalRecords(), is(receivingRq.getTotalRecords()));
    assertThat(results.getReceivingResults(), hasSize(1));
    ReceivingResult receivingResult = results.getReceivingResults().get(0);
    assertThat(receivingResult.getPoLineId(), not(is(emptyString())));
    assertThat(receivingResult.getProcessedSuccessfully(), is(5));
    assertThat(receivingResult.getProcessedWithError(), is(5));
    Set<String> errorCodes = new HashSet<>();
    for (ReceivingItemResult receivingItemResult : receivingResult.getReceivingItemResults()) {
        assertThat(receivingItemResult.getPieceId(), not(is(emptyString())));
        assertThat(receivingItemResult.getProcessingStatus(), not(nullValue()));
        if (receivingItemResult.getProcessingStatus().getType() == SUCCESS) {
            assertThat(receivingItemResult.getProcessingStatus().getError(), nullValue());
        } else {
            assertThat(receivingItemResult.getProcessingStatus().getError(), not(nullValue()));
            errorCodes.add(receivingItemResult.getProcessingStatus().getError().getCode());
        }
    }
    assertThat(errorCodes, containsInAnyOrder(PIECE_ALREADY_RECEIVED.getCode(), PIECE_POL_MISMATCH.getCode(), PIECE_NOT_FOUND.getCode(), ITEM_UPDATE_FAILED.getCode(), PIECE_UPDATE_FAILED.getCode()));
    List<JsonObject> itemUpdates = getItemUpdates();
    List<JsonObject> polUpdates = getPoLineUpdates();
    assertThat(getPoLineSearches(), hasSize(1));
    assertThat(polUpdates, hasSize(1));
    assertThat(itemUpdates, hasSize(6));
    itemUpdates.forEach(item -> {
        assertThat(item.getJsonObject(ITEM_STATUS), notNullValue());
        assertThat(item.getJsonObject(ITEM_STATUS).getString(ITEM_STATUS_NAME), equalTo(ReceivedItem.ItemStatus.IN_PROCESS.value()));
    });
    polUpdates.forEach(pol -> {
        PoLine poLine = pol.mapTo(PoLine.class);
        assertThat(poLine.getReceiptStatus(), is(PoLine.ReceiptStatus.PARTIALLY_RECEIVED));
        assertThat(poLine.getReceiptDate(), is(nullValue()));
    });
    verifyProperQuantityOfHoldingsCreated(receivingRq);
    // Verify messages sent via event bus
    verifyOrderStatusUpdateEvent(1);
}
Also used : ReceivingItemResult(org.folio.rest.jaxrs.model.ReceivingItemResult) ReceivingResult(org.folio.rest.jaxrs.model.ReceivingResult) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) PoLine(org.folio.rest.jaxrs.model.PoLine) ReceivingCollection(org.folio.rest.jaxrs.model.ReceivingCollection) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) JsonObject(io.vertx.core.json.JsonObject) Matchers.emptyString(org.hamcrest.Matchers.emptyString) ReceivingResults(org.folio.rest.jaxrs.model.ReceivingResults) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 9 with ReceivingResults

use of org.folio.rest.jaxrs.model.ReceivingResults in project mod-orders by folio-org.

the class CheckinReceivingApiTest method testPostCheckInPhysicalWithMissingItem.

@Test
void testPostCheckInPhysicalWithMissingItem() {
    logger.info("=== Test POST Checkin - CheckIn physical resource with only one item updated");
    CompositePoLine poLines = getMockAsJson(POLINES_COLLECTION).getJsonArray("poLines").getJsonObject(7).mapTo(CompositePoLine.class);
    MockServer.addMockTitles(Collections.singletonList(poLines));
    CheckinCollection checkInRq = getMockAsJson(CHECKIN_RQ_MOCK_DATA_PATH + "checkin-pe-mix-2-physical-resources.json").mapTo(CheckinCollection.class);
    ReceivingResults results = verifyPostResponse(ORDERS_CHECKIN_ENDPOINT, JsonObject.mapFrom(checkInRq).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10), APPLICATION_JSON, 200).as(ReceivingResults.class);
    assertThat(results.getTotalRecords(), equalTo(checkInRq.getTotalRecords()));
    ReceivingResult receivingResult = results.getReceivingResults().get(0);
    for (ReceivingItemResult receivingItemResult : receivingResult.getReceivingItemResults()) {
        assertThat(receivingItemResult.getPieceId(), not(is(emptyString())));
        assertThat(receivingItemResult.getProcessingStatus(), not(nullValue()));
        assertThat(receivingItemResult.getProcessingStatus().getType(), is(SUCCESS));
        assertThat(receivingItemResult.getProcessingStatus().getError(), nullValue());
    }
    List<JsonObject> pieceSearches = getPieceSearches();
    List<JsonObject> pieceUpdates = getPieceUpdates();
    List<JsonObject> itemsSearches = getItemsSearches();
    List<JsonObject> itemUpdates = getItemUpdates();
    List<JsonObject> polSearches = getPoLineSearches();
    List<JsonObject> polUpdates = getPoLineUpdates();
    assertThat(pieceSearches, not(nullValue()));
    assertThat(pieceUpdates, not(nullValue()));
    assertThat(itemsSearches, not(nullValue()));
    assertThat(itemUpdates, not(nullValue()));
    assertThat(polSearches, not(nullValue()));
    assertThat(polUpdates, not(nullValue()));
    assertThat(pieceSearches, hasSize(2));
    assertThat(pieceUpdates, hasSize(2));
    assertThat(itemsSearches, hasSize(1));
    assertThat(itemUpdates, hasSize(1));
    assertThat(polSearches, hasSize(1));
    assertThat(polUpdates, hasSize(1));
    itemUpdates.forEach(item -> {
        assertThat(item.getJsonObject(ITEM_STATUS), notNullValue());
        assertThat(item.getJsonObject(ITEM_STATUS).getString(ITEM_STATUS_NAME), equalTo(CheckInPiece.ItemStatus.IN_PROCESS.value()));
    });
    polUpdates.forEach(pol -> {
        PoLine poLine = pol.mapTo(PoLine.class);
        assertThat(poLine.getCheckinItems(), is(true));
        assertThat(poLine.getReceiptStatus(), is(PoLine.ReceiptStatus.PARTIALLY_RECEIVED));
        assertThat(poLine.getReceiptDate(), is(notNullValue()));
    });
    // Verify message is sent via event bus
    verifyCheckinOrderStatusUpdateEvent(1);
}
Also used : CheckinCollection(org.folio.rest.jaxrs.model.CheckinCollection) ReceivingItemResult(org.folio.rest.jaxrs.model.ReceivingItemResult) ReceivingResult(org.folio.rest.jaxrs.model.ReceivingResult) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) PoLine(org.folio.rest.jaxrs.model.PoLine) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) JsonObject(io.vertx.core.json.JsonObject) ReceivingResults(org.folio.rest.jaxrs.model.ReceivingResults) Test(org.junit.jupiter.api.Test)

Example 10 with ReceivingResults

use of org.folio.rest.jaxrs.model.ReceivingResults in project mod-orders by folio-org.

the class CheckinReceivingApiTest method testPostReceivingRevertElectronicResource.

@Test
void testPostReceivingRevertElectronicResource() {
    logger.info("=== Test POST Receiving - Revert received electronic resource");
    CompositePoLine poLines = getMockAsJson(POLINES_COLLECTION).getJsonArray("poLines").getJsonObject(6).mapTo(CompositePoLine.class);
    MockServer.addMockTitles(Collections.singletonList(poLines));
    ReceivingCollection receivingRq = getMockAsJson(RECEIVING_RQ_MOCK_DATA_PATH + "revert-electronic-1-of-1-resource.json").mapTo(ReceivingCollection.class);
    ReceivingResults results = verifyPostResponse(ORDERS_RECEIVING_ENDPOINT, JsonObject.mapFrom(receivingRq).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10), APPLICATION_JSON, 200).as(ReceivingResults.class);
    assertThat(results.getTotalRecords(), equalTo(receivingRq.getTotalRecords()));
    verifyReceivingSuccessRs(results);
    List<JsonObject> pieceSearches = getPieceSearches();
    List<JsonObject> pieceUpdates = getPieceUpdates();
    List<JsonObject> itemsSearches = getItemsSearches();
    List<JsonObject> itemUpdates = getItemUpdates();
    List<JsonObject> polSearches = getPoLineSearches();
    List<JsonObject> polUpdates = getPoLineUpdates();
    assertThat(pieceSearches, not(nullValue()));
    assertThat(pieceUpdates, not(nullValue()));
    assertThat(itemsSearches, not(nullValue()));
    assertThat(itemUpdates, not(nullValue()));
    assertThat(polSearches, not(nullValue()));
    assertThat(polUpdates, not(nullValue()));
    // The piece searches should be made 3 times: 1st time to get piece record, 2nd and 3rd times to calculate expected PO Line status
    assertThat(pieceSearches, hasSize(3));
    assertThat(pieceUpdates, hasSize(1));
    assertThat(itemsSearches, hasSize(1));
    assertThat(itemUpdates, hasSize(1));
    assertThat(polSearches, hasSize(1));
    assertThat(polUpdates, hasSize(1));
    itemUpdates.forEach(item -> {
        assertThat(item.getJsonObject(ITEM_STATUS), notNullValue());
        assertThat(item.getString(ITEM_LEVEL_CALL_NUMBER), is(nullValue()));
        assertThat(item.getJsonObject(ITEM_STATUS).getString(ITEM_STATUS_NAME), equalTo(ReceivedItem.ItemStatus.ON_ORDER.value()));
    });
    polUpdates.forEach(pol -> {
        PoLine poLine = pol.mapTo(PoLine.class);
        assertThat(poLine.getReceiptStatus(), is(PoLine.ReceiptStatus.AWAITING_RECEIPT));
        assertThat(poLine.getReceiptDate(), is(nullValue()));
    });
    // Verify messages sent via event bus
    verifyOrderStatusUpdateEvent(1);
}
Also used : CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) PoLine(org.folio.rest.jaxrs.model.PoLine) ReceivingCollection(org.folio.rest.jaxrs.model.ReceivingCollection) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) JsonObject(io.vertx.core.json.JsonObject) ReceivingResults(org.folio.rest.jaxrs.model.ReceivingResults) Test(org.junit.jupiter.api.Test)

Aggregations

ReceivingResults (org.folio.rest.jaxrs.model.ReceivingResults)20 Test (org.junit.jupiter.api.Test)14 TestUtils.getMinimalContentCompositePoLine (org.folio.TestUtils.getMinimalContentCompositePoLine)13 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)13 JsonObject (io.vertx.core.json.JsonObject)12 ReceivingCollection (org.folio.rest.jaxrs.model.ReceivingCollection)11 PoLine (org.folio.rest.jaxrs.model.PoLine)9 HashSet (java.util.HashSet)7 ReceivingItemResult (org.folio.rest.jaxrs.model.ReceivingItemResult)7 Matchers.emptyString (org.hamcrest.Matchers.emptyString)7 Set (java.util.Set)6 CheckinCollection (org.folio.rest.jaxrs.model.CheckinCollection)6 ReceivingResult (org.folio.rest.jaxrs.model.ReceivingResult)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 EnumSource (org.junit.jupiter.params.provider.EnumSource)5 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 List (java.util.List)3