use of org.folio.TestConstants.ID in project mod-orders by folio-org.
the class PieceDeleteFlowManagerTest method shouldNotUpdateLineQuantityIfPoLineIsNotPackageAndManualPieceCreateTrueAndDeleteHoldingAndItemAndPiece.
@Test
void shouldNotUpdateLineQuantityIfPoLineIsNotPackageAndManualPieceCreateTrueAndDeleteHoldingAndItemAndPiece() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String holdingId = 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);
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 piece = new Piece().withId(UUID.randomUUID().toString()).withPoLineId(lineId).withItemId(itemId).withTitleId(titleId).withHoldingId(holdingId).withFormat(Piece.Format.ELECTRONIC);
Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(1).withQuantity(1);
Cost cost = new Cost().withQuantityElectronic(1).withListUnitPriceElectronic(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
PoLine poLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withId(lineId).withLocations(List.of(loc)).withCost(cost).withCheckinItems(true);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
doReturn(completedFuture(piece)).when(pieceStorageService).getPieceById(piece.getId(), requestContext);
doReturn(completedFuture(null)).when(protectionService).isOperationRestricted(any(List.class), any(ProtectedOperationType.class), eq(requestContext));
doReturn(completedFuture(null)).when(pieceStorageService).deletePiece(eq(piece.getId()), eq(true), eq(requestContext));
doReturn(completedFuture(null)).when(inventoryManager).getNumberOfRequestsByItemId(eq(piece.getItemId()), eq(requestContext));
doReturn(completedFuture(item)).when(inventoryManager).getItemRecordById(itemId, true, requestContext);
doReturn(completedFuture(null)).when(inventoryManager).deleteItem(itemId, true, requestContext);
doReturn(completedFuture(holding)).when(inventoryManager).getHoldingById(holdingId, true, requestContext);
doReturn(completedFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(piece, requestContext);
doReturn(completedFuture(new ArrayList())).when(inventoryManager).getItemsByHoldingId(holdingId, requestContext);
final ArgumentCaptor<PieceDeletionHolder> PieceDeletionHolderCapture = ArgumentCaptor.forClass(PieceDeletionHolder.class);
doAnswer((Answer<CompletableFuture<Void>>) invocation -> {
PieceDeletionHolder answerHolder = invocation.getArgument(0);
answerHolder.withOrderInformation(purchaseOrder, poLine);
return completedFuture(null);
}).when(basePieceFlowHolderBuilder).updateHolderWithOrderInformation(PieceDeletionHolderCapture.capture(), eq(requestContext));
final ArgumentCaptor<PieceDeletionHolder> pieceDeletionHolderCapture = ArgumentCaptor.forClass(PieceDeletionHolder.class);
doReturn(completedFuture(null)).when(pieceDeleteFlowPoLineService).updatePoLine(pieceDeletionHolderCapture.capture(), eq(requestContext));
// When
pieceDeleteFlowManager.deletePiece(piece.getId(), true, requestContext).get();
// Then
PieceDeletionHolder holder = PieceDeletionHolderCapture.getValue();
assertNull(poLine.getLocations().get(0).getLocationId());
assertEquals(holdingId, poLine.getLocations().get(0).getHoldingId());
verify(pieceStorageService).deletePiece(eq(piece.getId()), eq(true), eq(requestContext));
verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(piece, requestContext);
verify(inventoryManager).deleteItem(itemId, true, requestContext);
verify(pieceDeleteFlowPoLineService, times(0)).updatePoLine(pieceDeletionHolderCapture.capture(), eq(requestContext));
verify(basePieceFlowHolderBuilder).updateHolderWithOrderInformation(holder, requestContext);
}
use of org.folio.TestConstants.ID 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.TestConstants.ID 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.TestConstants.ID 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.TestConstants.ID in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testPutOrdersByIdPEMixFormat.
@Test
@Disabled
// TODO must be fixed in scoupe of https://issues.folio.org/browse/MODORDERS-587
void testPutOrdersByIdPEMixFormat() {
logger.info("=== Test Put Order By Id create Pieces with P/E Mix format ===");
CompositePurchaseOrder reqData = getMockAsJson(PE_MIX_PATH).mapTo(CompositePurchaseOrder.class);
reqData.setId(ID_FOR_PRINT_MONOGRAPH_ORDER);
reqData.setReEncumber(null);
// Make sure that mock PO has 1 po line
assertThat(reqData.getCompositePoLines(), hasSize(1));
reqData.setManualPo(false);
CompositePoLine compositePoLine = reqData.getCompositePoLines().get(0);
compositePoLine.setId(PO_LINE_ID_FOR_SUCCESS_CASE);
compositePoLine.getEresource().setCreateInventory(Eresource.CreateInventory.NONE);
compositePoLine.setPhysical(new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM).withMaterialType("4b93736c-8731-46cd-9d6e-f9dce0f63bcd"));
compositePoLine.getCost().setQuantityPhysical(3);
compositePoLine.getCost().setQuantityElectronic(2);
compositePoLine.setOrderFormat(OrderFormat.P_E_MIX);
Transaction encumbrance = getMockAsJson(ENCUMBRANCE_PATH).getJsonArray("transactions").getJsonObject(0).mapTo(Transaction.class);
compositePoLine.getFundDistribution().get(0).setEncumbrance(encumbrance.getId());
compositePoLine.getFundDistribution().get(0).setFundId(encumbrance.getFromFundId());
encumbrance.getEncumbrance().setSourcePoLineId(compositePoLine.getId());
encumbrance.getEncumbrance().setSourcePurchaseOrderId(compositePoLine.getPurchaseOrderId());
compositePoLine.getLocations().stream().filter(location -> ObjectUtils.defaultIfNull(location.getQuantityPhysical(), 0) > 0).forEach(location -> location.setQuantityElectronic(null));
// MODORDERS-243
removeAllEncumbranceLinks(reqData);
reqData.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN);
MockServer.addMockTitles(reqData.getCompositePoLines());
preparePiecesForCompositePo(reqData);
verifyPut(String.format(COMPOSITE_ORDERS_BY_ID_PATH, reqData.getId()), JsonObject.mapFrom(reqData), "", 204);
List<JsonObject> respOrder = MockServer.serverRqRs.get(PURCHASE_ORDER_STORAGE, HttpMethod.PUT);
CompositePurchaseOrder compPo = respOrder.get(0).mapTo(CompositePurchaseOrder.class);
List<JsonObject> respLines = MockServer.serverRqRs.get(PO_LINES_STORAGE, HttpMethod.PUT);
CompositePoLine respLine1 = respLines.stream().filter(line -> line.getString(ID).equals(compositePoLine.getId())).peek(line -> line.remove("reportingCodes")).map(line -> line.mapTo(CompositePoLine.class)).filter(line -> line.getLocations().stream().filter(loc -> Objects.nonNull(loc.getHoldingId())).findFirst().isPresent()).distinct().findAny().get();
compPo.setCompositePoLines(List.of(respLine1));
List<JsonObject> createdPieces = getCreatedPieces();
List<JsonObject> createdItems = getCreatedItems();
assertThat(createdItems, notNullValue());
assertThat(createdPieces, notNullValue());
int piecesSize = createdPieces.size();
logger.debug("------------------- piecesSize, itemSize --------------------\n" + piecesSize + " " + createdItems.size());
// Verify total number of pieces created should be equal to total quantity
assertEquals(calculateTotalQuantity(respLine1), piecesSize);
verifyOpenOrderPiecesCreated(createdItems, compPo.getCompositePoLines(), createdPieces, 0);
verifyEncumbrancesOnPoUpdate(compPo);
assertTrue(getExistingOrderSummaries().size() > 0);
}
Aggregations