Search in sources :

Example 6 with PieceStorageService

use of org.folio.service.pieces.PieceStorageService in project mod-orders by folio-org.

the class OpenCompositeOrderPieceServiceTest method shouldCreatePieceWithLocationReferenceIfElectronicLineContainsLocationAndInventoryIsInstanceOrNoneAndNoCreatedPieces.

@ParameterizedTest
@CsvSource(value = { "Electronic Resource:Instance:2:3:Electronic", "Electronic Resource:None:2:3:Electronic" }, delimiter = ':')
void shouldCreatePieceWithLocationReferenceIfElectronicLineContainsLocationAndInventoryIsInstanceOrNoneAndNoCreatedPieces(String lineType, String createInventory, int qty1, int qty2, String pieceFormat) {
    // 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(qty1).withQuantity(qty1);
    Location location2 = new Location().withLocationId(locationId2).withQuantityElectronic(qty2).withQuantity(qty2);
    Cost cost = new Cost().withQuantityElectronic(qty1 + qty2);
    Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.fromValue(createInventory));
    CompositePoLine line = new CompositePoLine().withId(lineId).withCost(cost).withLocations(List.of(location1, location2)).withIsPackage(false).withEresource(eresource).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(qty1, piecesLoc1.size());
    piecesLoc1.forEach(piece -> {
        assertNull(piece.getHoldingId());
        assertNull(piece.getItemId());
        assertEquals(lineId, piece.getPoLineId());
        assertEquals(titleId, piece.getTitleId());
        assertEquals(Piece.Format.fromValue(pieceFormat), piece.getFormat());
    });
    List<Piece> piecesLoc2 = createdPieces.stream().filter(piece -> piece.getLocationId().equals(locationId2)).collect(toList());
    assertEquals(qty2, piecesLoc2.size());
    piecesLoc2.forEach(piece -> {
        assertNull(piece.getHoldingId());
        assertNull(piece.getItemId());
        assertEquals(lineId, piece.getPoLineId());
        assertEquals(titleId, piece.getTitleId());
        assertEquals(Piece.Format.fromValue(pieceFormat), piece.getFormat());
    });
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Cost(org.folio.rest.jaxrs.model.Cost) TestConfig.getVertx(org.folio.TestConfig.getVertx) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) PurchaseOrderStorageService(org.folio.service.orders.PurchaseOrderStorageService) TimeoutException(java.util.concurrent.TimeoutException) Autowired(org.springframework.beans.factory.annotation.Autowired) Context(io.vertx.core.Context) ApiTestSuite(org.folio.ApiTestSuite) AfterAll(org.junit.jupiter.api.AfterAll) MockitoAnnotations(org.mockito.MockitoAnnotations) ProtectionService(org.folio.service.ProtectionService) BeforeAll(org.junit.jupiter.api.BeforeAll) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) Spy(org.mockito.Spy) JsonObject(io.vertx.core.json.JsonObject) ORDER_PATH(org.folio.service.orders.flows.update.unopen.UnOpenCompositeOrderManagerTest.ORDER_PATH) Mockito.doReturn(org.mockito.Mockito.doReturn) PieceStorageService(org.folio.service.pieces.PieceStorageService) BASE_MOCK_DATA_PATH(org.folio.rest.impl.MockServer.BASE_MOCK_DATA_PATH) TILES_PATH(org.folio.TestConstants.TILES_PATH) TestConfig.clearServiceInteractions(org.folio.TestConfig.clearServiceInteractions) Location(org.folio.rest.jaxrs.model.Location) UUID(java.util.UUID) TestConfig.isVerticleNotDeployed(org.folio.TestConfig.isVerticleNotDeployed) Test(org.junit.jupiter.api.Test) List(java.util.List) Eresource(org.folio.rest.jaxrs.model.Eresource) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TestConfig.getFirstContextFromVertx(org.folio.TestConfig.getFirstContextFromVertx) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) CsvSource(org.junit.jupiter.params.provider.CsvSource) PieceChangeReceiptStatusPublisher(org.folio.service.pieces.PieceChangeReceiptStatusPublisher) Mock(org.mockito.Mock) ProtectedOperationType(org.folio.orders.utils.ProtectedOperationType) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) CompletableFuture(java.util.concurrent.CompletableFuture) TestConfig.clearVertxContext(org.folio.TestConfig.clearVertxContext) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) Title(org.folio.rest.jaxrs.model.Title) Answer(org.mockito.stubbing.Answer) TitlesService(org.folio.service.titles.TitlesService) ArgumentCaptor(org.mockito.ArgumentCaptor) PIECE_PATH(org.folio.TestConstants.PIECE_PATH) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) RequestContext(org.folio.rest.core.models.RequestContext) TestConfig.autowireDependencies(org.folio.TestConfig.autowireDependencies) InventoryManager(org.folio.service.inventory.InventoryManager) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Physical(org.folio.rest.jaxrs.model.Physical) MessageAddress(org.folio.orders.events.handlers.MessageAddress) Piece(org.folio.rest.jaxrs.model.Piece) TestConfig.initSpringContext(org.folio.TestConfig.initSpringContext) Mockito.times(org.mockito.Mockito.times) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) Collectors.toList(java.util.stream.Collectors.toList) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Bean(org.springframework.context.annotation.Bean) Collections(java.util.Collections) TestUtils.getMockAsJson(org.folio.TestUtils.getMockAsJson) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Cost(org.folio.rest.jaxrs.model.Cost) Eresource(org.folio.rest.jaxrs.model.Eresource) CompletableFuture(java.util.concurrent.CompletableFuture) Piece(org.folio.rest.jaxrs.model.Piece) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) ProtectedOperationType(org.folio.orders.utils.ProtectedOperationType) Location(org.folio.rest.jaxrs.model.Location) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with PieceStorageService

use of org.folio.service.pieces.PieceStorageService in project mod-orders by folio-org.

the class PieceDeleteFlowManagerTest method shouldUpdateLineQuantityIfPoLineIsNotPackageAndManualPieceCreateFalseAndInventoryInstanceVsHoldingAndDeleteHoldingAndPiece.

@Test
void shouldUpdateLineQuantityIfPoLineIsNotPackageAndManualPieceCreateFalseAndInventoryInstanceVsHoldingAndDeleteHoldingAndPiece() throws ExecutionException, InterruptedException {
    String orderId = UUID.randomUUID().toString();
    String holdingId = UUID.randomUUID().toString();
    String lineId = UUID.randomUUID().toString();
    String itemId = UUID.randomUUID().toString();
    String locationId = UUID.randomUUID().toString();
    JsonObject holding = new JsonObject();
    holding.put(ID, holdingId);
    holding.put(HOLDING_PERMANENT_LOCATION_ID, locationId);
    JsonObject item = new JsonObject().put(ID, itemId);
    item.put(ITEM_STATUS, new JsonObject().put(ITEM_STATUS_NAME, ItemStatus.ON_ORDER.value()));
    Piece piece = new Piece().withId(UUID.randomUUID().toString()).withPoLineId(lineId).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).withCheckinItems(false).withOrderFormat(PoLine.OrderFormat.ELECTRONIC_RESOURCE).withEresource(new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE_HOLDING)).withPurchaseOrderId(orderId).withId(lineId).withLocations(List.of(loc)).withCost(cost);
    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(holding)).when(inventoryManager).getHoldingById(holdingId, requestContext);
    doReturn(completedFuture(null)).when(inventoryManager).getItemsByHoldingId(holdingId, requestContext);
    doReturn(completedFuture(null)).when(inventoryManager).deleteHoldingById(piece.getHoldingId(), true, requestContext);
    doReturn(completedFuture(null)).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();
    verify(pieceStorageService).deletePiece(eq(piece.getId()), eq(true), eq(requestContext));
    verify(inventoryManager, times(0)).deleteItem(itemId, true, requestContext);
    verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(piece, requestContext);
    verify(pieceStorageService, times(1)).deletePiece(eq(piece.getId()), eq(true), eq(requestContext));
    verify(pieceDeleteFlowPoLineService).updatePoLine(pieceDeletionHolderCapture.capture(), eq(requestContext));
    verify(basePieceFlowHolderBuilder).updateHolderWithOrderInformation(holder, requestContext);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Cost(org.folio.rest.jaxrs.model.Cost) TestConfig.getVertx(org.folio.TestConfig.getVertx) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) TimeoutException(java.util.concurrent.TimeoutException) Autowired(org.springframework.beans.factory.annotation.Autowired) PoLine(org.folio.rest.jaxrs.model.PoLine) Context(io.vertx.core.Context) ApiTestSuite(org.folio.ApiTestSuite) AfterAll(org.junit.jupiter.api.AfterAll) MockitoAnnotations(org.mockito.MockitoAnnotations) ITEM_STATUS(org.folio.service.inventory.InventoryManager.ITEM_STATUS) ProtectionService(org.folio.service.ProtectionService) BeforeAll(org.junit.jupiter.api.BeforeAll) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) Spy(org.mockito.Spy) JsonObject(io.vertx.core.json.JsonObject) Mockito.doReturn(org.mockito.Mockito.doReturn) PieceStorageService(org.folio.service.pieces.PieceStorageService) ID(org.folio.TestConstants.ID) ItemStatus(org.folio.models.ItemStatus) TestConfig.clearServiceInteractions(org.folio.TestConfig.clearServiceInteractions) Location(org.folio.rest.jaxrs.model.Location) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) BasePieceFlowHolderBuilder(org.folio.service.pieces.flows.BasePieceFlowHolderBuilder) UUID(java.util.UUID) TestConfig.isVerticleNotDeployed(org.folio.TestConfig.isVerticleNotDeployed) Test(org.junit.jupiter.api.Test) List(java.util.List) Eresource(org.folio.rest.jaxrs.model.Eresource) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TestConfig.getFirstContextFromVertx(org.folio.TestConfig.getFirstContextFromVertx) Mock(org.mockito.Mock) ProtectedOperationType(org.folio.orders.utils.ProtectedOperationType) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) CompletableFuture(java.util.concurrent.CompletableFuture) TestConfig.clearVertxContext(org.folio.TestConfig.clearVertxContext) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) RequestContext(org.folio.rest.core.models.RequestContext) PieceUpdateInventoryService(org.folio.service.pieces.PieceUpdateInventoryService) HOLDING_PERMANENT_LOCATION_ID(org.folio.service.inventory.InventoryManager.HOLDING_PERMANENT_LOCATION_ID) TestConfig.autowireDependencies(org.folio.TestConfig.autowireDependencies) InventoryManager(org.folio.service.inventory.InventoryManager) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PieceDeletionHolder(org.folio.models.pieces.PieceDeletionHolder) Piece(org.folio.rest.jaxrs.model.Piece) TestConfig.initSpringContext(org.folio.TestConfig.initSpringContext) Mockito.times(org.mockito.Mockito.times) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) Bean(org.springframework.context.annotation.Bean) ITEM_STATUS_NAME(org.folio.service.inventory.InventoryManager.ITEM_STATUS_NAME) PieceDeletionHolder(org.folio.models.pieces.PieceDeletionHolder) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) Cost(org.folio.rest.jaxrs.model.Cost) Eresource(org.folio.rest.jaxrs.model.Eresource) CompletableFuture(java.util.concurrent.CompletableFuture) Piece(org.folio.rest.jaxrs.model.Piece) PoLine(org.folio.rest.jaxrs.model.PoLine) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) List(java.util.List) ArrayList(java.util.ArrayList) ProtectedOperationType(org.folio.orders.utils.ProtectedOperationType) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test)

Example 8 with PieceStorageService

use of org.folio.service.pieces.PieceStorageService in project mod-orders by folio-org.

the class PieceDeleteFlowManagerTest method shouldUpdateLineQuantityIfPoLineIsNotPackageAndManualPieceCreateFalseAndDeleteOnlyPiece.

@Test
void shouldUpdateLineQuantityIfPoLineIsNotPackageAndManualPieceCreateFalseAndDeleteOnlyPiece() throws ExecutionException, InterruptedException {
    String orderId = UUID.randomUUID().toString();
    String lineId = UUID.randomUUID().toString();
    String titleId = UUID.randomUUID().toString();
    String locationId = UUID.randomUUID().toString();
    String holdingId = UUID.randomUUID().toString();
    String itemId = UUID.randomUUID().toString();
    Piece piece = new Piece().withId(UUID.randomUUID().toString()).withPoLineId(lineId).withTitleId(titleId).withLocationId(locationId).withFormat(Piece.Format.ELECTRONIC);
    Location loc = new Location().withLocationId(locationId).withQuantityElectronic(1).withQuantity(1);
    Cost cost = new Cost().withQuantityElectronic(1).withListUnitPriceElectronic(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
    PoLine poLine = new PoLine().withIsPackage(false).withCheckinItems(false).withOrderFormat(PoLine.OrderFormat.ELECTRONIC_RESOURCE).withEresource(new Eresource().withCreateInventory(Eresource.CreateInventory.NONE)).withPurchaseOrderId(orderId).withId(lineId).withLocations(List.of(loc)).withCost(cost);
    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(requestContext));
    doReturn(completedFuture(null)).when(inventoryManager).getNumberOfRequestsByItemId(eq(piece.getItemId()), 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(null)).when(inventoryManager).deleteItem(itemId, true, requestContext);
    doReturn(completedFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(piece, 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();
    verify(pieceStorageService).deletePiece(eq(piece.getId()), eq(true), eq(requestContext));
    verify(inventoryManager, times(0)).deleteItem(itemId, true, requestContext);
    verify(inventoryManager, times(0)).deleteHoldingById(holdingId, true, requestContext);
    verify(pieceStorageService, times(1)).deletePiece(eq(piece.getId()), eq(true), eq(requestContext));
    verify(pieceDeleteFlowPoLineService).updatePoLine(pieceDeletionHolderCapture.capture(), eq(requestContext));
    verify(basePieceFlowHolderBuilder).updateHolderWithOrderInformation(holder, requestContext);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Cost(org.folio.rest.jaxrs.model.Cost) TestConfig.getVertx(org.folio.TestConfig.getVertx) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) TimeoutException(java.util.concurrent.TimeoutException) Autowired(org.springframework.beans.factory.annotation.Autowired) PoLine(org.folio.rest.jaxrs.model.PoLine) Context(io.vertx.core.Context) ApiTestSuite(org.folio.ApiTestSuite) AfterAll(org.junit.jupiter.api.AfterAll) MockitoAnnotations(org.mockito.MockitoAnnotations) ITEM_STATUS(org.folio.service.inventory.InventoryManager.ITEM_STATUS) ProtectionService(org.folio.service.ProtectionService) BeforeAll(org.junit.jupiter.api.BeforeAll) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) Spy(org.mockito.Spy) JsonObject(io.vertx.core.json.JsonObject) Mockito.doReturn(org.mockito.Mockito.doReturn) PieceStorageService(org.folio.service.pieces.PieceStorageService) ID(org.folio.TestConstants.ID) ItemStatus(org.folio.models.ItemStatus) TestConfig.clearServiceInteractions(org.folio.TestConfig.clearServiceInteractions) Location(org.folio.rest.jaxrs.model.Location) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) BasePieceFlowHolderBuilder(org.folio.service.pieces.flows.BasePieceFlowHolderBuilder) UUID(java.util.UUID) TestConfig.isVerticleNotDeployed(org.folio.TestConfig.isVerticleNotDeployed) Test(org.junit.jupiter.api.Test) List(java.util.List) Eresource(org.folio.rest.jaxrs.model.Eresource) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TestConfig.getFirstContextFromVertx(org.folio.TestConfig.getFirstContextFromVertx) Mock(org.mockito.Mock) ProtectedOperationType(org.folio.orders.utils.ProtectedOperationType) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) CompletableFuture(java.util.concurrent.CompletableFuture) TestConfig.clearVertxContext(org.folio.TestConfig.clearVertxContext) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) RequestContext(org.folio.rest.core.models.RequestContext) PieceUpdateInventoryService(org.folio.service.pieces.PieceUpdateInventoryService) HOLDING_PERMANENT_LOCATION_ID(org.folio.service.inventory.InventoryManager.HOLDING_PERMANENT_LOCATION_ID) TestConfig.autowireDependencies(org.folio.TestConfig.autowireDependencies) InventoryManager(org.folio.service.inventory.InventoryManager) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PieceDeletionHolder(org.folio.models.pieces.PieceDeletionHolder) Piece(org.folio.rest.jaxrs.model.Piece) TestConfig.initSpringContext(org.folio.TestConfig.initSpringContext) Mockito.times(org.mockito.Mockito.times) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) Bean(org.springframework.context.annotation.Bean) ITEM_STATUS_NAME(org.folio.service.inventory.InventoryManager.ITEM_STATUS_NAME) PieceDeletionHolder(org.folio.models.pieces.PieceDeletionHolder) Cost(org.folio.rest.jaxrs.model.Cost) Eresource(org.folio.rest.jaxrs.model.Eresource) CompletableFuture(java.util.concurrent.CompletableFuture) Piece(org.folio.rest.jaxrs.model.Piece) PoLine(org.folio.rest.jaxrs.model.PoLine) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) List(java.util.List) ArrayList(java.util.ArrayList) ProtectedOperationType(org.folio.orders.utils.ProtectedOperationType) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test)

Example 9 with PieceStorageService

use of org.folio.service.pieces.PieceStorageService in project mod-orders by folio-org.

the class PieceDeleteFlowManagerTest method shouldNotUpdateLineQuantityIfPoLineIsPackageAndShouldDeleteHoldingAndItemAndPiece.

@Test
void shouldNotUpdateLineQuantityIfPoLineIsPackageAndShouldDeleteHoldingAndItemAndPiece() 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);
    Cost cost = new Cost().withQuantityElectronic(1).withListUnitPriceElectronic(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
    Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(1).withQuantity(1);
    PoLine poLine = new PoLine().withIsPackage(true).withPurchaseOrderId(orderId).withId(lineId).withLocations(List.of(loc)).withCost(cost);
    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);
    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));
    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);
    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);
    // Then
    assertNull(poLine.getLocations().get(0).getLocationId());
    assertEquals(holdingId, poLine.getLocations().get(0).getHoldingId());
    verify(pieceDeleteFlowPoLineService, times(0)).updatePoLine(pieceDeletionHolderCapture.capture(), eq(requestContext));
    verify(basePieceFlowHolderBuilder).updateHolderWithOrderInformation(holder, requestContext);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Cost(org.folio.rest.jaxrs.model.Cost) TestConfig.getVertx(org.folio.TestConfig.getVertx) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) TimeoutException(java.util.concurrent.TimeoutException) Autowired(org.springframework.beans.factory.annotation.Autowired) PoLine(org.folio.rest.jaxrs.model.PoLine) Context(io.vertx.core.Context) ApiTestSuite(org.folio.ApiTestSuite) AfterAll(org.junit.jupiter.api.AfterAll) MockitoAnnotations(org.mockito.MockitoAnnotations) ITEM_STATUS(org.folio.service.inventory.InventoryManager.ITEM_STATUS) ProtectionService(org.folio.service.ProtectionService) BeforeAll(org.junit.jupiter.api.BeforeAll) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) Spy(org.mockito.Spy) JsonObject(io.vertx.core.json.JsonObject) Mockito.doReturn(org.mockito.Mockito.doReturn) PieceStorageService(org.folio.service.pieces.PieceStorageService) ID(org.folio.TestConstants.ID) ItemStatus(org.folio.models.ItemStatus) TestConfig.clearServiceInteractions(org.folio.TestConfig.clearServiceInteractions) Location(org.folio.rest.jaxrs.model.Location) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) BasePieceFlowHolderBuilder(org.folio.service.pieces.flows.BasePieceFlowHolderBuilder) UUID(java.util.UUID) TestConfig.isVerticleNotDeployed(org.folio.TestConfig.isVerticleNotDeployed) Test(org.junit.jupiter.api.Test) List(java.util.List) Eresource(org.folio.rest.jaxrs.model.Eresource) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TestConfig.getFirstContextFromVertx(org.folio.TestConfig.getFirstContextFromVertx) Mock(org.mockito.Mock) ProtectedOperationType(org.folio.orders.utils.ProtectedOperationType) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) CompletableFuture(java.util.concurrent.CompletableFuture) TestConfig.clearVertxContext(org.folio.TestConfig.clearVertxContext) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) RequestContext(org.folio.rest.core.models.RequestContext) PieceUpdateInventoryService(org.folio.service.pieces.PieceUpdateInventoryService) HOLDING_PERMANENT_LOCATION_ID(org.folio.service.inventory.InventoryManager.HOLDING_PERMANENT_LOCATION_ID) TestConfig.autowireDependencies(org.folio.TestConfig.autowireDependencies) InventoryManager(org.folio.service.inventory.InventoryManager) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PieceDeletionHolder(org.folio.models.pieces.PieceDeletionHolder) Piece(org.folio.rest.jaxrs.model.Piece) TestConfig.initSpringContext(org.folio.TestConfig.initSpringContext) Mockito.times(org.mockito.Mockito.times) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) Bean(org.springframework.context.annotation.Bean) ITEM_STATUS_NAME(org.folio.service.inventory.InventoryManager.ITEM_STATUS_NAME) PieceDeletionHolder(org.folio.models.pieces.PieceDeletionHolder) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) Cost(org.folio.rest.jaxrs.model.Cost) CompletableFuture(java.util.concurrent.CompletableFuture) Piece(org.folio.rest.jaxrs.model.Piece) PoLine(org.folio.rest.jaxrs.model.PoLine) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) List(java.util.List) ArrayList(java.util.ArrayList) ProtectedOperationType(org.folio.orders.utils.ProtectedOperationType) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test)

Example 10 with PieceStorageService

use of org.folio.service.pieces.PieceStorageService 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);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Cost(org.folio.rest.jaxrs.model.Cost) TestConfig.getVertx(org.folio.TestConfig.getVertx) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) TimeoutException(java.util.concurrent.TimeoutException) Autowired(org.springframework.beans.factory.annotation.Autowired) PoLine(org.folio.rest.jaxrs.model.PoLine) Context(io.vertx.core.Context) ApiTestSuite(org.folio.ApiTestSuite) AfterAll(org.junit.jupiter.api.AfterAll) MockitoAnnotations(org.mockito.MockitoAnnotations) ITEM_STATUS(org.folio.service.inventory.InventoryManager.ITEM_STATUS) ProtectionService(org.folio.service.ProtectionService) BeforeAll(org.junit.jupiter.api.BeforeAll) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) Spy(org.mockito.Spy) JsonObject(io.vertx.core.json.JsonObject) Mockito.doReturn(org.mockito.Mockito.doReturn) PieceStorageService(org.folio.service.pieces.PieceStorageService) ID(org.folio.TestConstants.ID) ItemStatus(org.folio.models.ItemStatus) TestConfig.clearServiceInteractions(org.folio.TestConfig.clearServiceInteractions) Location(org.folio.rest.jaxrs.model.Location) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) BasePieceFlowHolderBuilder(org.folio.service.pieces.flows.BasePieceFlowHolderBuilder) UUID(java.util.UUID) TestConfig.isVerticleNotDeployed(org.folio.TestConfig.isVerticleNotDeployed) Test(org.junit.jupiter.api.Test) List(java.util.List) Eresource(org.folio.rest.jaxrs.model.Eresource) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TestConfig.getFirstContextFromVertx(org.folio.TestConfig.getFirstContextFromVertx) Mock(org.mockito.Mock) ProtectedOperationType(org.folio.orders.utils.ProtectedOperationType) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) CompletableFuture(java.util.concurrent.CompletableFuture) TestConfig.clearVertxContext(org.folio.TestConfig.clearVertxContext) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) RequestContext(org.folio.rest.core.models.RequestContext) PieceUpdateInventoryService(org.folio.service.pieces.PieceUpdateInventoryService) HOLDING_PERMANENT_LOCATION_ID(org.folio.service.inventory.InventoryManager.HOLDING_PERMANENT_LOCATION_ID) TestConfig.autowireDependencies(org.folio.TestConfig.autowireDependencies) InventoryManager(org.folio.service.inventory.InventoryManager) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PieceDeletionHolder(org.folio.models.pieces.PieceDeletionHolder) Piece(org.folio.rest.jaxrs.model.Piece) TestConfig.initSpringContext(org.folio.TestConfig.initSpringContext) Mockito.times(org.mockito.Mockito.times) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) Bean(org.springframework.context.annotation.Bean) ITEM_STATUS_NAME(org.folio.service.inventory.InventoryManager.ITEM_STATUS_NAME) PieceDeletionHolder(org.folio.models.pieces.PieceDeletionHolder) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) Cost(org.folio.rest.jaxrs.model.Cost) CompletableFuture(java.util.concurrent.CompletableFuture) Piece(org.folio.rest.jaxrs.model.Piece) PoLine(org.folio.rest.jaxrs.model.PoLine) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) List(java.util.List) ArrayList(java.util.ArrayList) ProtectedOperationType(org.folio.orders.utils.ProtectedOperationType) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test)

Aggregations

Context (io.vertx.core.Context)18 JsonObject (io.vertx.core.json.JsonObject)18 List (java.util.List)18 Map (java.util.Map)18 UUID (java.util.UUID)18 CompletableFuture (java.util.concurrent.CompletableFuture)18 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)18 ExecutionException (java.util.concurrent.ExecutionException)18 TimeoutException (java.util.concurrent.TimeoutException)18 ApiTestSuite (org.folio.ApiTestSuite)18 TestConfig.autowireDependencies (org.folio.TestConfig.autowireDependencies)18 TestConfig.clearServiceInteractions (org.folio.TestConfig.clearServiceInteractions)18 TestConfig.clearVertxContext (org.folio.TestConfig.clearVertxContext)18 TestConfig.getFirstContextFromVertx (org.folio.TestConfig.getFirstContextFromVertx)18 TestConfig.getVertx (org.folio.TestConfig.getVertx)18 TestConfig.initSpringContext (org.folio.TestConfig.initSpringContext)18 TestConfig.isVerticleNotDeployed (org.folio.TestConfig.isVerticleNotDeployed)18 RequestContext (org.folio.rest.core.models.RequestContext)18 Eresource (org.folio.rest.jaxrs.model.Eresource)18 Location (org.folio.rest.jaxrs.model.Location)18