use of org.folio.rest.jaxrs.model.Title in project mod-orders by folio-org.
the class PieceUpdateFlowInventoryManagerTest method shouldDeleteHoldingWhenElecPieceUpdateForNonPackagePoLineWithCreateInventoryAllAndPieceContainsNewHoldingAndTitleWithInstanceId.
@Test
void shouldDeleteHoldingWhenElecPieceUpdateForNonPackagePoLineWithCreateInventoryAllAndPieceContainsNewHoldingAndTitleWithInstanceId() {
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.ELECTRONIC);
Piece pieceToUpdate = new Piece().withId(pieceId).withTitleId(titleId).withItemId(itemId).withPoLineId(lineId).withHoldingId(holdingId).withFormat(Piece.Format.ELECTRONIC);
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.ELECTRONIC_RESOURCE).withId(lineId).withEresource(new Eresource().withCreateInventory(Eresource.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).createMissingElectronicItems(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.Title in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method createMockTitle.
private void createMockTitle(CompositePoLine line) {
Title title = new Title().withTitle(line.getTitleOrPackage()).withPoLineId(line.getId());
MockServer.addMockEntry(TITLES, JsonObject.mapFrom(title));
}
use of org.folio.rest.jaxrs.model.Title in project mod-orders by folio-org.
the class InventoryManagerTest method testShouldBuildInstanceWithoutTitleFields.
@Test
void testShouldBuildInstanceWithoutTitleFields() {
// given
Title title = spy(getMockAsJson(TILES_PATH, "title").mapTo(Title.class));
title.setContributors(null);
title.setPublishedDate(null);
title.setPublisher(null);
title.setProductIds(null);
JsonObject statuseJSON = new JsonObject("{\"instanceTypes\":\"30fffe0e-e985-4144-b2e2-1e8179bdb41f\"" + ",\"instanceStatuses\":\"daf2681c-25af-4202-a3fa-e58fdf806183\"}");
// When
inventoryManager.buildInstanceRecordJsonObject(title, statuseJSON);
// Then
verify(title).getContributors();
verify(title, times(1)).getPublishedDate();
verify(title, times(1)).getPublisher();
verify(title).getProductIds();
}
use of org.folio.rest.jaxrs.model.Title in project mod-orders by folio-org.
the class InventoryManagerTest method testShouldSkipCreationNewInstanceIfInstanceIdIsProvided.
@Test
void testShouldSkipCreationNewInstanceIfInstanceIdIsProvided() throws ExecutionException, InterruptedException {
// given
Title title = getMockAsJson(TILES_PATH, "title").mapTo(Title.class);
// When
CompletableFuture<Title> result = inventoryManager.openOrderHandlePackageLineInstance(title, false, requestContext);
// Then
Title actTitle = result.get();
assertEquals(title, actTitle);
}
use of org.folio.rest.jaxrs.model.Title in project mod-orders by folio-org.
the class InventoryManagerTest method testShouldCreateInstanceRecordIfProductPresentAndInstancesNotFoundInDB.
@Test
void testShouldCreateInstanceRecordIfProductPresentAndInstancesNotFoundInDB() throws ExecutionException, InterruptedException {
// given
Title title = getMockAsJson(TILES_PATH, "title").mapTo(Title.class);
doReturn(completedFuture(new JsonObject("{\"instances\" : []}"))).when(inventoryManager).searchInstancesByProducts(any(List.class), eq(requestContext));
doReturn(completedFuture(UUID.randomUUID().toString())).when(inventoryManager).createInstanceRecord(any(Title.class), eq(requestContext));
// When
inventoryManager.getOrCreateInstanceRecord(title, requestContext).get();
// Then
verify(inventoryManager, times(1)).createInstanceRecord(any(Title.class), eq(requestContext));
}
Aggregations