use of org.folio.models.pieces.PieceDeletionHolder in project mod-orders by folio-org.
the class PieceDeleteFlowPoLineServiceTest method electDeleteStrategyShouldDecreaseQuantityTo1ForCostAndLocationIfInitiallyWas1AndHoldingIdInPOLAndPieceTheSame.
@Test
@DisplayName("Delete 1 electronic piece with holding to electronic pol with 1 location and same holding id as in piece")
void electDeleteStrategyShouldDecreaseQuantityTo1ForCostAndLocationIfInitiallyWas1AndHoldingIdInPOLAndPieceTheSame() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
Piece piece = new Piece().withPoLineId(lineId).withHoldingId(holdingId).withFormat(Piece.Format.ELECTRONIC);
Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(2).withQuantity(2);
List<Location> locations = new ArrayList<>();
locations.add(loc);
Cost cost = new Cost().withQuantityElectronic(2).withListUnitPriceElectronic(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(2d);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE_HOLDING);
PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.ELECTRONIC_RESOURCE).withId(lineId).withEresource(eresource).withLocations(List.of(loc)).withCost(cost);
PieceDeletionHolder incomingUpdateHolder = new PieceDeletionHolder().withPieceToDelete(piece).withDeleteHolding(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
pieceDeleteFlowPoLineService.updatePoLine(incomingUpdateHolder, requestContext).get();
// Then
CompositePoLine poLineToSave = incomingUpdateHolder.getPoLineToSave();
assertNull(poLineToSave.getCost().getQuantityPhysical());
assertEquals(1, poLineToSave.getCost().getQuantityElectronic());
assertEquals(1, poLineToSave.getLocations().size());
assertNull(poLineToSave.getLocations().get(0).getQuantityPhysical());
assertEquals(1, poLineToSave.getLocations().get(0).getQuantityElectronic());
assertEquals(1, poLineToSave.getLocations().get(0).getQuantity());
verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
use of org.folio.models.pieces.PieceDeletionHolder in project mod-orders by folio-org.
the class PieceDeleteFlowPoLineServiceTest method elecDeleteStrategyShouldDecreaseQuantityTo1ForCostAndLocationIfInitiallyWas1AndLocationIdInPOLAndPieceTheSame.
@Test
@DisplayName("Delete 1 electronic piece with location to electronic pol with 1 location and same location id as in piece")
void elecDeleteStrategyShouldDecreaseQuantityTo1ForCostAndLocationIfInitiallyWas1AndLocationIdInPOLAndPieceTheSame() throws ExecutionException, InterruptedException {
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(2).withQuantity(2);
List<Location> locations = new ArrayList<>();
locations.add(loc);
Cost cost = new Cost().withQuantityElectronic(2).withListUnitPriceElectronic(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE_HOLDING);
PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.ELECTRONIC_RESOURCE).withId(lineId).withEresource(eresource).withLocations(locations).withCost(cost);
PieceDeletionHolder incomingUpdateHolder = new PieceDeletionHolder().withPieceToDelete(piece).withDeleteHolding(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
pieceDeleteFlowPoLineService.updatePoLine(incomingUpdateHolder, requestContext).get();
// Then
CompositePoLine poLineToSave = incomingUpdateHolder.getPoLineToSave();
assertNull(poLineToSave.getCost().getQuantityPhysical());
assertEquals(1, poLineToSave.getCost().getQuantityElectronic());
assertEquals(1, poLineToSave.getLocations().size());
assertNull(poLineToSave.getLocations().get(0).getQuantityPhysical());
assertEquals(1, poLineToSave.getLocations().get(0).getQuantityElectronic());
assertEquals(1, poLineToSave.getLocations().get(0).getQuantity());
verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
use of org.folio.models.pieces.PieceDeletionHolder in project mod-orders by folio-org.
the class PieceDeleteFlowPoLineServiceTest method physDeleteLocationStrategyShouldDecreaseQuantityTo1ForCostAndLocationIfInitiallyWas1AndLocationIdInPOLAndPieceTheSame.
@Test
@DisplayName("Should delete POL location if 1 physical piece with location to physical pol with 1 location and same location id as in piece")
void physDeleteLocationStrategyShouldDecreaseQuantityTo1ForCostAndLocationIfInitiallyWas1AndLocationIdInPOLAndPieceTheSame() throws ExecutionException, InterruptedException {
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.PHYSICAL);
Location loc = new Location().withLocationId(locationId).withQuantityPhysical(1).withQuantity(1);
List<Location> locations = new ArrayList<>();
locations.add(loc);
Cost cost = new Cost().withQuantityPhysical(1).withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM);
PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.PHYSICAL_RESOURCE).withId(lineId).withPhysical(physical).withLocations(List.of(loc)).withCost(cost);
PieceDeletionHolder incomingUpdateHolder = new PieceDeletionHolder().withPieceToDelete(piece).withDeleteHolding(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
pieceDeleteFlowPoLineService.updatePoLine(incomingUpdateHolder, requestContext).get();
// Then
CompositePoLine poLineToSave = incomingUpdateHolder.getPoLineToSave();
assertNull(poLineToSave.getCost().getQuantityElectronic());
assertEquals(0, poLineToSave.getCost().getQuantityPhysical());
assertEquals(Collections.emptyList(), poLineToSave.getLocations());
verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
use of org.folio.models.pieces.PieceDeletionHolder in project mod-orders by folio-org.
the class PieceDeleteFlowPoLineServiceTest method physDeleteStrategyShouldDecreaseQuantityTo1ForCostAndLocationIfInitiallyWas1AndHoldingIdInPOLAndPieceTheSame.
@Test
@DisplayName("Delete 1 physical piece with holding to physical pol with 1 location and same holding id as in piece")
void physDeleteStrategyShouldDecreaseQuantityTo1ForCostAndLocationIfInitiallyWas1AndHoldingIdInPOLAndPieceTheSame() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
Piece piece = new Piece().withPoLineId(lineId).withHoldingId(holdingId).withFormat(Piece.Format.PHYSICAL);
Location loc = new Location().withHoldingId(holdingId).withQuantityPhysical(2).withQuantity(2);
List<Location> locations = new ArrayList<>();
locations.add(loc);
Cost cost = new Cost().withQuantityPhysical(2).withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(2d);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM);
PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.PHYSICAL_RESOURCE).withId(lineId).withPhysical(physical).withLocations(List.of(loc)).withCost(cost);
PieceDeletionHolder incomingUpdateHolder = new PieceDeletionHolder().withPieceToDelete(piece).withDeleteHolding(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
pieceDeleteFlowPoLineService.updatePoLine(incomingUpdateHolder, requestContext).get();
// Then
CompositePoLine poLineToSave = incomingUpdateHolder.getPoLineToSave();
assertNull(poLineToSave.getCost().getQuantityElectronic());
assertEquals(1, poLineToSave.getCost().getQuantityPhysical());
assertEquals(1, poLineToSave.getLocations().size());
assertNull(poLineToSave.getLocations().get(0).getQuantityElectronic());
assertEquals(1, poLineToSave.getLocations().get(0).getQuantityPhysical());
assertEquals(1, poLineToSave.getLocations().get(0).getQuantity());
verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
Aggregations