use of org.folio.rest.core.RestClient in project mod-orders by folio-org.
the class InventoryManagerTest method testShouldHandleItemRecordsIfPhysycPresentInUpdatePoLineTime.
@Test
void testShouldHandleItemRecordsIfPhysycPresentInUpdatePoLineTime() throws IOException {
CompositePoLine reqData = getMockAsJson(COMP_PO_LINES_MOCK_DATA_PATH, "c0d08448-347b-418a-8c2f-5fb50248d67e").mapTo(CompositePoLine.class);
String poLineId = "c0d08448-347b-418a-8c2f-5fb50248d67d";
String itemId = "86481a22-633e-4b97-8061-0dc5fdaaeabb";
String materialType = "1a54b431-2e4f-452d-9cae-9cee66c9a892";
String locationId = "758258bc-ecc1-41b8-abca-f7b610822fff";
String oldLocationId = "fcd64ce1-6995-48f0-840e-89ffa2288371";
reqData.setId(poLineId);
reqData.setPurchaseOrderId("9d56b621-202d-414b-9e7f-5fefe4422ab3");
reqData.getPhysical().setMaterialType(materialType);
reqData.getPhysical().setMaterialSupplier(ACTIVE_ACCESS_PROVIDER_B);
reqData.getPhysical().setCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM);
reqData.getLocations().get(0).setQuantityPhysical(1);
reqData.getLocations().get(0).setQuantity(1);
reqData.getCost().setQuantityPhysical(1);
reqData.getLocations().get(0).setLocationId(locationId);
CompositePoLine storagePoLineCom = getMockAsJson(COMP_PO_LINES_MOCK_DATA_PATH, "c0d08448-347b-418a-8c2f-5fb50248d67e").mapTo(CompositePoLine.class);
storagePoLineCom.setAlerts(null);
storagePoLineCom.setReportingCodes(null);
storagePoLineCom.getLocations().get(0).setQuantityPhysical(1);
storagePoLineCom.getLocations().get(0).setQuantity(1);
storagePoLineCom.getCost().setQuantityPhysical(1);
JsonObject items = new JsonObject(getMockData(ITEMS_RECORDS_MOCK_DATA_PATH + "inventoryItemsCollection.json"));
List<JsonObject> needUpdateItems = items.getJsonArray(ITEMS).stream().map(o -> ((JsonObject) o)).filter(item -> item.getString(TestConstants.ID).equals(itemId)).map(item -> item.put(ITEM_PURCHASE_ORDER_LINE_IDENTIFIER, poLineId)).collect(toList());
;
String path = PIECE_RECORDS_MOCK_DATA_PATH + String.format("pieceRecords-%s.json", poLineId);
PieceCollection existedPieces = new JsonObject(getMockData(path)).mapTo(PieceCollection.class);
existedPieces.getPieces().get(0).setItemId(itemId);
existedPieces.getPieces().get(0).setFormat(Piece.Format.PHYSICAL);
existedPieces.getPieces().get(0).setPoLineId(poLineId);
// given
doReturn(completedFuture(existedPieces)).when(pieceStorageService).getExpectedPiecesByLineId(poLineId, requestContext);
doReturn(completedFuture(needUpdateItems)).when(inventoryManager).getItemRecordsByIds(Collections.singletonList(itemId), requestContext);
doReturn(completedFuture(null)).when(inventoryManager).updateItemRecords(any(), eq(requestContext));
doReturn(completedFuture(null)).when(restClient).put(any(RequestEntry.class), any(JsonObject.class), eq(requestContext));
// When
PoLineUpdateHolder poLineUpdateHolder = new PoLineUpdateHolder().withOldLocationId(oldLocationId).withNewLocationId(locationId);
List<Piece> pieces = inventoryManager.handleItemRecords(reqData, poLineUpdateHolder, requestContext).join();
assertEquals(1, pieces.size());
assertEquals(itemId, pieces.get(0).getItemId());
assertEquals(locationId, pieces.get(0).getLocationId());
}
use of org.folio.rest.core.RestClient in project mod-orders by folio-org.
the class InventoryManagerTest method shouldCheckIfTheHoldingExistsWhenLocationIdSpecifiedAndIfNotExistThenCreateNewHoldingReturnHoldingId.
@Test
void shouldCheckIfTheHoldingExistsWhenLocationIdSpecifiedAndIfNotExistThenCreateNewHoldingReturnHoldingId() throws IOException {
String instanceId = UUID.randomUUID().toString();
JsonObject holdingsCollection = new JsonObject(getMockData(HOLDINGS_OLD_NEW_PATH));
String holdingIdExp = extractId(getFirstObjectFromResponse(holdingsCollection, HOLDINGS_RECORDS));
List<JsonObject> holdings = holdingsCollection.getJsonArray(HOLDINGS_RECORDS).stream().map(o -> ((JsonObject) o)).collect(toList());
List<String> locationIds = holdings.stream().map(holding -> holding.getString(HOLDING_PERMANENT_LOCATION_ID)).collect(toList());
Location location = new Location().withLocationId(locationIds.get(0)).withQuantity(1).withQuantityPhysical(1);
JsonObject holdingsRecJson = new JsonObject();
holdingsRecJson.put(HOLDING_INSTANCE_ID, instanceId);
holdingsRecJson.put(HOLDING_PERMANENT_LOCATION_ID, locationIds.get(0));
JsonObject emptyHoldingCollection = new JsonObject().put(HOLDINGS_RECORDS, new JsonArray());
doReturn(completedFuture(emptyHoldingCollection)).when(restClient).getAsJsonObject(any(RequestEntry.class), eq(requestContext));
doReturn(completedFuture(holdingIdExp)).when(restClient).post(any(RequestEntry.class), any(JsonObject.class), eq(PostResponseType.UUID), eq(String.class), eq(requestContext));
String holdingIdAct = inventoryManager.getOrCreateHoldingsRecord(instanceId, location, requestContext).join();
assertThat(holdingIdAct, equalTo(holdingIdExp));
verify(restClient, times(1)).post(any(RequestEntry.class), any(JsonObject.class), eq(PostResponseType.UUID), eq(String.class), eq(requestContext));
;
}
use of org.folio.rest.core.RestClient in project mod-orders by folio-org.
the class InventoryManagerTest method shouldReturnHoldingsByInstanceIdAndLocationIdIfTheyExist.
@Test
void shouldReturnHoldingsByInstanceIdAndLocationIdIfTheyExist() throws IOException, ExecutionException, InterruptedException {
String instanceId = UUID.randomUUID().toString();
JsonObject holdingsCollection = new JsonObject(getMockData(HOLDINGS_OLD_NEW_PATH));
List<JsonObject> holdings = holdingsCollection.getJsonArray("holdingsRecords").stream().map(o -> ((JsonObject) o)).collect(toList());
List<String> locationIds = holdings.stream().map(holding -> holding.getString(HOLDING_PERMANENT_LOCATION_ID)).collect(toList());
doReturn(completedFuture(holdingsCollection)).when(restClient).getAsJsonObject(any(RequestEntry.class), eq(requestContext));
JsonObject actHoldings = inventoryManager.getFirstHoldingRecord(instanceId, locationIds.get(0), requestContext).get();
verify(restClient, times(1)).getAsJsonObject(any(RequestEntry.class), eq(requestContext));
}
use of org.folio.rest.core.RestClient in project mod-orders by folio-org.
the class InventoryManagerTest method shouldTrowExceptionHoldingsByIdsIfNotAllOfThemExist.
@Test
void shouldTrowExceptionHoldingsByIdsIfNotAllOfThemExist() throws IOException, ExecutionException, InterruptedException {
JsonObject holdingsCollection = new JsonObject(getMockData(HOLDINGS_OLD_NEW_PATH));
List<JsonObject> holdings = holdingsCollection.getJsonArray("holdingsRecords").stream().map(o -> ((JsonObject) o)).collect(toList());
List<String> holdingIds = holdings.stream().map(holding -> holding.getString(ID)).collect(toList());
holdingIds.add(UUID.randomUUID().toString());
doReturn(completedFuture(holdingsCollection)).when(restClient).getAsJsonObject(any(RequestEntry.class), eq(requestContext));
CompletableFuture<List<JsonObject>> resultFuture = inventoryManager.getHoldingsByIds(holdingIds, requestContext);
ExecutionException executionException = assertThrows(ExecutionException.class, resultFuture::get);
assertThat(executionException.getCause(), IsInstanceOf.instanceOf(HttpException.class));
HttpException httpException = (HttpException) executionException.getCause();
assertEquals(404, httpException.getCode());
assertEquals(PARTIALLY_RETURNED_COLLECTION.toError().getCode(), httpException.getError().getCode());
}
use of org.folio.rest.core.RestClient in project mod-invoice by folio-org.
the class InvoiceCancelServiceTest method setupPoLineQuery.
private void setupPoLineQuery(List<PoLine> poLines) {
String poLineIdsQuery = poLines.stream().map(PoLine::getId).collect(joining(" or "));
String poLineQuery = "paymentStatus==(\"Awaiting Payment\" OR \"Partially Paid\" OR \"Fully Paid\") AND id==(" + poLineIdsQuery + ")";
PoLineCollection poLineCollection = new PoLineCollection().withPoLines(poLines).withTotalRecords(poLines.size());
RequestEntry requestEntry = new RequestEntry("/orders/order-lines").withQuery(poLineQuery).withOffset(0).withLimit(Integer.MAX_VALUE);
doReturn(completedFuture(poLineCollection)).when(restClient).get(argThat(re -> sameRequestEntry(requestEntry, re)), eq(requestContextMock), eq(PoLineCollection.class));
}
Aggregations