Search in sources :

Example 1 with Cost

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

the class CompositePoLineValidationUtilTest method shouldReturnErrorIfLocationAndHoldingReferenceArePresentAtTheSameTimeInTheLocation.

@Test
@DisplayName("Should return error if location and holding reference are not present in the location")
void shouldReturnErrorIfLocationAndHoldingReferenceArePresentAtTheSameTimeInTheLocation() {
    Location location1 = new Location().withHoldingId(UUID.randomUUID().toString()).withLocationId(UUID.randomUUID().toString()).withQuantity(1).withQuantityPhysical(1);
    Location location2 = new Location().withHoldingId(UUID.randomUUID().toString()).withLocationId(UUID.randomUUID().toString()).withQuantity(1).withQuantityPhysical(1);
    Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM);
    Cost cost = new Cost().withQuantityPhysical(2);
    CompositePoLine compositePoLine = new CompositePoLine().withPhysical(physical).withCost(cost).withLocations(List.of(location1, location2));
    List<Error> errors = CompositePoLineValidationUtil.validateLocations(compositePoLine);
    assertEquals(2, errors.size());
    errors.forEach(error -> {
        assertEquals(ErrorCodes.MAY_BE_LINK_TO_EITHER_HOLDING_OR_LOCATION_ERROR.getCode(), error.getCode());
    });
}
Also used : Physical(org.folio.rest.jaxrs.model.Physical) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Error(org.folio.rest.jaxrs.model.Error) Cost(org.folio.rest.jaxrs.model.Cost) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with Cost

use of org.folio.rest.jaxrs.model.Cost 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 3 with Cost

use of org.folio.rest.jaxrs.model.Cost 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 4 with Cost

use of org.folio.rest.jaxrs.model.Cost 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 5 with Cost

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

the class OrderRolloverServiceTest method shouldUpdateOrderLinesCostAndEncumbranceLinksAndPolCurrencyVsSystemCurrencyTheSame.

@Test
@DisplayName("Should update order lines cost And Encumbrance Links where Pol Currency equals systemCurrency")
void shouldUpdateOrderLinesCostAndEncumbranceLinksAndPolCurrencyVsSystemCurrencyTheSame() {
    String fromFiscalYearId = UUID.randomUUID().toString();
    String ledgerId = UUID.randomUUID().toString();
    String toFiscalYearId = UUID.randomUUID().toString();
    String fundId1 = UUID.randomUUID().toString();
    String fundId2 = UUID.randomUUID().toString();
    String fundId3 = UUID.randomUUID().toString();
    String orderId1 = UUID.randomUUID().toString();
    String orderId2 = UUID.randomUUID().toString();
    String orderId3 = UUID.randomUUID().toString();
    String poLineId1 = UUID.randomUUID().toString();
    String poLineId2 = UUID.randomUUID().toString();
    String poLineId3 = UUID.randomUUID().toString();
    String prevEncumbrId1 = UUID.randomUUID().toString();
    String prevEncumbrId2 = UUID.randomUUID().toString();
    String prevEncumbrId3 = UUID.randomUUID().toString();
    String currEncumbrId1 = UUID.randomUUID().toString();
    String currEncumbrId2 = UUID.randomUUID().toString();
    String currEncumbrId3 = UUID.randomUUID().toString();
    String expClassId2 = UUID.randomUUID().toString();
    String expClassId3 = UUID.randomUUID().toString();
    EncumbranceRollover ongoingEncumbranceBasedOnExpended = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONGOING).withBasedOn(EncumbranceRollover.BasedOn.EXPENDED);
    EncumbranceRollover oneTimeEncumbrance = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONE_TIME).withBasedOn(EncumbranceRollover.BasedOn.REMAINING);
    EncumbranceRollover ongoingEncumbranceBasedOnInitialAmount = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONGOING).withBasedOn(EncumbranceRollover.BasedOn.INITIAL_AMOUNT);
    LedgerFiscalYearRollover ledgerFiscalYearRollover = new LedgerFiscalYearRollover().withId(UUID.randomUUID().toString()).withFromFiscalYearId(fromFiscalYearId).withLedgerId(ledgerId).withToFiscalYearId(toFiscalYearId).withEncumbrancesRollover(List.of(ongoingEncumbranceBasedOnExpended, oneTimeEncumbrance, ongoingEncumbranceBasedOnInitialAmount));
    List<Fund> funds = List.of(new Fund().withId(fundId1).withLedgerId(ledgerId), new Fund().withId(fundId2).withLedgerId(ledgerId), new Fund().withId(fundId3).withLedgerId(ledgerId));
    PurchaseOrder purchaseOrder1 = new PurchaseOrder().withId(orderId1).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
    PurchaseOrder purchaseOrder2 = new PurchaseOrder().withId(orderId2).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
    PurchaseOrder purchaseOrder3 = new PurchaseOrder().withId(orderId3).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
    List<PurchaseOrder> orders = List.of(purchaseOrder1, purchaseOrder2, purchaseOrder3);
    PurchaseOrderCollection purchaseOrderCollection = new PurchaseOrderCollection().withPurchaseOrders(orders).withTotalRecords(3);
    FundDistribution fundDistributionOneTime = new FundDistribution().withFundId(fundId1).withValue(100d).withEncumbrance(prevEncumbrId1);
    FundDistribution fundDistributionOngoing2 = new FundDistribution().withFundId(fundId2).withValue(100d).withEncumbrance(prevEncumbrId2).withExpenseClassId(expClassId2);
    FundDistribution fundDistributionOngoing3 = new FundDistribution().withFundId(fundId3).withValue(100d).withEncumbrance(prevEncumbrId3).withExpenseClassId(expClassId3);
    Cost costOneTime = new Cost().withListUnitPrice(100d).withQuantityPhysical(1).withCurrency("USD").withPoLineEstimatedPrice(100d);
    PoLine poLineOneTime = new PoLine().withId(poLineId1).withPurchaseOrderId(orderId1).withCost(costOneTime).withFundDistribution(List.of(fundDistributionOneTime));
    Cost costOngoing2 = new Cost().withListUnitPrice(100d).withQuantityPhysical(1).withCurrency("USD").withPoLineEstimatedPrice(100d);
    PoLine poLineOngoing2 = new PoLine().withId(poLineId2).withPurchaseOrderId(orderId2).withCost(costOngoing2).withFundDistribution(List.of(fundDistributionOngoing2));
    Cost costOngoing3 = new Cost().withListUnitPrice(100d).withQuantityPhysical(1).withCurrency("USD").withPoLineEstimatedPrice(100d);
    PoLine poLineOngoing3 = new PoLine().withId(poLineId3).withPurchaseOrderId(orderId3).withCost(costOngoing3).withFundDistribution(List.of(fundDistributionOngoing3));
    List<PoLine> poLines = List.of(poLineOneTime, poLineOngoing2, poLineOngoing3);
    doReturn(completedFuture(funds)).when(fundService).getFundsByLedgerId(ledgerId, requestContext);
    doReturn(completedFuture(purchaseOrderCollection)).when(purchaseOrderStorageService).getPurchaseOrders(anyString(), anyInt(), anyInt(), any());
    doReturn(completedFuture(poLines)).when(purchaseOrderLineService).getOrderLines(anyString(), anyInt(), anyInt(), any());
    doReturn(completedFuture(null)).when(purchaseOrderLineService).saveOrderLines(eq(poLines), any());
    Encumbrance encumbranceOneTime = new Encumbrance().withSourcePurchaseOrderId(orderId1).withSourcePoLineId(poLineId1).withOrderType(Encumbrance.OrderType.ONE_TIME).withInitialAmountEncumbered(60d);
    Transaction transactionOneTime = new Transaction().withId(currEncumbrId1).withFromFundId(fundId1).withEncumbrance(encumbranceOneTime);
    Encumbrance encumbranceOngoing2 = new Encumbrance().withSourcePurchaseOrderId(orderId2).withSourcePoLineId(poLineId2).withOrderType(Encumbrance.OrderType.ONGOING).withInitialAmountEncumbered(90d);
    Transaction transactionOngoing2 = new Transaction().withId(currEncumbrId2).withFromFundId(fundId2).withEncumbrance(encumbranceOngoing2).withExpenseClassId(expClassId2);
    Encumbrance encumbranceOngoing3 = new Encumbrance().withSourcePurchaseOrderId(orderId3).withSourcePoLineId(poLineId3).withOrderType(Encumbrance.OrderType.ONGOING).withInitialAmountEncumbered(95d);
    Transaction transactionOngoing3 = new Transaction().withId(currEncumbrId3).withFromFundId(fundId3).withEncumbrance(encumbranceOngoing3).withExpenseClassId(expClassId3);
    List<Transaction> encumbrances = List.of(transactionOneTime, transactionOngoing2, transactionOngoing3);
    TransactionCollection encumbranceCollection = new TransactionCollection().withTransactions(encumbrances).withTotalRecords(3);
    doReturn(completedFuture(encumbranceCollection)).when(transactionService).getTransactions(anyString(), anyInt(), anyInt(), any());
    double exchangeEurToUsdRate = 1.0d;
    doReturn(completedFuture(systemCurrency)).when(configurationEntriesService).getSystemCurrency(requestContext);
    String polCurrency = systemCurrency;
    ConversionQuery actQuery = ConversionQueryBuilder.of().setBaseCurrency(polCurrency).setTermCurrency(systemCurrency).set(RATE_KEY, exchangeEurToUsdRate).build();
    ExchangeRateProvider exchangeRateProvider = Mockito.mock(ManualExchangeRateProvider.class);
    ManualCurrencyConversion manualCurrencyConversion = new ManualCurrencyConversion(actQuery, exchangeRateProvider, ConversionContext.of());
    ExchangeRate exchangeRate = mock(ExchangeRate.class);
    doReturn(exchangeRateProvider).when(exchangeRateProviderResolver).resolve(any(ConversionQuery.class), eq(requestContext));
    doReturn(manualCurrencyConversion).when(exchangeRateProvider).getCurrencyConversion(any(ConversionQuery.class));
    doReturn(exchangeRate).when(exchangeRateProvider).getExchangeRate(any(ConversionQuery.class));
    when(exchangeRate.getContext()).thenReturn(ConversionContext.of());
    when(exchangeRate.getCurrency()).thenReturn(Monetary.getCurrency(systemCurrency));
    when(exchangeRate.getBaseCurrency()).thenReturn(Monetary.getCurrency(polCurrency));
    when(exchangeRate.getFactor()).thenReturn(new DefaultNumberValue(exchangeEurToUsdRate));
    CompletableFuture<Void> future = orderRolloverService.rollover(ledgerFiscalYearRollover, requestContext);
    future.join();
    assertFalse(future.isCompletedExceptionally());
    assertThat(fundDistributionOneTime.getEncumbrance(), equalTo(currEncumbrId1));
    assertThat(fundDistributionOngoing2.getEncumbrance(), equalTo(currEncumbrId2));
    assertThat(fundDistributionOngoing3.getEncumbrance(), equalTo(currEncumbrId3));
    assertThat(costOneTime.getPoLineEstimatedPrice(), equalTo(60d));
    assertThat(costOngoing2.getPoLineEstimatedPrice(), equalTo(90d));
    assertThat(costOngoing3.getPoLineEstimatedPrice(), equalTo(95d));
    assertThat(costOneTime.getFyroAdjustmentAmount(), equalTo(-40d));
    assertThat(costOngoing2.getFyroAdjustmentAmount(), equalTo(-10d));
    assertThat(costOngoing3.getFyroAdjustmentAmount(), equalTo(-5d));
}
Also used : EncumbranceRollover(org.folio.rest.jaxrs.model.EncumbranceRollover) DefaultNumberValue(org.javamoney.moneta.spi.DefaultNumberValue) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) ExchangeRate(javax.money.convert.ExchangeRate) PurchaseOrderCollection(org.folio.rest.jaxrs.model.PurchaseOrderCollection) ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) ManualExchangeRateProvider(org.folio.service.exchange.ManualExchangeRateProvider) Fund(org.folio.rest.acq.model.finance.Fund) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) Cost(org.folio.rest.jaxrs.model.Cost) ManualCurrencyConversion(org.folio.service.exchange.ManualCurrencyConversion) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) ConversionQuery(javax.money.convert.ConversionQuery) Transaction(org.folio.rest.acq.model.finance.Transaction) PoLine(org.folio.rest.jaxrs.model.PoLine) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

Cost (org.folio.rest.jaxrs.model.Cost)94 Test (org.junit.jupiter.api.Test)79 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)70 Location (org.folio.rest.jaxrs.model.Location)66 Piece (org.folio.rest.jaxrs.model.Piece)63 PoLine (org.folio.rest.jaxrs.model.PoLine)47 PurchaseOrder (org.folio.rest.jaxrs.model.PurchaseOrder)46 Eresource (org.folio.rest.jaxrs.model.Eresource)44 Physical (org.folio.rest.jaxrs.model.Physical)41 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 ArrayList (java.util.ArrayList)33 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)32 JsonObject (io.vertx.core.json.JsonObject)30 DisplayName (org.junit.jupiter.api.DisplayName)27 List (java.util.List)22 Map (java.util.Map)19 CompletableFuture (java.util.concurrent.CompletableFuture)19 RequestContext (org.folio.rest.core.models.RequestContext)19 BeforeEach (org.junit.jupiter.api.BeforeEach)18 Context (io.vertx.core.Context)17