Search in sources :

Example 11 with PieceDeletionHolder

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);
}
Also used : Piece(org.folio.rest.jaxrs.model.Piece) PieceDeletionHolder(org.folio.models.pieces.PieceDeletionHolder) PoLine(org.folio.rest.jaxrs.model.PoLine) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) ArrayList(java.util.ArrayList) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Cost(org.folio.rest.jaxrs.model.Cost) Eresource(org.folio.rest.jaxrs.model.Eresource) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 12 with PieceDeletionHolder

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);
}
Also used : Piece(org.folio.rest.jaxrs.model.Piece) PieceDeletionHolder(org.folio.models.pieces.PieceDeletionHolder) PoLine(org.folio.rest.jaxrs.model.PoLine) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) ArrayList(java.util.ArrayList) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Cost(org.folio.rest.jaxrs.model.Cost) Eresource(org.folio.rest.jaxrs.model.Eresource) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 13 with PieceDeletionHolder

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);
}
Also used : Physical(org.folio.rest.jaxrs.model.Physical) Piece(org.folio.rest.jaxrs.model.Piece) PieceDeletionHolder(org.folio.models.pieces.PieceDeletionHolder) PoLine(org.folio.rest.jaxrs.model.PoLine) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) ArrayList(java.util.ArrayList) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Cost(org.folio.rest.jaxrs.model.Cost) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 14 with PieceDeletionHolder

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);
}
Also used : Physical(org.folio.rest.jaxrs.model.Physical) Piece(org.folio.rest.jaxrs.model.Piece) PieceDeletionHolder(org.folio.models.pieces.PieceDeletionHolder) PoLine(org.folio.rest.jaxrs.model.PoLine) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) ArrayList(java.util.ArrayList) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Cost(org.folio.rest.jaxrs.model.Cost) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

PieceDeletionHolder (org.folio.models.pieces.PieceDeletionHolder)14 Piece (org.folio.rest.jaxrs.model.Piece)14 Cost (org.folio.rest.jaxrs.model.Cost)12 PoLine (org.folio.rest.jaxrs.model.PoLine)12 PurchaseOrder (org.folio.rest.jaxrs.model.PurchaseOrder)12 ArrayList (java.util.ArrayList)11 Location (org.folio.rest.jaxrs.model.Location)11 Test (org.junit.jupiter.api.Test)10 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)9 Eresource (org.folio.rest.jaxrs.model.Eresource)8 DisplayName (org.junit.jupiter.api.DisplayName)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 JsonObject (io.vertx.core.json.JsonObject)5 List (java.util.List)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)5 ItemStatus (org.folio.models.ItemStatus)5 RequestContext (org.folio.rest.core.models.RequestContext)5 ProtectionService (org.folio.service.ProtectionService)5 InventoryManager (org.folio.service.inventory.InventoryManager)5