Search in sources :

Example 6 with Physical

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

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

the class OrderLineUpdateInstanceHandlerTest method shouldThrowNotImplementedExceptionForPhysicalOrderFormat.

@Test
public void shouldThrowNotImplementedExceptionForPhysicalOrderFormat() {
    String orderLineId = UUID.randomUUID().toString();
    PoLine poLine = new PoLine().withId(orderLineId).withOrderFormat(PoLine.OrderFormat.PHYSICAL_RESOURCE).withPhysical(new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING));
    PatchOrderLineRequest patchOrderLineRequest = new PatchOrderLineRequest();
    patchOrderLineRequest.withOperation(PatchOrderLineRequest.Operation.REPLACE_INSTANCE_REF);
    OrderLineUpdateInstanceHolder orderLineUpdateInstanceHolder = new OrderLineUpdateInstanceHolder().withStoragePoLine(poLine).withPathOrderLineRequest(patchOrderLineRequest);
    assertThrows(NotImplementedException.class, () -> orderLineUpdateInstanceHandler.handle(orderLineUpdateInstanceHolder, requestContext));
}
Also used : Physical(org.folio.rest.jaxrs.model.Physical) PatchOrderLineRequest(org.folio.rest.jaxrs.model.PatchOrderLineRequest) PoLine(org.folio.rest.jaxrs.model.PoLine) Test(org.junit.jupiter.api.Test)

Example 8 with Physical

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

the class OrderLineUpdateInstanceHandlerTest method shouldThrowNotImplementedExceptionForOtherOrderFormat.

@Test
public void shouldThrowNotImplementedExceptionForOtherOrderFormat() {
    String orderLineId = UUID.randomUUID().toString();
    PoLine poLine = new PoLine().withId(orderLineId).withOrderFormat(PoLine.OrderFormat.OTHER).withPhysical(new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING));
    PatchOrderLineRequest patchOrderLineRequest = new PatchOrderLineRequest();
    patchOrderLineRequest.withOperation(PatchOrderLineRequest.Operation.REPLACE_INSTANCE_REF);
    OrderLineUpdateInstanceHolder orderLineUpdateInstanceHolder = new OrderLineUpdateInstanceHolder().withStoragePoLine(poLine).withPathOrderLineRequest(patchOrderLineRequest);
    assertThrows(NotImplementedException.class, () -> orderLineUpdateInstanceHandler.handle(orderLineUpdateInstanceHolder, requestContext));
}
Also used : Physical(org.folio.rest.jaxrs.model.Physical) PatchOrderLineRequest(org.folio.rest.jaxrs.model.PatchOrderLineRequest) PoLine(org.folio.rest.jaxrs.model.PoLine) Test(org.junit.jupiter.api.Test)

Example 9 with Physical

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

the class OrderLineUpdateInstanceHandlerTest method shouldThrowNotImplementedExceptionForMIXOrderFormat.

@Test
public void shouldThrowNotImplementedExceptionForMIXOrderFormat() {
    String orderLineId = UUID.randomUUID().toString();
    PoLine poLine = new PoLine().withId(orderLineId).withOrderFormat(PoLine.OrderFormat.P_E_MIX).withPhysical(new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING)).withEresource(new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE));
    PatchOrderLineRequest patchOrderLineRequest = new PatchOrderLineRequest();
    patchOrderLineRequest.withOperation(PatchOrderLineRequest.Operation.REPLACE_INSTANCE_REF);
    OrderLineUpdateInstanceHolder orderLineUpdateInstanceHolder = new OrderLineUpdateInstanceHolder().withStoragePoLine(poLine).withPathOrderLineRequest(patchOrderLineRequest);
    assertThrows(NotImplementedException.class, () -> orderLineUpdateInstanceHandler.handle(orderLineUpdateInstanceHolder, requestContext));
}
Also used : Physical(org.folio.rest.jaxrs.model.Physical) PatchOrderLineRequest(org.folio.rest.jaxrs.model.PatchOrderLineRequest) PoLine(org.folio.rest.jaxrs.model.PoLine) Eresource(org.folio.rest.jaxrs.model.Eresource) Test(org.junit.jupiter.api.Test)

Example 10 with Physical

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

the class PieceCreateFlowPoLineServiceTest method shouldIncreaseQuantityTo3ForCostAndLocationIfInitiallyWas2AndLocationIdInPieceAndMixedPOLWithLocationId.

@Test
@DisplayName("Add 1 electronic piece with location id to mixed pol with 1 location with location id and electronic and physical qty")
void shouldIncreaseQuantityTo3ForCostAndLocationIfInitiallyWas2AndLocationIdInPieceAndMixedPOLWithLocationId() throws ExecutionException, InterruptedException {
    String orderId = UUID.randomUUID().toString();
    String locationId = UUID.randomUUID().toString();
    String lineId = UUID.randomUUID().toString();
    Piece pieceToCreate = new Piece().withPoLineId(lineId).withLocationId(locationId).withFormat(Piece.Format.ELECTRONIC);
    Location loc = new Location().withLocationId(locationId).withQuantityElectronic(1).withQuantityPhysical(1).withQuantity(2);
    Cost cost = new Cost().withQuantityElectronic(1).withQuantityPhysical(1).withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
    PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
    Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE);
    Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE);
    PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.P_E_MIX).withId(lineId).withEresource(eresource).withPhysical(physical).withLocations(List.of(loc)).withCost(cost);
    PieceCreationHolder incomingUpdateHolder = new PieceCreationHolder().withPieceToCreate(pieceToCreate).withCreateItem(true);
    incomingUpdateHolder.withOrderInformation(purchaseOrder, originPoLine);
    doReturn(completedFuture(null)).when(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
    doReturn(completedFuture(null)).when(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
    // When
    pieceCreateFlowPoLineService.updatePoLine(incomingUpdateHolder, requestContext).get();
    // Then
    CompositePoLine poLineToSave = incomingUpdateHolder.getPoLineToSave();
    assertEquals(1, poLineToSave.getLocations().size());
    assertEquals(3, poLineToSave.getLocations().get(0).getQuantity());
    assertEquals(1, poLineToSave.getLocations().get(0).getQuantityPhysical());
    assertEquals(2, poLineToSave.getLocations().get(0).getQuantityElectronic());
    assertEquals(1, poLineToSave.getCost().getQuantityPhysical());
    assertEquals(2, poLineToSave.getCost().getQuantityElectronic());
    verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
    verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
Also used : PieceCreationHolder(org.folio.models.pieces.PieceCreationHolder) Physical(org.folio.rest.jaxrs.model.Physical) Piece(org.folio.rest.jaxrs.model.Piece) PoLine(org.folio.rest.jaxrs.model.PoLine) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Cost(org.folio.rest.jaxrs.model.Cost) Eresource(org.folio.rest.jaxrs.model.Eresource) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

Physical (org.folio.rest.jaxrs.model.Physical)54 Test (org.junit.jupiter.api.Test)51 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)43 Cost (org.folio.rest.jaxrs.model.Cost)42 Piece (org.folio.rest.jaxrs.model.Piece)42 Location (org.folio.rest.jaxrs.model.Location)39 PoLine (org.folio.rest.jaxrs.model.PoLine)28 PurchaseOrder (org.folio.rest.jaxrs.model.PurchaseOrder)27 Eresource (org.folio.rest.jaxrs.model.Eresource)25 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)24 ArrayList (java.util.ArrayList)23 JsonObject (io.vertx.core.json.JsonObject)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 Title (org.folio.rest.jaxrs.model.Title)15 DisplayName (org.junit.jupiter.api.DisplayName)15 Context (io.vertx.core.Context)11 Collections (java.util.Collections)11 List (java.util.List)11 Map (java.util.Map)11 UUID (java.util.UUID)11