Search in sources :

Example 1 with Piece

use of org.folio.rest.jaxrs.model.Piece in project mod-orders by folio-org.

the class OpenCompositeOrderPieceServiceTest method shouldCreatePieceWithLocationAndHoldingReferenceIfMixedLineContainsLocationAndInventoryIsInstanceOrNoneAndNoCreatedPieces.

@ParameterizedTest
@CsvSource(value = { "P/E Mix:Instance:Instance, Holding:2:3", "P/E Mix:None:Instance, Holding:2:3" }, delimiter = ':')
void shouldCreatePieceWithLocationAndHoldingReferenceIfMixedLineContainsLocationAndInventoryIsInstanceOrNoneAndNoCreatedPieces(String lineType, String elecCreateInventory, String physCreateInventory, int elecQty1, int physQty2) {
    // given
    String lineId = UUID.randomUUID().toString();
    String locationId1 = UUID.randomUUID().toString();
    String holdingId = UUID.randomUUID().toString();
    String titleId = UUID.randomUUID().toString();
    Location location1 = new Location().withLocationId(locationId1).withQuantityElectronic(elecQty1).withQuantity(elecQty1);
    Location location2 = new Location().withHoldingId(holdingId).withQuantityPhysical(physQty2).withQuantity(physQty2);
    Cost cost = new Cost().withQuantityElectronic(elecQty1 + physQty2);
    Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.fromValue(elecCreateInventory));
    Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.fromValue(physCreateInventory));
    CompositePoLine line = new CompositePoLine().withId(lineId).withCost(cost).withLocations(List.of(location1, location2)).withIsPackage(false).withEresource(eresource).withPhysical(physical).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 -> locationId1.equals(piece.getLocationId())).collect(toList());
    assertEquals(elecQty1, piecesLoc1.size());
    piecesLoc1.forEach(piece -> {
        assertNull(piece.getHoldingId());
        assertNull(piece.getItemId());
        assertEquals(lineId, piece.getPoLineId());
        assertEquals(titleId, piece.getTitleId());
        assertEquals(Piece.Format.ELECTRONIC, piece.getFormat());
    });
    List<Piece> piecesLoc2 = createdPieces.stream().filter(piece -> holdingId.equals(piece.getHoldingId())).collect(toList());
    assertEquals(physQty2, piecesLoc2.size());
    piecesLoc2.forEach(piece -> {
        assertNull(piece.getLocationId());
        assertNull(piece.getItemId());
        assertEquals(lineId, piece.getPoLineId());
        assertEquals(titleId, piece.getTitleId());
        assertEquals(Piece.Format.PHYSICAL, 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) 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) OpenCompositeOrderHolderBuilder(org.folio.service.orders.flows.update.open.OpenCompositeOrderHolderBuilder) TILES_PATH(org.folio.TestConstants.TILES_PATH) OpenCompositeOrderPieceService(org.folio.service.orders.flows.update.open.OpenCompositeOrderPieceService) 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) ORDER_PATH(org.folio.service.orders.flows.unopen.UnOpenCompositeOrderManagerTest.ORDER_PATH) 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) Physical(org.folio.rest.jaxrs.model.Physical) 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 2 with Piece

use of org.folio.rest.jaxrs.model.Piece 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) 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) OpenCompositeOrderHolderBuilder(org.folio.service.orders.flows.update.open.OpenCompositeOrderHolderBuilder) TILES_PATH(org.folio.TestConstants.TILES_PATH) OpenCompositeOrderPieceService(org.folio.service.orders.flows.update.open.OpenCompositeOrderPieceService) 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) ORDER_PATH(org.folio.service.orders.flows.unopen.UnOpenCompositeOrderManagerTest.ORDER_PATH) 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 3 with Piece

use of org.folio.rest.jaxrs.model.Piece in project mod-orders by folio-org.

the class OpenCompositeOrderPieceServiceTest method shouldCreatePieceWithLocationAndHoldingReferenceIfMixedLineContainsLocationAndInventoryIsInstanceOrNoneAndExistPiecesWithItems.

@ParameterizedTest
@CsvSource(value = { "P/E Mix:Instance:Instance, Holding, Item:2:3", "P/E Mix:None:Instance, Holding, Item:2:3" }, delimiter = ':')
void shouldCreatePieceWithLocationAndHoldingReferenceIfMixedLineContainsLocationAndInventoryIsInstanceOrNoneAndExistPiecesWithItems(String lineType, String elecCreateInventory, String physCreateInventory, int elecQty1, int physQty2) {
    // given
    String lineId = UUID.randomUUID().toString();
    String locationId = UUID.randomUUID().toString();
    String holdingId = UUID.randomUUID().toString();
    String titleId = UUID.randomUUID().toString();
    List<Piece> expectedPiecesWithItem = new ArrayList<>();
    Location elecLocation = new Location().withQuantityElectronic(elecQty1).withQuantity(elecQty1);
    if (Eresource.CreateInventory.INSTANCE_HOLDING_ITEM == Eresource.CreateInventory.fromValue(elecCreateInventory)) {
        elecLocation.withHoldingId(holdingId);
        expectedPiecesWithItem.addAll(createElecPiecesWithHoldingId(lineId, titleId, true, elecLocation));
    } else {
        elecLocation.withLocationId(locationId);
    }
    Location physLocation = new Location().withQuantityPhysical(physQty2).withQuantity(physQty2);
    if (Physical.CreateInventory.INSTANCE_HOLDING_ITEM == Physical.CreateInventory.fromValue(physCreateInventory)) {
        physLocation.withHoldingId(holdingId);
        expectedPiecesWithItem.addAll(createPhysPiecesWithHoldingId(lineId, titleId, true, physLocation));
    } else {
        physLocation.withLocationId(locationId);
    }
    Cost cost = new Cost().withQuantityElectronic(elecQty1 + physQty2);
    Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.fromValue(elecCreateInventory));
    Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.fromValue(physCreateInventory));
    CompositePoLine line = new CompositePoLine().withId(lineId).withCost(cost).withLocations(List.of(elecLocation, physLocation)).withIsPackage(false).withEresource(eresource).withPhysical(physical).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, expectedPiecesWithItem, false, requestContext).join();
    // Then
    List<Piece> piecesLocElec = createdPieces.stream().filter(piece -> Piece.Format.ELECTRONIC.equals(piece.getFormat())).collect(toList());
    assertEquals(elecQty1, piecesLocElec.size());
    piecesLocElec.forEach(piece -> {
        assertEquals(lineId, piece.getPoLineId());
        assertEquals(titleId, piece.getTitleId());
        if (Eresource.CreateInventory.INSTANCE_HOLDING_ITEM == Eresource.CreateInventory.fromValue(elecCreateInventory)) {
            assertEquals(holdingId, piece.getHoldingId());
            assertNotNull(piece.getItemId());
        } else {
            assertEquals(locationId, piece.getLocationId());
            assertNull(piece.getItemId());
        }
    });
    List<Piece> piecesLocPhys = createdPieces.stream().filter(piece -> Piece.Format.PHYSICAL.equals(piece.getFormat())).collect(toList());
    assertEquals(physQty2, piecesLocPhys.size());
    piecesLocPhys.forEach(piece -> {
        assertEquals(lineId, piece.getPoLineId());
        assertEquals(titleId, piece.getTitleId());
        if (Physical.CreateInventory.INSTANCE_HOLDING_ITEM == Physical.CreateInventory.fromValue(physCreateInventory)) {
            assertEquals(holdingId, piece.getHoldingId());
            assertNotNull(piece.getItemId());
        } else {
            assertEquals(locationId, piece.getLocationId());
            assertNull(piece.getItemId());
        }
    });
}
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) 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) OpenCompositeOrderHolderBuilder(org.folio.service.orders.flows.update.open.OpenCompositeOrderHolderBuilder) TILES_PATH(org.folio.TestConstants.TILES_PATH) OpenCompositeOrderPieceService(org.folio.service.orders.flows.update.open.OpenCompositeOrderPieceService) 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) ORDER_PATH(org.folio.service.orders.flows.unopen.UnOpenCompositeOrderManagerTest.ORDER_PATH) 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) ArrayList(java.util.ArrayList) 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) Physical(org.folio.rest.jaxrs.model.Physical) 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 4 with Piece

use of org.folio.rest.jaxrs.model.Piece in project mod-orders by folio-org.

the class OpenCompositeOrderPieceServiceTest method testShouldUpdateInventoryPositiveCaseIfLineIsPackageAndPieceContainsHoldingId.

@Test
void testShouldUpdateInventoryPositiveCaseIfLineIsPackageAndPieceContainsHoldingId() throws ExecutionException, InterruptedException {
    // given
    CompositePoLine line = getMockAsJson(COMPOSITE_LINES_PATH, LINE_ID).mapTo(CompositePoLine.class);
    String holdingId = UUID.randomUUID().toString();
    String itemId = UUID.randomUUID().toString();
    line.getLocations().get(0).withLocationId(null).withHoldingId(holdingId);
    line.setIsPackage(true);
    Title title = getMockAsJson(TILES_PATH, "title").mapTo(Title.class);
    Piece piece = createPieceWithHoldingId(line, title);
    doReturn(completedFuture(title)).when(titlesService).getTitleById(piece.getTitleId(), requestContext);
    doReturn(completedFuture(null)).when(titlesService).saveTitle(title, requestContext);
    doReturn(completedFuture(title)).when(inventoryManager).openOrderHandlePackageLineInstance(title, false, requestContext);
    doReturn(completedFuture(itemId)).when(inventoryManager).openOrderCreateItemRecord(line, holdingId, requestContext);
    // When
    openCompositeOrderPieceService.openOrderUpdateInventory(line, piece, false, requestContext).get();
    // Then
    assertEquals(holdingId, piece.getHoldingId());
    assertEquals(title.getId(), piece.getTitleId());
}
Also used : Piece(org.folio.rest.jaxrs.model.Piece) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Title(org.folio.rest.jaxrs.model.Title) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with Piece

use of org.folio.rest.jaxrs.model.Piece in project mod-orders by folio-org.

the class PurchaseOrderLinesApiTest method testShouldReleaseEncumbrancesAfterCancelledPoLine.

@Test
void testShouldReleaseEncumbrancesAfterCancelledPoLine() {
    logger.info("=== Test release encumbrances after cancelled PoLine  ===");
    CompositePoLine lineFromStorage = getMockAsJson(COMP_PO_LINES_MOCK_DATA_PATH, "740809a1-84ca-45d7-a7a8-accc21efd5bd").mapTo(CompositePoLine.class);
    CompositePoLine reqData = getMockAsJson(COMP_PO_LINES_MOCK_DATA_PATH, "740809a1-84ca-45d7-a7a8-accc21efd5bd").mapTo(CompositePoLine.class);
    reqData.setReceiptStatus(ReceiptStatus.CANCELLED);
    reqData.setPaymentStatus(PaymentStatus.CANCELLED);
    Fund fund = new Fund().withId("7fbd5d84-62d1-44c6-9c45-6cb173998bbd").withName("Fund").withExternalAccountNo("externalNo").withLedgerId("133a7916-f05e-4df4-8f7f-09eb2a7076d1");
    addMockEntry(PIECES_STORAGE, new Piece().withPoLineId(reqData.getId()).withLocationId(reqData.getLocations().get(0).getLocationId()));
    addMockEntry(PO_LINES_STORAGE, lineFromStorage);
    addMockEntry(FUNDS, fund);
    verifyPut(String.format(LINE_BY_ID_PATH, reqData.getId()), JsonObject.mapFrom(reqData).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID), "", 204);
}
Also used : Fund(org.folio.rest.acq.model.finance.Fund) Piece(org.folio.rest.jaxrs.model.Piece) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

Piece (org.folio.rest.jaxrs.model.Piece)157 Test (org.junit.jupiter.api.Test)120 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)116 Location (org.folio.rest.jaxrs.model.Location)91 Cost (org.folio.rest.jaxrs.model.Cost)66 ArrayList (java.util.ArrayList)62 Eresource (org.folio.rest.jaxrs.model.Eresource)59 JsonObject (io.vertx.core.json.JsonObject)55 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)55 PoLine (org.folio.rest.jaxrs.model.PoLine)52 Physical (org.folio.rest.jaxrs.model.Physical)49 PurchaseOrder (org.folio.rest.jaxrs.model.PurchaseOrder)49 Title (org.folio.rest.jaxrs.model.Title)41 List (java.util.List)40 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)39 RequestContext (org.folio.rest.core.models.RequestContext)37 CompletableFuture (java.util.concurrent.CompletableFuture)34 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)33 Map (java.util.Map)32 Context (io.vertx.core.Context)30