Search in sources :

Example 96 with Piece

use of org.folio.rest.jaxrs.model.Piece in project mod-orders by folio-org.

the class PieceUpdateInventoryServiceTest method shouldNotDeleteHoldingIfHoldingIdIsNotNullButNotFoundInTheDB.

@Test
void shouldNotDeleteHoldingIfHoldingIdIsNotNullButNotFoundInTheDB() throws ExecutionException, InterruptedException {
    String holdingId = UUID.randomUUID().toString();
    Piece piece = new Piece().withId(UUID.randomUUID().toString()).withHoldingId(holdingId);
    doReturn(completedFuture(null)).when(inventoryManager).getHoldingById(piece.getHoldingId(), true, requestContext);
    pieceUpdateInventoryService.deleteHoldingConnectedToPiece(piece, requestContext).get();
    verify(inventoryManager, times(0)).deleteHoldingById(piece.getHoldingId(), true, requestContext);
}
Also used : Piece(org.folio.rest.jaxrs.model.Piece) Test(org.junit.jupiter.api.Test)

Example 97 with Piece

use of org.folio.rest.jaxrs.model.Piece in project mod-orders by folio-org.

the class PieceUpdateInventoryServiceTest method shouldNoDeleteHoldingIfHoldingIdIsProvidedAndFoundInDBAndPiecesExistAndNoItems.

@Test
void shouldNoDeleteHoldingIfHoldingIdIsProvidedAndFoundInDBAndPiecesExistAndNoItems() throws ExecutionException, InterruptedException {
    String holdingId = UUID.randomUUID().toString();
    String locationId = UUID.randomUUID().toString();
    JsonObject holding = new JsonObject();
    holding.put(ID, holding);
    holding.put(HOLDING_PERMANENT_LOCATION_ID, locationId);
    Piece piece = new Piece().withId(UUID.randomUUID().toString()).withHoldingId(holdingId);
    Piece piece2 = new Piece().withId(UUID.randomUUID().toString()).withHoldingId(holdingId);
    doReturn(completedFuture(List.of(piece, piece2))).when(pieceStorageService).getPiecesByHoldingId(holdingId, requestContext);
    doReturn(completedFuture(holding)).when(inventoryManager).getHoldingById(holdingId, true, requestContext);
    doReturn(completedFuture(new ArrayList<>())).when(inventoryManager).getItemsByHoldingId(holdingId, requestContext);
    pieceUpdateInventoryService.deleteHoldingConnectedToPiece(piece, requestContext).get();
    verify(inventoryManager, times(0)).deleteHoldingById(holdingId, true, requestContext);
}
Also used : Piece(org.folio.rest.jaxrs.model.Piece) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test)

Example 98 with Piece

use of org.folio.rest.jaxrs.model.Piece in project mod-orders by folio-org.

the class DefaultPieceFlowsValidatorTest method createPieceIsValid.

@Test
void createPieceIsValid() {
    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);
    Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE_HOLDING_ITEM);
    CompositePoLine originPoLine = new CompositePoLine().withIsPackage(true).withPurchaseOrderId(orderId).withOrderFormat(CompositePoLine.OrderFormat.ELECTRONIC_RESOURCE).withId(lineId).withEresource(eresource).withLocations(List.of(loc)).withCost(cost);
    defaultPieceFlowsValidator.isPieceRequestValid(piece, originPoLine, true);
}
Also used : Piece(org.folio.rest.jaxrs.model.Piece) 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)

Example 99 with Piece

use of org.folio.rest.jaxrs.model.Piece in project mod-orders by folio-org.

the class PieceCreateFlowPoLineServiceTest method physAddStrategyShouldIncreaseQuantityTo2ForCostAndLocationIfInitiallyWas1AndHoldingIdInPOLAndPieceTheSame.

@Test
@DisplayName("Add 1 physical piece with holding to physical pol with 1 location and same holding id as in piece")
void physAddStrategyShouldIncreaseQuantityTo2ForCostAndLocationIfInitiallyWas1AndHoldingIdInPOLAndPieceTheSame() 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(1).withQuantity(1);
    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);
    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();
    CompositePoLine poLineToSave = incomingUpdateHolder.getPoLineToSave();
    assertNull(poLineToSave.getCost().getQuantityElectronic());
    assertEquals(2, poLineToSave.getCost().getQuantityPhysical());
    assertEquals(1, poLineToSave.getLocations().size());
    assertNull(poLineToSave.getLocations().get(0).getQuantityElectronic());
    assertEquals(2, poLineToSave.getLocations().get(0).getQuantityPhysical());
    assertEquals(2, poLineToSave.getLocations().get(0).getQuantity());
    verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
    verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
Also used : PieceCreationHolder(org.folio.models.pieces.PieceCreationHolder) Physical(org.folio.rest.jaxrs.model.Physical) Piece(org.folio.rest.jaxrs.model.Piece) PoLine(org.folio.rest.jaxrs.model.PoLine) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) 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 100 with Piece

use of org.folio.rest.jaxrs.model.Piece in project mod-orders by folio-org.

the class PieceCreateFlowPoLineServiceTest method electAddStrategyShouldIncreaseQuantityTo3ForCostAndLocationIfInitiallyWas2AndLocationIdInPOLAndPieceTheSameInventoryNone.

@ParameterizedTest
@DisplayName("Add 1 electronic piece with location id to electronic pol with 2 location and another location id as in piece")
@CsvSource(value = { "Electronic Resource:Instance:2:3:Electronic:6:6.0", "Electronic Resource:None:2:3:Electronic:6:6.0" }, delimiter = ':')
void electAddStrategyShouldIncreaseQuantityTo3ForCostAndLocationIfInitiallyWas2AndLocationIdInPOLAndPieceTheSameInventoryNone(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).withQuantityElectronic(qty1).withQuantity(qty1);
    Location loc2 = new Location().withLocationId(locationId2).withQuantityElectronic(qty2).withQuantity(qty2);
    Cost cost = new Cost().withQuantityElectronic(qty1 + qty2).withListUnitPriceElectronic(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().getQuantityPhysical());
    assertEquals(expQty, poLineToSave.getCost().getQuantityElectronic());
    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.getQuantityElectronic());
    assertEquals(qty1, actLoc1.getQuantity());
    assertNull(actLoc1.getQuantityPhysical());
    assertEquals(qty2, actLoc2.getQuantityElectronic());
    assertEquals(qty2, actLoc2.getQuantity());
    assertNull(actLoc2.getQuantityPhysical());
    assertEquals(1, actLoc3.getQuantityElectronic());
    assertEquals(1, actLoc3.getQuantity());
    assertNull(actLoc3.getQuantityPhysical());
    verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
    verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
Also used : PieceCreationHolder(org.folio.models.pieces.PieceCreationHolder) Piece(org.folio.rest.jaxrs.model.Piece) PoLine(org.folio.rest.jaxrs.model.PoLine) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) 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) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

Piece (org.folio.rest.jaxrs.model.Piece)157 Test (org.junit.jupiter.api.Test)120 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)116 Location (org.folio.rest.jaxrs.model.Location)91 Cost (org.folio.rest.jaxrs.model.Cost)66 ArrayList (java.util.ArrayList)62 Eresource (org.folio.rest.jaxrs.model.Eresource)59 JsonObject (io.vertx.core.json.JsonObject)55 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)55 PoLine (org.folio.rest.jaxrs.model.PoLine)52 Physical (org.folio.rest.jaxrs.model.Physical)49 PurchaseOrder (org.folio.rest.jaxrs.model.PurchaseOrder)49 Title (org.folio.rest.jaxrs.model.Title)41 List (java.util.List)40 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)39 RequestContext (org.folio.rest.core.models.RequestContext)37 CompletableFuture (java.util.concurrent.CompletableFuture)34 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)33 Map (java.util.Map)32 Context (io.vertx.core.Context)30