Search in sources :

Example 26 with Title

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);
}
Also used : PieceUpdateHolder(org.folio.models.pieces.PieceUpdateHolder) Piece(org.folio.rest.jaxrs.model.Piece) PoLine(org.folio.rest.jaxrs.model.PoLine) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) Title(org.folio.rest.jaxrs.model.Title) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) Cost(org.folio.rest.jaxrs.model.Cost) Eresource(org.folio.rest.jaxrs.model.Eresource) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test)

Example 27 with Title

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));
}
Also used : Title(org.folio.rest.jaxrs.model.Title)

Example 28 with 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();
}
Also used : Title(org.folio.rest.jaxrs.model.Title) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test)

Example 29 with Title

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);
}
Also used : Title(org.folio.rest.jaxrs.model.Title) Test(org.junit.jupiter.api.Test)

Example 30 with Title

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));
}
Also used : Title(org.folio.rest.jaxrs.model.Title) JsonObject(io.vertx.core.json.JsonObject) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Test(org.junit.jupiter.api.Test)

Aggregations

Title (org.folio.rest.jaxrs.model.Title)42 Test (org.junit.jupiter.api.Test)28 Piece (org.folio.rest.jaxrs.model.Piece)23 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)19 Location (org.folio.rest.jaxrs.model.Location)19 JsonObject (io.vertx.core.json.JsonObject)17 ArrayList (java.util.ArrayList)10 List (java.util.List)9 CompletableFuture (java.util.concurrent.CompletableFuture)8 Cost (org.folio.rest.jaxrs.model.Cost)8 PoLine (org.folio.rest.jaxrs.model.PoLine)8 PurchaseOrder (org.folio.rest.jaxrs.model.PurchaseOrder)8 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)7 Collectors (java.util.stream.Collectors)7 Eresource (org.folio.rest.jaxrs.model.Eresource)7 Context (io.vertx.core.Context)6 Map (java.util.Map)6 PieceUpdateHolder (org.folio.models.pieces.PieceUpdateHolder)6 Optional (java.util.Optional)5 LogManager (org.apache.logging.log4j.LogManager)5