use of org.folio.rest.jaxrs.model.PieceCollection 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.jaxrs.model.PieceCollection in project mod-orders by folio-org.
the class LocationsAndPiecesConsistencyValidatorTest method testVerifyLocationsAndPiecesConsistencyWhenTwoLocationWithHoldingAndPiecesWithHolding.
@Test
public void testVerifyLocationsAndPiecesConsistencyWhenTwoLocationWithHoldingAndPiecesWithHolding() {
String holdingId1 = UUID.randomUUID().toString();
String holdingId2 = UUID.randomUUID().toString();
Location location1 = new Location().withHoldingId(holdingId1).withQuantity(1).withQuantityPhysical(1);
Location location2 = new Location().withHoldingId(holdingId2).withQuantity(1).withQuantityPhysical(1);
String poLineId = UUID.randomUUID().toString();
CompositePoLine poLine = new CompositePoLine().withId(poLineId).withLocations(List.of(location1, location2));
List<CompositePoLine> poLines = List.of(poLine);
Piece piece1 = new Piece().withPoLineId(poLineId).withHoldingId(holdingId1).withReceivingStatus(Piece.ReceivingStatus.EXPECTED);
Piece piece2 = new Piece().withPoLineId(poLineId).withHoldingId(holdingId2).withReceivingStatus(Piece.ReceivingStatus.EXPECTED);
PieceCollection pieces = new PieceCollection().withPieces(List.of(piece1, piece2)).withTotalRecords(2);
// Expect
LocationsAndPiecesConsistencyValidator.verifyLocationsAndPiecesConsistency(poLines, pieces);
}
use of org.folio.rest.jaxrs.model.PieceCollection in project mod-orders by folio-org.
the class LocationsAndPiecesConsistencyValidatorTest method testVerifyLocationsAndPiecesConsistencyWhenTwoLocationWithHoldingAndPiecesWithHoldingIdDifferenceWithPol.
@Test
public void testVerifyLocationsAndPiecesConsistencyWhenTwoLocationWithHoldingAndPiecesWithHoldingIdDifferenceWithPol() {
String holdingId1 = UUID.randomUUID().toString();
String holdingId2 = UUID.randomUUID().toString();
Location location1 = new Location().withHoldingId(holdingId1).withQuantity(1).withQuantityPhysical(1);
Location location2 = new Location().withHoldingId(holdingId2).withQuantity(1).withQuantityPhysical(1);
String poLineId = UUID.randomUUID().toString();
CompositePoLine poLine = new CompositePoLine().withId(poLineId).withLocations(List.of(location1, location2));
List<CompositePoLine> poLines = List.of(poLine);
Piece piece1 = new Piece().withPoLineId(poLineId).withHoldingId(UUID.randomUUID().toString()).withReceivingStatus(Piece.ReceivingStatus.EXPECTED);
Piece piece2 = new Piece().withPoLineId(poLineId).withHoldingId(holdingId2).withReceivingStatus(Piece.ReceivingStatus.EXPECTED);
PieceCollection pieces = new PieceCollection().withPieces(List.of(piece1, piece2)).withTotalRecords(2);
// Expect
HttpException actHttpException = assertThrows(HttpException.class, () -> LocationsAndPiecesConsistencyValidator.verifyLocationsAndPiecesConsistency(poLines, pieces), "Expected exception");
Error actError = actHttpException.getError();
assertEquals(PIECES_TO_BE_DELETED.getCode(), actError.getCode());
assertEquals(VALIDATION_ERROR, actHttpException.getCode());
}
Aggregations