use of org.folio.rest.jaxrs.model.Piece in project mod-orders by folio-org.
the class DefaultPieceFlowsValidatorTest method createPieceIsForbiddenIfPieceAndLIneFormatIsNotCompatible.
@Test
void createPieceIsForbiddenIfPieceAndLIneFormatIsNotCompatible() {
String orderId = UUID.randomUUID().toString();
String locationId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
Piece piece = new Piece().withPoLineId(lineId).withLocationId(locationId).withFormat(Piece.Format.ELECTRONIC);
Location loc = new Location().withLocationId(locationId).withQuantityElectronic(1).withQuantity(1);
Cost cost = new Cost().withQuantityElectronic(1);
CompositePoLine originPoLine = new CompositePoLine().withIsPackage(true).withPurchaseOrderId(orderId).withOrderFormat(CompositePoLine.OrderFormat.PHYSICAL_RESOURCE).withId(lineId).withLocations(List.of(loc)).withCost(cost);
HttpException exception = Assertions.assertThrows(HttpException.class, () -> {
defaultPieceFlowsValidator.isPieceRequestValid(piece, originPoLine, true);
});
boolean isErrorPresent = exception.getErrors().getErrors().stream().anyMatch(error -> error.getCode().equals(ErrorCodes.PIECE_FORMAT_IS_NOT_VALID_ERROR.getCode()));
assertEquals(true, isErrorPresent);
}
use of org.folio.rest.jaxrs.model.Piece in project mod-orders by folio-org.
the class PieceCreateFlowInventoryManagerTest method testShouldNotCreateHoldingPieceCreateForPackagePoLineWithCreateInventoryInstance.
@Test
void testShouldNotCreateHoldingPieceCreateForPackagePoLineWithCreateInventoryInstance() {
String orderId = UUID.randomUUID().toString();
String locationId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
String titleId = UUID.randomUUID().toString();
String pieceId = UUID.randomUUID().toString();
Title title = new Title().withId(titleId).withPoLineId(lineId).withInstanceId(UUID.randomUUID().toString());
Piece piece = new Piece().withId(pieceId).withPoLineId(lineId).withLocationId(locationId).withFormat(Piece.Format.ELECTRONIC);
Location loc = new Location().withLocationId(locationId).withQuantityElectronic(1).withQuantity(1);
Cost cost = new Cost().withQuantityElectronic(1).withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
CompositePoLine compPOL = new CompositePoLine().withIsPackage(true).withPurchaseOrderId(orderId).withOrderFormat(ELECTRONIC_RESOURCE).withId(lineId).withCheckinItems(false).withEresource(new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE)).withLocations(List.of(loc)).withCost(cost);
CompositePurchaseOrder compositePurchaseOrder = new CompositePurchaseOrder().withId(orderId).withCompositePoLines(List.of(compPOL));
doReturn(completedFuture(piece)).when(pieceStorageService).getPieceById(pieceId, requestContext);
doReturn(completedFuture(title)).when(titlesService).getTitleById(piece.getTitleId(), requestContext);
doReturn(completedFuture(null)).when(titlesService).saveTitle(title, requestContext);
doReturn(completedFuture(title)).when(inventoryManager).openOrderHandlePackageLineInstance(title, false, requestContext);
PieceCreationHolder holder = new PieceCreationHolder().withPieceToCreate(piece).withCreateItem(true);
holder.withOrderInformation(compositePurchaseOrder);
pieceCreateFlowInventoryManager.processInventory(holder.getOriginPoLine(), holder.getPieceToCreate(), holder.isCreateItem(), requestContext).join();
assertNull(piece.getItemId());
assertNull(piece.getHoldingId());
assertEquals(locationId, piece.getLocationId());
verify(titlesService).getTitleById(piece.getTitleId(), requestContext);
verify(pieceUpdateInventoryService, times(0)).handleHoldingsRecord(eq(compPOL), any(Location.class), eq(title.getInstanceId()), eq(requestContext));
verify(pieceUpdateInventoryService, times(0)).manualPieceFlowCreateItemRecord(piece, compPOL, requestContext);
}
use of org.folio.rest.jaxrs.model.Piece in project mod-orders by folio-org.
the class PieceCreateFlowInventoryManagerTest method testPieceCreateForPackagePoLineWithCreateInventoryInstanceHoldingItem.
@Test
void testPieceCreateForPackagePoLineWithCreateInventoryInstanceHoldingItem() {
String orderId = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
String titleId = UUID.randomUUID().toString();
String itemId = UUID.randomUUID().toString();
String pieceId = UUID.randomUUID().toString();
Title title = new Title().withId(titleId).withPoLineId(lineId).withInstanceId(UUID.randomUUID().toString());
Piece piece = new Piece().withId(pieceId).withPoLineId(lineId).withHoldingId(holdingId).withFormat(Piece.Format.ELECTRONIC);
Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(1).withQuantity(1);
Cost cost = new Cost().withQuantityElectronic(1).withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
CompositePoLine compPOL = new CompositePoLine().withIsPackage(true).withPurchaseOrderId(orderId).withOrderFormat(ELECTRONIC_RESOURCE).withId(lineId).withEresource(new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE_HOLDING_ITEM)).withLocations(List.of(loc)).withCost(cost);
CompositePurchaseOrder compositePurchaseOrder = new CompositePurchaseOrder().withId(orderId).withCompositePoLines(List.of(compPOL));
doReturn(completedFuture(piece)).when(pieceStorageService).getPieceById(pieceId, requestContext);
doReturn(completedFuture(List.of(piece))).when(pieceStorageService).getPiecesByHoldingId(piece.getId(), requestContext);
doReturn(completedFuture(title)).when(titlesService).getTitleById(piece.getTitleId(), requestContext);
doReturn(completedFuture(null)).when(titlesService).saveTitle(title, requestContext);
doReturn(completedFuture(itemId)).when(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(piece, compPOL, requestContext);
doReturn(completedFuture(title)).when(inventoryManager).openOrderHandlePackageLineInstance(title, false, requestContext);
doReturn(completedFuture(holdingId)).when(pieceUpdateInventoryService).handleHoldingsRecord(eq(compPOL), any(Location.class), eq(title.getInstanceId()), eq(requestContext));
doReturn(completedFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(piece, requestContext);
PieceCreationHolder holder = new PieceCreationHolder().withPieceToCreate(piece).withCreateItem(true);
holder.withOrderInformation(compositePurchaseOrder);
pieceCreateFlowInventoryManager.processInventory(holder.getOriginPoLine(), holder.getPieceToCreate(), holder.isCreateItem(), requestContext).join();
assertEquals(itemId, piece.getItemId());
assertEquals(holdingId, piece.getHoldingId());
verify(titlesService).getTitleById(piece.getTitleId(), requestContext);
verify(pieceUpdateInventoryService, times(0)).handleHoldingsRecord(eq(compPOL), any(Location.class), eq(title.getInstanceId()), eq(requestContext));
verify(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(piece, compPOL, requestContext);
}
use of org.folio.rest.jaxrs.model.Piece in project mod-orders by folio-org.
the class PieceCreateFlowInventoryManagerTest method testShouldNotCreateHoldingPieceCreateForNonPackagePoLineWithCreateInventoryInstance.
@Test
void testShouldNotCreateHoldingPieceCreateForNonPackagePoLineWithCreateInventoryInstance() {
String orderId = UUID.randomUUID().toString();
String locationId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
String titleId = UUID.randomUUID().toString();
String pieceId = UUID.randomUUID().toString();
Title title = new Title().withId(titleId).withPoLineId(lineId).withInstanceId(UUID.randomUUID().toString());
Piece piece = new Piece().withId(pieceId).withPoLineId(lineId).withLocationId(locationId).withFormat(Piece.Format.ELECTRONIC);
Location loc = new Location().withLocationId(locationId).withQuantityElectronic(1).withQuantity(1);
Cost cost = new Cost().withQuantityElectronic(1).withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
CompositePoLine compPOL = new CompositePoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(ELECTRONIC_RESOURCE).withId(lineId).withEresource(new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE)).withLocations(List.of(loc)).withCost(cost);
CompositePurchaseOrder compositePurchaseOrder = new CompositePurchaseOrder().withId(orderId).withCompositePoLines(List.of(compPOL));
doReturn(completedFuture(piece)).when(pieceStorageService).getPieceById(pieceId, requestContext);
doReturn(completedFuture(title)).when(titlesService).getTitleById(piece.getTitleId(), requestContext);
doReturn(completedFuture(null)).when(titlesService).saveTitle(title, requestContext);
doReturn(completedFuture(title)).when(inventoryManager).openOrderHandlePackageLineInstance(title, false, requestContext);
PieceCreationHolder holder = new PieceCreationHolder().withPieceToCreate(piece).withCreateItem(true);
holder.withOrderInformation(compositePurchaseOrder);
pieceCreateFlowInventoryManager.processInventory(holder.getOriginPoLine(), holder.getPieceToCreate(), holder.isCreateItem(), requestContext).join();
assertNull(piece.getItemId());
assertNull(piece.getHoldingId());
assertEquals(locationId, piece.getLocationId());
verify(titlesService).getTitleById(piece.getTitleId(), requestContext);
verify(pieceUpdateInventoryService, times(0)).handleHoldingsRecord(eq(compPOL), any(Location.class), eq(title.getInstanceId()), eq(requestContext));
verify(pieceUpdateInventoryService, times(0)).manualPieceFlowCreateItemRecord(piece, compPOL, requestContext);
}
use of org.folio.rest.jaxrs.model.Piece in project mod-orders by folio-org.
the class PieceCreateFlowPoLineServiceTest method physOrNonetAddStrategyShouldIncreaseQuantityTo3ForCostAndLocationIfInitiallyWas2AndLocationIdInPOLAndPieceTheSameInventoryNone.
@ParameterizedTest
@DisplayName("Add 1 physical piece with location id to physical pol with 2 location and another location id as in piece")
@CsvSource(value = { "Physical Resource:None:2:4:Physical:7:7.0", "Physical Resource:Instance:2:4:Physical:7:7.0", "Other:None:2:4:Other:7:7.0", "Other:None:2:4:Other:7:7.0" }, delimiter = ':')
void physOrNonetAddStrategyShouldIncreaseQuantityTo3ForCostAndLocationIfInitiallyWas2AndLocationIdInPOLAndPieceTheSameInventoryNone(String lineType, String createInventory, int qty1, int qty2, String pieceFormat, int expQty, double expEstimatedPrice) throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
String locationId1 = UUID.randomUUID().toString();
String locationId2 = UUID.randomUUID().toString();
String locationId3 = UUID.randomUUID().toString();
Piece piece = new Piece().withPoLineId(lineId).withLocationId(locationId3).withFormat(Piece.Format.fromValue(pieceFormat));
Location loc1 = new Location().withLocationId(locationId1).withQuantityPhysical(qty1).withQuantity(qty1);
Location loc2 = new Location().withLocationId(locationId2).withQuantityPhysical(qty2).withQuantity(qty2);
Cost cost = new Cost().withQuantityPhysical(qty1 + qty2).withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice((double) (qty1 + qty2));
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.fromValue(createInventory));
PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.fromValue(lineType)).withId(lineId).withEresource(eresource).withLocations(List.of(loc1, loc2)).withCost(cost);
PieceCreationHolder incomingUpdateHolder = new PieceCreationHolder().withPieceToCreate(piece).withCreateItem(true);
incomingUpdateHolder.withOrderInformation(purchaseOrder, originPoLine);
doReturn(completedFuture(null)).when(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
doReturn(completedFuture(null)).when(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
// When
pieceCreateFlowPoLineService.updatePoLine(incomingUpdateHolder, requestContext).get();
// Then
CompositePoLine poLineToSave = incomingUpdateHolder.getPoLineToSave();
assertNull(poLineToSave.getCost().getQuantityElectronic());
assertEquals(expQty, poLineToSave.getCost().getQuantityPhysical());
assertEquals(expEstimatedPrice, poLineToSave.getCost().getPoLineEstimatedPrice());
assertEquals(3, poLineToSave.getLocations().size());
Location actLoc1 = poLineToSave.getLocations().stream().filter(loc -> locationId1.equals(loc.getLocationId())).findFirst().get();
Location actLoc2 = poLineToSave.getLocations().stream().filter(loc -> locationId2.equals(loc.getLocationId())).findFirst().get();
Location actLoc3 = poLineToSave.getLocations().stream().filter(loc -> locationId3.equals(loc.getLocationId())).findFirst().get();
assertEquals(qty1, actLoc1.getQuantityPhysical());
assertEquals(qty1, actLoc1.getQuantity());
assertNull(actLoc1.getQuantityElectronic());
assertEquals(qty2, actLoc2.getQuantityPhysical());
assertEquals(qty2, actLoc2.getQuantity());
assertNull(actLoc2.getQuantityElectronic());
assertEquals(1, actLoc3.getQuantityPhysical());
assertEquals(1, actLoc3.getQuantity());
assertNull(actLoc3.getQuantityElectronic());
verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
Aggregations