use of org.folio.service.ProtectionService in project mod-orders by folio-org.
the class PieceUpdateFlowManagerTest method shouldNotUpdateLineQuantityIfManualPieceCreateTrueAndShouldRunProcessInventory.
@Test
void shouldNotUpdateLineQuantityIfManualPieceCreateTrueAndShouldRunProcessInventory() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
String holdingIdTpUpdate = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
String titleId = UUID.randomUUID().toString();
String itemId = UUID.randomUUID().toString();
String locationId = UUID.randomUUID().toString();
JsonObject item = new JsonObject().put(ID, itemId);
String pieceId = UUID.randomUUID().toString();
item.put(ITEM_STATUS, new JsonObject().put(ITEM_STATUS_NAME, ItemStatus.ON_ORDER.value()));
JsonObject holding = new JsonObject().put(ID, holdingId);
holding.put(HOLDING_PERMANENT_LOCATION_ID, locationId);
Piece pieceFromStorage = new Piece().withId(pieceId).withPoLineId(lineId).withItemId(itemId).withTitleId(titleId).withHoldingId(holdingId).withFormat(Piece.Format.ELECTRONIC);
Piece pieceToUpdate = new Piece().withId(pieceId).withPoLineId(lineId).withItemId(itemId).withTitleId(titleId).withHoldingId(holdingIdTpUpdate).withFormat(Piece.Format.ELECTRONIC);
Cost cost = new Cost().withQuantityElectronic(1);
Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(1).withQuantity(1);
Eresource eresource = new Eresource().withCreateInventory(INSTANCE_HOLDING_ITEM);
PoLine poLine = new PoLine().withIsPackage(false).withCheckinItems(true).withPurchaseOrderId(orderId).withId(lineId).withOrderFormat(PoLine.OrderFormat.ELECTRONIC_RESOURCE).withEresource(eresource).withLocations(List.of(loc)).withCost(cost);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
doReturn(completedFuture(pieceFromStorage)).when(pieceStorageService).getPieceById(pieceToUpdate.getId(), requestContext);
doReturn(completedFuture(null)).when(pieceStorageService).updatePiece(pieceToUpdate, requestContext);
final ArgumentCaptor<PieceUpdateHolder> pieceUpdateHolderCapture = ArgumentCaptor.forClass(PieceUpdateHolder.class);
doAnswer((Answer<CompletableFuture<Void>>) invocation -> {
PieceUpdateHolder answerHolder = invocation.getArgument(0);
answerHolder.withOrderInformation(purchaseOrder, poLine);
return completedFuture(null);
}).when(basePieceFlowHolderBuilder).updateHolderWithOrderInformation(pieceUpdateHolderCapture.capture(), eq(requestContext));
doReturn(completedFuture(null)).when(protectionService).isOperationRestricted(any(List.class), any(ProtectedOperationType.class), eq(requestContext));
doReturn(completedFuture(null)).when(pieceUpdateFlowInventoryManager).processInventory(any(PieceUpdateHolder.class), eq(requestContext));
doNothing().when(pieceService).receiptConsistencyPiecePoLine(any(JsonObject.class), eq(requestContext));
doReturn(completedFuture(null)).when(pieceUpdateFlowPoLineService).updatePoLine(pieceUpdateHolderCapture.capture(), eq(requestContext));
// When
pieceUpdateFlowManager.updatePiece(pieceToUpdate, true, true, requestContext).get();
// Then
PieceUpdateHolder holder = pieceUpdateHolderCapture.getValue();
assertNull(poLine.getLocations().get(0).getLocationId());
assertEquals(holdingId, poLine.getLocations().get(0).getHoldingId());
verify(basePieceFlowHolderBuilder).updateHolderWithOrderInformation(holder, requestContext);
verify(pieceUpdateFlowPoLineService, times(0)).updatePoLine(pieceUpdateHolderCapture.capture(), eq(requestContext));
verify(pieceUpdateFlowInventoryManager).processInventory(any(PieceUpdateHolder.class), eq(requestContext));
verify(pieceStorageService).updatePiece(pieceToUpdate, requestContext);
}
use of org.folio.service.ProtectionService in project mod-orders by folio-org.
the class PieceUpdateFlowManagerTest method shouldNotUpdateLineQuantityIfPoLineIsPackageAndShouldRunProcessInventory.
@Test
void shouldNotUpdateLineQuantityIfPoLineIsPackageAndShouldRunProcessInventory() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
String holdingIdTpUpdate = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
String titleId = UUID.randomUUID().toString();
String itemId = UUID.randomUUID().toString();
String locationId = UUID.randomUUID().toString();
JsonObject item = new JsonObject().put(ID, itemId);
String pieceId = UUID.randomUUID().toString();
item.put(ITEM_STATUS, new JsonObject().put(ITEM_STATUS_NAME, ItemStatus.ON_ORDER.value()));
JsonObject holding = new JsonObject().put(ID, holdingId);
holding.put(HOLDING_PERMANENT_LOCATION_ID, locationId);
Piece pieceFromStorage = new Piece().withId(pieceId).withPoLineId(lineId).withItemId(itemId).withTitleId(titleId).withHoldingId(holdingId).withFormat(Piece.Format.ELECTRONIC);
Piece pieceToUpdate = new Piece().withId(pieceId).withPoLineId(lineId).withItemId(itemId).withTitleId(titleId).withHoldingId(holdingIdTpUpdate).withFormat(Piece.Format.ELECTRONIC);
Cost cost = new Cost().withQuantityElectronic(1);
Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(1).withQuantity(1);
Eresource eresource = new Eresource().withCreateInventory(INSTANCE_HOLDING_ITEM);
PoLine poLine = new PoLine().withIsPackage(true).withPurchaseOrderId(orderId).withId(lineId).withOrderFormat(PoLine.OrderFormat.ELECTRONIC_RESOURCE).withEresource(eresource).withLocations(List.of(loc)).withCost(cost);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
doReturn(completedFuture(pieceFromStorage)).when(pieceStorageService).getPieceById(pieceToUpdate.getId(), requestContext);
doReturn(completedFuture(null)).when(pieceStorageService).updatePiece(pieceToUpdate, requestContext);
final ArgumentCaptor<PieceUpdateHolder> pieceUpdateHolderCapture = ArgumentCaptor.forClass(PieceUpdateHolder.class);
doAnswer((Answer<CompletableFuture<Void>>) invocation -> {
PieceUpdateHolder answerHolder = invocation.getArgument(0);
answerHolder.withOrderInformation(purchaseOrder, poLine);
return completedFuture(null);
}).when(basePieceFlowHolderBuilder).updateHolderWithOrderInformation(pieceUpdateHolderCapture.capture(), eq(requestContext));
doReturn(completedFuture(null)).when(protectionService).isOperationRestricted(any(List.class), any(ProtectedOperationType.class), eq(requestContext));
doReturn(completedFuture(null)).when(pieceUpdateFlowInventoryManager).processInventory(any(PieceUpdateHolder.class), eq(requestContext));
doNothing().when(pieceService).receiptConsistencyPiecePoLine(any(JsonObject.class), eq(requestContext));
doReturn(completedFuture(null)).when(pieceUpdateFlowPoLineService).updatePoLine(pieceUpdateHolderCapture.capture(), eq(requestContext));
// When
pieceUpdateFlowManager.updatePiece(pieceToUpdate, true, true, requestContext).get();
// Then
PieceUpdateHolder holder = pieceUpdateHolderCapture.getValue();
assertNull(poLine.getLocations().get(0).getLocationId());
assertEquals(holdingId, poLine.getLocations().get(0).getHoldingId());
verify(basePieceFlowHolderBuilder).updateHolderWithOrderInformation(holder, requestContext);
verify(pieceUpdateFlowPoLineService, times(0)).updatePoLine(pieceUpdateHolderCapture.capture(), eq(requestContext));
verify(pieceUpdateFlowInventoryManager).processInventory(any(PieceUpdateHolder.class), eq(requestContext));
verify(pieceStorageService).updatePiece(pieceToUpdate, requestContext);
}
use of org.folio.service.ProtectionService in project mod-orders by folio-org.
the class PieceUpdateFlowManagerTest method shouldUpdateLineQuantityIfPoLineIsNotPackageAndHoldingReferenceChangedAndShouldRunProcessInventory.
@Test
void shouldUpdateLineQuantityIfPoLineIsNotPackageAndHoldingReferenceChangedAndShouldRunProcessInventory() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String oldHoldingId = UUID.randomUUID().toString();
String holdingIdToUpdate = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
String titleId = UUID.randomUUID().toString();
String itemId = UUID.randomUUID().toString();
String locationId = UUID.randomUUID().toString();
String pieceId = UUID.randomUUID().toString();
JsonObject item = new JsonObject().put(ID, itemId);
item.put(ITEM_STATUS, new JsonObject().put(ITEM_STATUS_NAME, ItemStatus.ON_ORDER.value()));
JsonObject holding = new JsonObject().put(ID, oldHoldingId);
holding.put(HOLDING_PERMANENT_LOCATION_ID, locationId);
Piece pieceFromStorage = new Piece().withId(pieceId).withPoLineId(lineId).withItemId(itemId).withTitleId(titleId).withHoldingId(oldHoldingId).withFormat(Piece.Format.ELECTRONIC);
Piece incomingPieceToUpdate = new Piece().withId(pieceId).withPoLineId(lineId).withItemId(itemId).withTitleId(titleId).withHoldingId(holdingIdToUpdate).withFormat(Piece.Format.ELECTRONIC);
Cost cost = new Cost().withQuantityElectronic(1);
Location loc = new Location().withHoldingId(oldHoldingId).withQuantityElectronic(1).withQuantity(1);
PoLine poLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withId(lineId).withEresource(new Eresource().withCreateInventory(INSTANCE_HOLDING_ITEM)).withOrderFormat(PoLine.OrderFormat.ELECTRONIC_RESOURCE).withLocations(List.of(loc)).withCost(cost);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
doReturn(completedFuture(pieceFromStorage)).when(pieceStorageService).getPieceById(incomingPieceToUpdate.getId(), requestContext);
final ArgumentCaptor<Piece> pieceToUpdateCapture = ArgumentCaptor.forClass(Piece.class);
doReturn(completedFuture(null)).when(pieceStorageService).updatePiece(pieceToUpdateCapture.capture(), eq(requestContext));
doNothing().when(pieceService).receiptConsistencyPiecePoLine(any(JsonObject.class), eq(requestContext));
final ArgumentCaptor<PieceUpdateHolder> pieceUpdateHolderCapture = ArgumentCaptor.forClass(PieceUpdateHolder.class);
doAnswer((Answer<CompletableFuture<Void>>) invocation -> {
PieceUpdateHolder answerHolder = invocation.getArgument(0);
answerHolder.withOrderInformation(purchaseOrder, poLine);
return completedFuture(null);
}).when(basePieceFlowHolderBuilder).updateHolderWithOrderInformation(pieceUpdateHolderCapture.capture(), eq(requestContext));
doReturn(completedFuture(null)).when(protectionService).isOperationRestricted(any(List.class), any(ProtectedOperationType.class), eq(requestContext));
doReturn(completedFuture(null)).when(pieceUpdateFlowInventoryManager).processInventory(pieceUpdateHolderCapture.capture(), eq(requestContext));
doReturn(completedFuture(null)).when(pieceUpdateFlowPoLineService).updatePoLine(pieceUpdateHolderCapture.capture(), eq(requestContext));
// When
pieceUpdateFlowManager.updatePiece(incomingPieceToUpdate, true, true, requestContext).get();
// Then
Piece pieceToUpdate = pieceToUpdateCapture.getValue();
PieceUpdateHolder pieceUpdateHolder = pieceUpdateHolderCapture.getValue();
verify(basePieceFlowHolderBuilder).updateHolderWithOrderInformation(pieceUpdateHolderCapture.capture(), eq(requestContext));
verify(pieceUpdateFlowPoLineService).updatePoLine(pieceUpdateHolderCapture.capture(), eq(requestContext));
verify(pieceUpdateFlowInventoryManager).processInventory(any(PieceUpdateHolder.class), eq(requestContext));
verify(pieceStorageService).updatePiece(pieceToUpdate, requestContext);
}
use of org.folio.service.ProtectionService in project mod-orders by folio-org.
the class OpenCompositeOrderPieceServiceTest method shouldCreatePieceWithLocationAndHoldingReferenceIfMixedLineContainsLocationAndInventoryIsInstanceOrNoneAndExistPiecesWithItems.
@ParameterizedTest
@CsvSource(value = { "P/E Mix:Instance:Instance, Holding, Item:2:3", "P/E Mix:None:Instance, Holding, Item:2:3" }, delimiter = ':')
void shouldCreatePieceWithLocationAndHoldingReferenceIfMixedLineContainsLocationAndInventoryIsInstanceOrNoneAndExistPiecesWithItems(String lineType, String elecCreateInventory, String physCreateInventory, int elecQty1, int physQty2) {
// given
String lineId = UUID.randomUUID().toString();
String locationId = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
String titleId = UUID.randomUUID().toString();
List<Piece> expectedPiecesWithItem = new ArrayList<>();
Location elecLocation = new Location().withQuantityElectronic(elecQty1).withQuantity(elecQty1);
if (Eresource.CreateInventory.INSTANCE_HOLDING_ITEM == Eresource.CreateInventory.fromValue(elecCreateInventory)) {
elecLocation.withHoldingId(holdingId);
expectedPiecesWithItem.addAll(createElecPiecesWithHoldingId(lineId, titleId, true, elecLocation));
} else {
elecLocation.withLocationId(locationId);
}
Location physLocation = new Location().withQuantityPhysical(physQty2).withQuantity(physQty2);
if (Physical.CreateInventory.INSTANCE_HOLDING_ITEM == Physical.CreateInventory.fromValue(physCreateInventory)) {
physLocation.withHoldingId(holdingId);
expectedPiecesWithItem.addAll(createPhysPiecesWithHoldingId(lineId, titleId, true, physLocation));
} else {
physLocation.withLocationId(locationId);
}
Cost cost = new Cost().withQuantityElectronic(elecQty1 + physQty2);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.fromValue(elecCreateInventory));
Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.fromValue(physCreateInventory));
CompositePoLine line = new CompositePoLine().withId(lineId).withCost(cost).withLocations(List.of(elecLocation, physLocation)).withIsPackage(false).withEresource(eresource).withPhysical(physical).withOrderFormat(CompositePoLine.OrderFormat.fromValue(lineType));
CompositePurchaseOrder compOrder = new CompositePurchaseOrder().withCompositePoLines(List.of(line));
doReturn(completedFuture(null)).when(openCompositeOrderPieceService).openOrderUpdateInventory(any(CompositePoLine.class), any(Piece.class), any(Boolean.class), eq(requestContext));
doReturn(completedFuture(Collections.emptyList())).when(pieceStorageService).getPiecesByPoLineId(line, requestContext);
doReturn(completedFuture(new Piece())).when(pieceStorageService).insertPiece(any(Piece.class), eq(requestContext));
doReturn(completedFuture(null)).when(protectionService).isOperationRestricted(any(List.class), any(ProtectedOperationType.class), eq(requestContext));
doReturn(completedFuture(compOrder)).when(purchaseOrderStorageService).getCompositeOrderByPoLineId(eq(lineId), eq(requestContext));
final ArgumentCaptor<Piece> pieceArgumentCaptor = ArgumentCaptor.forClass(Piece.class);
doAnswer((Answer<CompletableFuture<Piece>>) invocation -> {
Piece piece = invocation.getArgument(0);
return completedFuture(piece);
}).when(pieceStorageService).insertPiece(pieceArgumentCaptor.capture(), eq(requestContext));
// When
List<Piece> createdPieces = openCompositeOrderPieceService.handlePieces(line, titleId, expectedPiecesWithItem, false, requestContext).join();
// Then
List<Piece> piecesLocElec = createdPieces.stream().filter(piece -> Piece.Format.ELECTRONIC.equals(piece.getFormat())).collect(toList());
assertEquals(elecQty1, piecesLocElec.size());
piecesLocElec.forEach(piece -> {
assertEquals(lineId, piece.getPoLineId());
assertEquals(titleId, piece.getTitleId());
if (Eresource.CreateInventory.INSTANCE_HOLDING_ITEM == Eresource.CreateInventory.fromValue(elecCreateInventory)) {
assertEquals(holdingId, piece.getHoldingId());
assertNotNull(piece.getItemId());
} else {
assertEquals(locationId, piece.getLocationId());
assertNull(piece.getItemId());
}
});
List<Piece> piecesLocPhys = createdPieces.stream().filter(piece -> Piece.Format.PHYSICAL.equals(piece.getFormat())).collect(toList());
assertEquals(physQty2, piecesLocPhys.size());
piecesLocPhys.forEach(piece -> {
assertEquals(lineId, piece.getPoLineId());
assertEquals(titleId, piece.getTitleId());
if (Physical.CreateInventory.INSTANCE_HOLDING_ITEM == Physical.CreateInventory.fromValue(physCreateInventory)) {
assertEquals(holdingId, piece.getHoldingId());
assertNotNull(piece.getItemId());
} else {
assertEquals(locationId, piece.getLocationId());
assertNull(piece.getItemId());
}
});
}
use of org.folio.service.ProtectionService in project mod-orders by folio-org.
the class OpenCompositeOrderPieceServiceTest method shouldCreatePieceWithLocationReferenceIfMixedLineContainsLocationAndInventoryIsInstanceOrNoneAndNoCreatedPieces.
@ParameterizedTest
@CsvSource(value = { "P/E Mix:Instance:None:2:3", "P/E Mix:None:Instance:2:3", "P/E Mix:None:None:2:3", "P/E Mix:Instance:Instance:2:3" }, delimiter = ':')
void shouldCreatePieceWithLocationReferenceIfMixedLineContainsLocationAndInventoryIsInstanceOrNoneAndNoCreatedPieces(String lineType, String elecCreateInventory, String physCreateInventory, int elecQty1, int physQty2) {
// given
String lineId = UUID.randomUUID().toString();
String locationId1 = UUID.randomUUID().toString();
String locationId2 = UUID.randomUUID().toString();
String titleId = UUID.randomUUID().toString();
Location location1 = new Location().withLocationId(locationId1).withQuantityElectronic(elecQty1).withQuantity(elecQty1);
Location location2 = new Location().withLocationId(locationId2).withQuantityPhysical(physQty2).withQuantity(physQty2);
Cost cost = new Cost().withQuantityElectronic(elecQty1 + physQty2);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.fromValue(elecCreateInventory));
Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.fromValue(physCreateInventory));
CompositePoLine line = new CompositePoLine().withId(lineId).withCost(cost).withLocations(List.of(location1, location2)).withIsPackage(false).withEresource(eresource).withPhysical(physical).withOrderFormat(CompositePoLine.OrderFormat.fromValue(lineType));
CompositePurchaseOrder compOrder = new CompositePurchaseOrder().withCompositePoLines(List.of(line));
doReturn(completedFuture(null)).when(openCompositeOrderPieceService).openOrderUpdateInventory(any(CompositePoLine.class), any(Piece.class), any(Boolean.class), eq(requestContext));
doReturn(completedFuture(Collections.emptyList())).when(pieceStorageService).getPiecesByPoLineId(line, requestContext);
doReturn(completedFuture(new Piece())).when(pieceStorageService).insertPiece(any(Piece.class), eq(requestContext));
doReturn(completedFuture(null)).when(protectionService).isOperationRestricted(any(List.class), any(ProtectedOperationType.class), eq(requestContext));
doReturn(completedFuture(compOrder)).when(purchaseOrderStorageService).getCompositeOrderByPoLineId(eq(lineId), eq(requestContext));
final ArgumentCaptor<Piece> pieceArgumentCaptor = ArgumentCaptor.forClass(Piece.class);
doAnswer((Answer<CompletableFuture<Piece>>) invocation -> {
Piece piece = invocation.getArgument(0);
return completedFuture(piece);
}).when(pieceStorageService).insertPiece(pieceArgumentCaptor.capture(), eq(requestContext));
// When
List<Piece> createdPieces = openCompositeOrderPieceService.handlePieces(line, titleId, Collections.emptyList(), false, requestContext).join();
// Then
List<Piece> piecesLoc1 = createdPieces.stream().filter(piece -> piece.getLocationId().equals(locationId1)).collect(toList());
assertEquals(elecQty1, piecesLoc1.size());
piecesLoc1.forEach(piece -> {
assertNull(piece.getHoldingId());
assertNull(piece.getItemId());
assertEquals(lineId, piece.getPoLineId());
assertEquals(titleId, piece.getTitleId());
assertEquals(Piece.Format.ELECTRONIC, piece.getFormat());
});
List<Piece> piecesLoc2 = createdPieces.stream().filter(piece -> piece.getLocationId().equals(locationId2)).collect(toList());
assertEquals(physQty2, piecesLoc2.size());
piecesLoc2.forEach(piece -> {
assertNull(piece.getHoldingId());
assertNull(piece.getItemId());
assertEquals(lineId, piece.getPoLineId());
assertEquals(titleId, piece.getTitleId());
assertEquals(Piece.Format.PHYSICAL, piece.getFormat());
});
}
Aggregations