Search in sources :

Example 1 with PoLineCollection

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

the class PurchaseOrderLineServiceTest method successRetrievePurchaseOrderLinesByQuery.

@Test
void successRetrievePurchaseOrderLinesByQuery() {
    String orderLineId = UUID.randomUUID().toString();
    List<PoLine> purchaseOrderLines = Collections.singletonList(new PoLine().withId(orderLineId));
    PoLineCollection expLines = new PoLineCollection().withPoLines(purchaseOrderLines).withTotalRecords(1);
    when(restClientMock.get(any(), any(), any())).thenReturn(CompletableFuture.completedFuture(expLines));
    String expectedQuery = String.format("id==%s", orderLineId);
    List<PoLine> actLines = purchaseOrderLineService.getOrderLines(expectedQuery, 0, Integer.MAX_VALUE, requestContext).join();
    verify(restClientMock).get(any(), eq(requestContext), eq(PoLineCollection.class));
    assertEquals(purchaseOrderLines, actLines);
}
Also used : PoLineCollection(org.folio.rest.jaxrs.model.PoLineCollection) PoLine(org.folio.rest.jaxrs.model.PoLine) Test(org.junit.jupiter.api.Test)

Example 2 with PoLineCollection

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

the class PurchaseOrderLineService method getOrderLinesChunk.

private CompletableFuture<List<PoLine>> getOrderLinesChunk(List<String> orderLineIds, RequestContext requestContext) {
    String query = convertIdsToCqlQuery(orderLineIds);
    RequestEntry requestEntry = new RequestEntry(ENDPOINT).withQuery(query).withOffset(0).withLimit(MAX_IDS_FOR_GET_RQ);
    return restClient.get(requestEntry, requestContext, PoLineCollection.class).thenApply(PoLineCollection::getPoLines);
}
Also used : PoLineCollection(org.folio.rest.jaxrs.model.PoLineCollection) RequestEntry(org.folio.rest.core.models.RequestEntry)

Example 3 with PoLineCollection

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

the class CheckinReceivingApiTest method verifyProperQuantityOfHoldingsCreated.

private void verifyProperQuantityOfHoldingsCreated(ReceivingCollection receivingRq) throws IOException {
    Set<String> expectedHoldings = new HashSet<>();
    // get processed poline
    PoLineCollection poLineCollection = new JsonObject(getMockData(POLINES_COLLECTION)).mapTo(PoLineCollection.class);
    PoLine poline = poLineCollection.getPoLines().stream().filter(poLine -> poLine.getId().equals(receivingRq.getToBeReceived().get(0).getPoLineId())).findFirst().get();
    CompositePoLine compPOL = PoLineCommonUtil.convertToCompositePoLine(poline);
    // get processed pieces for receiving
    PieceCollection pieces = new JsonObject(getMockData(PIECE_RECORDS_MOCK_DATA_PATH + "pieceRecordsCollection.json")).mapTo(PieceCollection.class);
    List<String> pieceIds = new ArrayList<>();
    receivingRq.getToBeReceived().get(0).getReceivedItems().forEach(recItem -> pieceIds.add(recItem.getPieceId()));
    // get processed pieces from mock collection
    pieces.getPieces().removeIf(piece -> !pieceIds.contains(piece.getId()));
    for (org.folio.rest.acq.model.Piece piece : pieces.getPieces()) {
        for (ReceivedItem receivedItem : receivingRq.getToBeReceived().get(0).getReceivedItems()) {
            if (receivedItem.getPieceId().equals(piece.getId()) && !receivedItem.getLocationId().equals(piece.getLocationId()) && isHoldingsUpdateRequired(piece, compPOL)) {
                expectedHoldings.add(getInstanceId(poline) + receivedItem.getLocationId());
            }
        }
    }
    assertEquals(expectedHoldings.size(), getCreatedHoldings().size());
}
Also used : PieceCollection(org.folio.rest.acq.model.PieceCollection) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) Matchers.emptyString(org.hamcrest.Matchers.emptyString) PoLineCollection(org.folio.rest.jaxrs.model.PoLineCollection) ReceivedItem(org.folio.rest.jaxrs.model.ReceivedItem) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) PoLine(org.folio.rest.jaxrs.model.PoLine) HashSet(java.util.HashSet)

Example 4 with PoLineCollection

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

the class PurchaseOrderLinesApiTest method testGetOrderPOLinesByPoId.

@Test
void testGetOrderPOLinesByPoId() {
    logger.info("=== Test Get Orders lines - by PO id ===");
    String sortBy = " sortBy poNumber";
    String cql = String.format("%s==%s", PURCHASE_ORDER_ID, ORDER_ID_WITH_PO_LINES);
    String endpointQuery = String.format("%s?query=%s%s", LINES_PATH, cql, sortBy);
    final PoLineCollection poLineCollection = verifySuccessGet(endpointQuery, PoLineCollection.class, PROTECTED_READ_ONLY_TENANT);
    assertThat(poLineCollection.getTotalRecords(), is(2));
    assertThat(getPoLineSearches(), hasSize(1));
    assertThat(MockServer.serverRqRs.get(ACQUISITIONS_UNITS, HttpMethod.GET), hasSize(1));
    assertThat(MockServer.serverRqRs.get(ACQUISITIONS_MEMBERSHIPS, HttpMethod.GET), hasSize(1));
    List<String> queryParams = getQueryParams(PO_LINES_STORAGE);
    assertThat(queryParams, hasSize(1));
    String queryToStorage = queryParams.get(0);
    assertThat(queryToStorage, containsString("(" + cql + ")"));
    assertThat(queryToStorage, containsString(ORDER_ID_WITH_PO_LINES));
    assertThat(queryToStorage, not(containsString(ACQUISITIONS_UNIT_IDS + "=")));
    assertThat(queryToStorage, containsString(NO_ACQ_UNIT_ASSIGNED_CQL));
    assertThat(queryToStorage, endsWith(sortBy));
}
Also used : PoLineCollection(org.folio.rest.jaxrs.model.PoLineCollection) Matchers.containsString(org.hamcrest.Matchers.containsString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

PoLineCollection (org.folio.rest.jaxrs.model.PoLineCollection)4 PoLine (org.folio.rest.jaxrs.model.PoLine)2 Test (org.junit.jupiter.api.Test)2 JsonObject (io.vertx.core.json.JsonObject)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 TestUtils.getMinimalContentCompositePoLine (org.folio.TestUtils.getMinimalContentCompositePoLine)1 PieceCollection (org.folio.rest.acq.model.PieceCollection)1 RequestEntry (org.folio.rest.core.models.RequestEntry)1 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)1 ReceivedItem (org.folio.rest.jaxrs.model.ReceivedItem)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.emptyString (org.hamcrest.Matchers.emptyString)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1