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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations