use of org.folio.rest.jaxrs.model.PoLine in project mod-orders by folio-org.
the class PieceCreateFlowPoLineServiceTest method shouldIncreaseQuantityTo3ForCostAndLocationIfInitiallyWas2AndLocationIdInPieceAndMixedPOLWithLocationId.
@Test
@DisplayName("Add 1 electronic piece with location id to mixed pol with 1 location with location id and electronic and physical qty")
void shouldIncreaseQuantityTo3ForCostAndLocationIfInitiallyWas2AndLocationIdInPieceAndMixedPOLWithLocationId() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String locationId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
Piece pieceToCreate = new Piece().withPoLineId(lineId).withLocationId(locationId).withFormat(Piece.Format.ELECTRONIC);
Location loc = new Location().withLocationId(locationId).withQuantityElectronic(1).withQuantityPhysical(1).withQuantity(2);
Cost cost = new Cost().withQuantityElectronic(1).withQuantityPhysical(1).withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE);
Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE);
PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.P_E_MIX).withId(lineId).withEresource(eresource).withPhysical(physical).withLocations(List.of(loc)).withCost(cost);
PieceCreationHolder incomingUpdateHolder = new PieceCreationHolder().withPieceToCreate(pieceToCreate).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();
assertEquals(1, poLineToSave.getLocations().size());
assertEquals(3, poLineToSave.getLocations().get(0).getQuantity());
assertEquals(1, poLineToSave.getLocations().get(0).getQuantityPhysical());
assertEquals(2, poLineToSave.getLocations().get(0).getQuantityElectronic());
assertEquals(1, poLineToSave.getCost().getQuantityPhysical());
assertEquals(2, poLineToSave.getCost().getQuantityElectronic());
verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
use of org.folio.rest.jaxrs.model.PoLine in project mod-orders by folio-org.
the class PieceCreateFlowPoLineServiceTest method shouldNotUpdateLocationIfCreateInventoryNoneForPhysicalAndNoLocationInTheLineButUpdateCostQty.
@Test
@DisplayName("Add 1 physical piece without location id to physical pol without location and physical qty and create inventory NONE")
void shouldNotUpdateLocationIfCreateInventoryNoneForPhysicalAndNoLocationInTheLineButUpdateCostQty() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
Piece pieceToCreate = new Piece().withPoLineId(lineId).withFormat(Piece.Format.PHYSICAL);
Cost cost = new Cost().withQuantityElectronic(1).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.NONE);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE);
PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.PHYSICAL_RESOURCE).withId(lineId).withEresource(eresource).withPhysical(physical).withCost(cost);
PieceCreationHolder incomingUpdateHolder = new PieceCreationHolder().withPieceToCreate(pieceToCreate).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();
assertEquals(0, poLineToSave.getLocations().size());
assertEquals(2, poLineToSave.getCost().getQuantityPhysical());
assertEquals(1, poLineToSave.getCost().getQuantityElectronic());
verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
use of org.folio.rest.jaxrs.model.PoLine in project mod-orders by folio-org.
the class PieceCreateFlowPoLineServiceTest method shouldNotUpdateLocationIfCreateInventoryNoneForElectronicButUpdateCostQty.
@Test
@DisplayName("Add 1 electronic piece without location id to mixed pol with 1 location with location id and physical qty and create inventory NONE")
void shouldNotUpdateLocationIfCreateInventoryNoneForElectronicButUpdateCostQty() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String locationId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
Piece pieceToCreate = new Piece().withPoLineId(lineId).withFormat(Piece.Format.ELECTRONIC);
Location loc = new Location().withLocationId(locationId).withQuantityPhysical(1).withQuantity(1);
Cost cost = new Cost().withQuantityElectronic(1).withQuantityPhysical(1).withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.NONE);
Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE);
PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.P_E_MIX).withId(lineId).withEresource(eresource).withPhysical(physical).withLocations(List.of(loc)).withCost(cost);
PieceCreationHolder incomingUpdateHolder = new PieceCreationHolder().withPieceToCreate(pieceToCreate).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();
assertEquals(1, poLineToSave.getLocations().size());
assertEquals(1, poLineToSave.getLocations().get(0).getQuantity());
assertEquals(1, poLineToSave.getLocations().get(0).getQuantityPhysical());
assertNull(poLineToSave.getLocations().get(0).getQuantityElectronic());
assertEquals(1, poLineToSave.getCost().getQuantityPhysical());
assertEquals(2, poLineToSave.getCost().getQuantityElectronic());
verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
use of org.folio.rest.jaxrs.model.PoLine in project mod-orders by folio-org.
the class PieceCreateFlowPoLineServiceTest method elecAddStrategyShouldIncreaseQuantityTo2ForCostAndLocationIfInitiallyWas1AndLocationIdInPieceAndPOLWithHoldingId.
@Test
@DisplayName("Add 1 electronic piece with location to electronic pol with 1 location with holding id")
void elecAddStrategyShouldIncreaseQuantityTo2ForCostAndLocationIfInitiallyWas1AndLocationIdInPieceAndPOLWithHoldingId() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String locationId = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
Piece piece = new Piece().withPoLineId(lineId).withLocationId(locationId).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);
List<Location> locations = new ArrayList<>();
locations.add(loc);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE);
PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.ELECTRONIC_RESOURCE).withId(lineId).withEresource(eresource).withLocations(List.of(loc)).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().getQuantityPhysical());
assertEquals(2, poLineToSave.getCost().getQuantityElectronic());
assertEquals(2, poLineToSave.getLocations().size());
assertNull(poLineToSave.getLocations().get(0).getQuantityPhysical());
assertNull(poLineToSave.getLocations().get(1).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.rest.jaxrs.model.PoLine in project mod-orders by folio-org.
the class PieceCreateFlowPoLineServiceTest method shouldNotUpdateLocationIfCreateInventoryNoneForPhysicalButUpdateCostQty.
@Test
@DisplayName("Add 1 physical piece without location id to mixed pol with 1 location with location id and physical qty and create inventory NONE")
void shouldNotUpdateLocationIfCreateInventoryNoneForPhysicalButUpdateCostQty() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String locationId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
Piece pieceToCreate = new Piece().withPoLineId(lineId).withFormat(Piece.Format.PHYSICAL);
Location loc = new Location().withLocationId(locationId).withQuantityElectronic(1).withQuantity(1);
Cost cost = new Cost().withQuantityElectronic(1).withQuantityPhysical(1).withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE);
Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.NONE);
PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.P_E_MIX).withId(lineId).withEresource(eresource).withPhysical(physical).withLocations(List.of(loc)).withCost(cost);
PieceCreationHolder incomingUpdateHolder = new PieceCreationHolder().withPieceToCreate(pieceToCreate).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();
assertEquals(1, poLineToSave.getLocations().size());
assertEquals(1, poLineToSave.getLocations().get(0).getQuantity());
assertEquals(1, poLineToSave.getLocations().get(0).getQuantityElectronic());
assertNull(poLineToSave.getLocations().get(0).getQuantityPhysical());
assertEquals(2, poLineToSave.getCost().getQuantityPhysical());
assertEquals(1, poLineToSave.getCost().getQuantityElectronic());
verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
Aggregations