use of org.folio.rest.jaxrs.model.Physical in project mod-orders by folio-org.
the class PieceUpdateFlowInventoryManagerTest method shouldDeleteHoldingWhenPhysPieceUpdateForPackagePoLineWithCreateInventoryAllAndPieceContainsNewHolding.
@Test
void shouldDeleteHoldingWhenPhysPieceUpdateForPackagePoLineWithCreateInventoryAllAndPieceContainsNewHolding() {
String orderId = UUID.randomUUID().toString();
String holdingFromStorageId = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
String titleId = UUID.randomUUID().toString();
String itemId = UUID.randomUUID().toString();
String pieceId = UUID.randomUUID().toString();
String instanceId = UUID.randomUUID().toString();
Title title = new Title().withId(titleId).withPoLineId(lineId).withInstanceId(instanceId);
JsonObject holding = new JsonObject().put(ID, holdingFromStorageId);
holding.put(HOLDING_PERMANENT_LOCATION_ID, UUID.randomUUID().toString());
Piece pieceFromStorage = new Piece().withId(pieceId).withTitleId(titleId).withItemId(itemId).withPoLineId(lineId).withHoldingId(holdingFromStorageId).withFormat(Piece.Format.PHYSICAL);
Piece pieceToUpdate = new Piece().withId(pieceId).withTitleId(titleId).withItemId(itemId).withPoLineId(lineId).withHoldingId(holdingId).withFormat(Piece.Format.PHYSICAL);
Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(1).withQuantity(1);
Cost cost = new Cost().withQuantityElectronic(1);
PoLine poLine = new PoLine().withIsPackage(true).withPurchaseOrderId(orderId).withId(lineId).withOrderFormat(PoLine.OrderFormat.PHYSICAL_RESOURCE).withId(lineId).withPhysical(new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM)).withLocations(List.of(loc)).withCost(cost);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
PieceUpdateHolder holder = new PieceUpdateHolder().withPieceToUpdate(pieceToUpdate).withPieceFromStorage(pieceFromStorage).withCreateItem(true).withDeleteHolding(true);
holder.withOrderInformation(purchaseOrder, poLine);
doReturn(completedFuture(title)).when(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext);
doReturn(completedFuture(new JsonObject())).when(inventoryManager).getItemRecordById(pieceToUpdate.getItemId(), true, requestContext);
doReturn(completedFuture(List.of(itemId))).when(inventoryManager).createMissingPhysicalItems(holder.getPoLineToSave(), pieceToUpdate, 1, requestContext);
doReturn(completedFuture(null)).when(inventoryManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext);
doReturn(completedFuture(holding)).when(inventoryManager).getHoldingById(holder.getPieceFromStorage().getHoldingId(), true, requestContext);
doReturn(completedFuture(new ArrayList())).when(inventoryManager).getItemsByHoldingId(holder.getPieceFromStorage().getHoldingId(), requestContext);
doReturn(completedFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext);
doReturn(completedFuture(itemId)).when(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(pieceToUpdate, holder.getPoLineToSave(), requestContext);
pieceUpdateFlowInventoryManager.processInventory(holder, requestContext).join();
verify(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext);
verify(inventoryManager, times(0)).getOrCreateHoldingsRecord(eq(holder.getInstanceId()), any(Location.class), eq(requestContext));
verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext);
verify(inventoryManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext);
verify(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(pieceToUpdate, holder.getPoLineToSave(), requestContext);
}
use of org.folio.rest.jaxrs.model.Physical in project mod-orders by folio-org.
the class PieceUpdateFlowInventoryManagerTest method shouldUpdateItemWithNewHoldingIdWhenPhysPieceUpdateForPackagePoLineWithCreateInventoryAllAndPieceContainsNewHolding.
@Test
void shouldUpdateItemWithNewHoldingIdWhenPhysPieceUpdateForPackagePoLineWithCreateInventoryAllAndPieceContainsNewHolding() {
String orderId = UUID.randomUUID().toString();
String holdingFromStorageId = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
String titleId = UUID.randomUUID().toString();
String itemId = UUID.randomUUID().toString();
String pieceId = UUID.randomUUID().toString();
String instanceId = UUID.randomUUID().toString();
Title title = new Title().withId(titleId).withPoLineId(lineId).withInstanceId(instanceId);
JsonObject item = new JsonObject().put(ID, itemId);
item.put(ITEM_STATUS, new JsonObject().put(ITEM_STATUS_NAME, ItemStatus.ON_ORDER.value()));
item.put(ITEM_HOLDINGS_RECORD_ID, holdingFromStorageId);
JsonObject holding = new JsonObject().put(ID, holdingFromStorageId);
holding.put(HOLDING_PERMANENT_LOCATION_ID, UUID.randomUUID().toString());
Piece pieceFromStorage = new Piece().withId(pieceId).withTitleId(titleId).withItemId(itemId).withPoLineId(lineId).withHoldingId(holdingFromStorageId).withFormat(Piece.Format.PHYSICAL);
Piece pieceToUpdate = new Piece().withId(pieceId).withTitleId(titleId).withItemId(itemId).withPoLineId(lineId).withHoldingId(holdingId).withFormat(Piece.Format.PHYSICAL);
Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(1).withQuantity(1);
Cost cost = new Cost().withQuantityElectronic(1);
PoLine poLine = new PoLine().withIsPackage(true).withPurchaseOrderId(orderId).withId(lineId).withOrderFormat(PoLine.OrderFormat.PHYSICAL_RESOURCE).withId(lineId).withPhysical(new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM)).withLocations(List.of(loc)).withCost(cost);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
PieceUpdateHolder holder = new PieceUpdateHolder().withPieceToUpdate(pieceToUpdate).withPieceFromStorage(pieceFromStorage).withCreateItem(true).withDeleteHolding(true);
holder.withOrderInformation(purchaseOrder, poLine);
doReturn(completedFuture(title)).when(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext);
doReturn(completedFuture(item)).when(inventoryManager).getItemRecordById(pieceToUpdate.getItemId(), true, requestContext);
doReturn(completedFuture(null)).when(inventoryManager).updateItem(item, requestContext);
doReturn(completedFuture(List.of(itemId))).when(inventoryManager).createMissingPhysicalItems(holder.getPoLineToSave(), pieceToUpdate, 1, requestContext);
doReturn(completedFuture(null)).when(inventoryManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext);
doReturn(completedFuture(holding)).when(inventoryManager).getHoldingById(holder.getPieceFromStorage().getHoldingId(), true, requestContext);
doReturn(completedFuture(new ArrayList())).when(inventoryManager).getItemsByHoldingId(holder.getPieceFromStorage().getHoldingId(), requestContext);
doReturn(completedFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext);
pieceUpdateFlowInventoryManager.processInventory(holder, requestContext).join();
assertEquals(holdingId, item.getString(ITEM_HOLDINGS_RECORD_ID));
assertEquals(holder.getPoLineToSave().getId(), item.getString(ITEM_PURCHASE_ORDER_LINE_IDENTIFIER));
verify(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext);
verify(inventoryManager, times(0)).getOrCreateHoldingsRecord(eq(holder.getInstanceId()), any(Location.class), eq(requestContext));
verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext);
verify(inventoryManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext);
verify(inventoryManager, times(0)).createMissingElectronicItems(holder.getPoLineToSave(), pieceToUpdate, 1, requestContext);
verify(inventoryManager, times(0)).createMissingPhysicalItems(holder.getPoLineToSave(), pieceToUpdate, 1, requestContext);
verify(inventoryManager).updateItem(item, requestContext);
}
use of org.folio.rest.jaxrs.model.Physical in project mod-orders by folio-org.
the class PieceUpdateFlowInventoryManagerTest method shouldDeleteHoldingWhenPhysPieceUpdateForNonPackagePoLineWithCreateInventoryAllAndPieceContainsNewHoldingAndTitleWithInstanceId.
@Test
void shouldDeleteHoldingWhenPhysPieceUpdateForNonPackagePoLineWithCreateInventoryAllAndPieceContainsNewHoldingAndTitleWithInstanceId() {
String orderId = UUID.randomUUID().toString();
String holdingFromStorageId = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
String titleId = UUID.randomUUID().toString();
String itemId = UUID.randomUUID().toString();
String pieceId = UUID.randomUUID().toString();
String instanceId = UUID.randomUUID().toString();
JsonObject holding = new JsonObject().put(ID, holdingFromStorageId);
holding.put(HOLDING_PERMANENT_LOCATION_ID, UUID.randomUUID().toString());
Title title = new Title().withId(titleId).withPoLineId(lineId).withInstanceId(instanceId);
Piece pieceFromStorage = new Piece().withId(pieceId).withTitleId(titleId).withItemId(itemId).withPoLineId(lineId).withHoldingId(holdingFromStorageId).withFormat(Piece.Format.PHYSICAL);
Piece pieceToUpdate = new Piece().withId(pieceId).withTitleId(titleId).withItemId(itemId).withPoLineId(lineId).withHoldingId(holdingId).withFormat(Piece.Format.PHYSICAL);
Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(1).withQuantity(1);
Cost cost = new Cost().withQuantityElectronic(1);
PoLine poLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withId(lineId).withOrderFormat(PoLine.OrderFormat.PHYSICAL_RESOURCE).withId(lineId).withPhysical(new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM)).withLocations(List.of(loc)).withCost(cost);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
PieceUpdateHolder holder = new PieceUpdateHolder().withPieceToUpdate(pieceToUpdate).withPieceFromStorage(pieceFromStorage).withCreateItem(true).withDeleteHolding(true);
holder.withOrderInformation(purchaseOrder, poLine);
doReturn(completedFuture(title)).when(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext);
doReturn(completedFuture(new JsonObject())).when(inventoryManager).getItemRecordById(pieceToUpdate.getItemId(), true, requestContext);
doReturn(completedFuture(List.of(itemId))).when(inventoryManager).createMissingPhysicalItems(holder.getPoLineToSave(), pieceToUpdate, 1, requestContext);
doReturn(completedFuture(null)).when(inventoryManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext);
doReturn(completedFuture(holding)).when(inventoryManager).getHoldingById(holder.getPieceFromStorage().getHoldingId(), true, requestContext);
doReturn(completedFuture(new ArrayList())).when(inventoryManager).getItemsByHoldingId(holder.getPieceFromStorage().getHoldingId(), requestContext);
doReturn(completedFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext);
doReturn(completedFuture(itemId)).when(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(pieceToUpdate, holder.getPoLineToSave(), requestContext);
pieceUpdateFlowInventoryManager.processInventory(holder, requestContext).join();
verify(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext);
verify(inventoryManager, times(0)).getOrCreateHoldingsRecord(eq(holder.getInstanceId()), any(Location.class), eq(requestContext));
verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext);
verify(inventoryManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext);
verify(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(pieceToUpdate, holder.getPoLineToSave(), requestContext);
}
use of org.folio.rest.jaxrs.model.Physical in project mod-orders by folio-org.
the class PieceUpdateFlowInventoryManagerTest method shouldNotTryToUpdateItemWhenUpdatingPieceThatDoesNotHaveItem.
@Test
void shouldNotTryToUpdateItemWhenUpdatingPieceThatDoesNotHaveItem() {
String orderId = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
String titleId = UUID.randomUUID().toString();
String pieceId = UUID.randomUUID().toString();
String instanceId = UUID.randomUUID().toString();
String caption = "updated";
JsonObject item = new JsonObject();
JsonObject holding = new JsonObject().put(ID, holdingId);
holding.put(HOLDING_PERMANENT_LOCATION_ID, UUID.randomUUID().toString());
Piece pieceFromStorage = new Piece().withId(pieceId).withTitleId(titleId).withPoLineId(lineId).withHoldingId(holdingId).withFormat(Piece.Format.PHYSICAL);
Piece pieceToUpdate = new Piece().withId(pieceId).withTitleId(titleId).withPoLineId(lineId).withHoldingId(holdingId).withFormat(Piece.Format.PHYSICAL).withCaption(caption);
Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(1).withQuantity(1);
Cost cost = new Cost().withQuantityElectronic(1);
PoLine poLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withId(lineId).withInstanceId(instanceId).withOrderFormat(PoLine.OrderFormat.PHYSICAL_RESOURCE).withId(lineId).withPhysical(new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM)).withLocations(List.of(loc)).withCost(cost);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
PieceUpdateHolder holder = new PieceUpdateHolder().withPieceToUpdate(pieceToUpdate).withPieceFromStorage(pieceFromStorage).withCreateItem(false).withDeleteHolding(false);
holder.withOrderInformation(purchaseOrder, poLine);
doReturn(completedFuture(new JsonObject())).when(inventoryManager).getItemRecordById(null, true, requestContext);
doReturn(completedFuture(null)).when(inventoryManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext);
pieceUpdateFlowInventoryManager.processInventory(holder, requestContext).join();
verify(inventoryManager, times(1)).getItemRecordById(null, true, requestContext);
verify(pieceUpdateInventoryService, times(0)).manualPieceFlowCreateItemRecord(pieceToUpdate, holder.getPoLineToSave(), requestContext);
verify(inventoryManager, times(0)).updateItem(item, requestContext);
}
use of org.folio.rest.jaxrs.model.Physical in project mod-orders by folio-org.
the class PieceUpdateFlowInventoryManagerTest method shouldDeleteHoldingWhenPhysPieceUpdateForPackagePoLineWithCreateInventoryAllAndPieceContainsNewHoldingAndTitleWithInstanceId.
@Test
void shouldDeleteHoldingWhenPhysPieceUpdateForPackagePoLineWithCreateInventoryAllAndPieceContainsNewHoldingAndTitleWithInstanceId() {
String orderId = UUID.randomUUID().toString();
String holdingFromStorageId = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
String titleId = UUID.randomUUID().toString();
String itemId = UUID.randomUUID().toString();
String pieceId = UUID.randomUUID().toString();
String instanceId = UUID.randomUUID().toString();
JsonObject holding = new JsonObject().put(ID, holdingFromStorageId);
holding.put(HOLDING_PERMANENT_LOCATION_ID, UUID.randomUUID().toString());
Title title = new Title().withId(titleId).withPoLineId(lineId).withInstanceId(instanceId);
Piece pieceFromStorage = new Piece().withId(pieceId).withTitleId(titleId).withItemId(itemId).withPoLineId(lineId).withHoldingId(holdingFromStorageId).withFormat(Piece.Format.PHYSICAL);
Piece pieceToUpdate = new Piece().withId(pieceId).withTitleId(titleId).withItemId(itemId).withPoLineId(lineId).withHoldingId(holdingId).withFormat(Piece.Format.PHYSICAL);
Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(1).withQuantity(1);
Cost cost = new Cost().withQuantityElectronic(1);
PoLine poLine = new PoLine().withIsPackage(true).withPurchaseOrderId(orderId).withId(lineId).withOrderFormat(PoLine.OrderFormat.PHYSICAL_RESOURCE).withId(lineId).withPhysical(new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM)).withLocations(List.of(loc)).withCost(cost);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
PieceUpdateHolder holder = new PieceUpdateHolder().withPieceToUpdate(pieceToUpdate).withPieceFromStorage(pieceFromStorage).withCreateItem(true).withDeleteHolding(true);
holder.withOrderInformation(purchaseOrder, poLine);
doReturn(completedFuture(title)).when(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext);
doReturn(completedFuture(new JsonObject())).when(inventoryManager).getItemRecordById(pieceToUpdate.getItemId(), true, requestContext);
doReturn(completedFuture(List.of(itemId))).when(inventoryManager).createMissingPhysicalItems(holder.getPoLineToSave(), pieceToUpdate, 1, requestContext);
doReturn(completedFuture(null)).when(inventoryManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext);
doReturn(completedFuture(holding)).when(inventoryManager).getHoldingById(holder.getPieceFromStorage().getHoldingId(), true, requestContext);
doReturn(completedFuture(new ArrayList())).when(inventoryManager).getItemsByHoldingId(holder.getPieceFromStorage().getHoldingId(), requestContext);
doReturn(completedFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext);
doReturn(completedFuture(itemId)).when(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(pieceToUpdate, holder.getPoLineToSave(), requestContext);
pieceUpdateFlowInventoryManager.processInventory(holder, requestContext).join();
verify(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext);
verify(inventoryManager, times(0)).getOrCreateHoldingsRecord(eq(holder.getInstanceId()), any(Location.class), eq(requestContext));
verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext);
verify(inventoryManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext);
verify(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(pieceToUpdate, holder.getPoLineToSave(), requestContext);
}
Aggregations