Search in sources :

Example 16 with Piece

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

the class ReOpenCompositeOrderManagerTest method shouldCheckPaymentAndReceiptStatusesIfInvoicesAndPiecesHaveSameStatuses.

@ParameterizedTest
@CsvSource(value = { "Open:Expected:Awaiting Receipt:Awaiting Payment", "Approved:Received:Partially Received:Partially Paid", "Paid:Received:Partially Received:Partially Paid" }, delimiter = ':')
void shouldCheckPaymentAndReceiptStatusesIfInvoicesAndPiecesHaveSameStatuses(String invoiceStatus, String pieceStatus, String expReceiptStatus, String expPaymentStatus) throws ExecutionException, InterruptedException {
    CompositePurchaseOrder oldOrder = getMockAsJson(ORDER_PATH).mapTo(CompositePurchaseOrder.class);
    CompositePoLine poLine1 = oldOrder.getCompositePoLines().get(0);
    String poLineId1 = poLine1.getId();
    String encumbrance1Id = poLine1.getFundDistribution().get(0).getEncumbrance();
    CompositePoLine poLine2 = JsonObject.mapFrom(poLine1).mapTo(CompositePoLine.class);
    String poLineId2 = UUID.randomUUID().toString();
    String encumbrance2Id = UUID.randomUUID().toString();
    String oldInstance2 = UUID.randomUUID().toString();
    poLine2.setId(poLineId2);
    poLine2.getFundDistribution().get(0).setEncumbrance(encumbrance2Id);
    poLine2.setInstanceId(oldInstance2);
    oldOrder.setCompositePoLines(List.of(poLine1, poLine2));
    CompositePurchaseOrder newOrder = JsonObject.mapFrom(oldOrder).mapTo(CompositePurchaseOrder.class);
    newOrder.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.CLOSED);
    String invoiceId1 = UUID.randomUUID().toString();
    Invoice invoice1 = new Invoice().withId(invoiceId1).withStatus(Invoice.Status.fromValue(invoiceStatus));
    String invoiceId2 = UUID.randomUUID().toString();
    Invoice invoice2 = new Invoice().withId(invoiceId2).withStatus(Invoice.Status.fromValue(invoiceStatus));
    InvoiceLine invoiceLine1 = new InvoiceLine().withId(UUID.randomUUID().toString()).withInvoiceId(invoice1.getId()).withPoLineId(poLineId1).withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance1Id)));
    InvoiceLine invoiceLine2 = new InvoiceLine().withId(UUID.randomUUID().toString()).withInvoiceId(invoice2.getId()).withPoLineId(poLineId2).withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance2Id)));
    List<InvoiceLine> invoiceLines = List.of(invoiceLine1, invoiceLine2);
    List<Invoice> invoices = List.of(invoice1, invoice2);
    Piece piece1 = new Piece().withFormat(Piece.Format.PHYSICAL).withReceivingStatus(Piece.ReceivingStatus.fromValue(pieceStatus)).withPoLineId(poLineId1).withLocationId(UUID.randomUUID().toString()).withHoldingId(UUID.randomUUID().toString());
    Piece piece2 = new Piece().withFormat(Piece.Format.PHYSICAL).withReceivingStatus(Piece.ReceivingStatus.fromValue(pieceStatus)).withPoLineId(poLineId2).withLocationId(UUID.randomUUID().toString()).withHoldingId(UUID.randomUUID().toString());
    doReturn(closedToOpenEncumbranceStrategy).when(encumbranceWorkflowStrategyFactory).getStrategy(eq(OrderWorkflowType.CLOSED_TO_OPEN));
    doReturn(completedFuture(null)).when(closedToOpenEncumbranceStrategy).processEncumbrances(eq(newOrder), eq(oldOrder), eq(requestContext));
    doReturn(completedFuture(invoiceLines)).when(invoiceLineService).getInvoiceLinesByOrderLineIds(List.of(poLineId1, poLineId2), requestContext);
    doReturn(completedFuture(invoices)).when(invoiceService).getInvoicesByOrderId(oldOrder.getId(), requestContext);
    doReturn(completedFuture(List.of(piece1, piece2))).when(pieceStorageService).getPiecesByLineIdsByChunks(List.of(poLineId1, poLineId2), requestContext);
    reOpenCompositeOrderManager.process(newOrder, oldOrder, requestContext).get();
    assertEquals(CompositePoLine.ReceiptStatus.fromValue(expReceiptStatus), newOrder.getCompositePoLines().get(0).getReceiptStatus());
    assertEquals(CompositePoLine.PaymentStatus.fromValue(expPaymentStatus), newOrder.getCompositePoLines().get(0).getPaymentStatus());
    assertEquals(CompositePoLine.ReceiptStatus.fromValue(expReceiptStatus), newOrder.getCompositePoLines().get(1).getReceiptStatus());
    assertEquals(CompositePoLine.PaymentStatus.fromValue(expPaymentStatus), newOrder.getCompositePoLines().get(1).getPaymentStatus());
}
Also used : Invoice(org.folio.rest.acq.model.invoice.Invoice) InvoiceLine(org.folio.rest.acq.model.invoice.InvoiceLine) Piece(org.folio.rest.jaxrs.model.Piece) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with Piece

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

the class PieceStorageServiceTest method testPiecesShouldBeReturnedByQuery.

@Test
void testPiecesShouldBeReturnedByQuery() {
    String pieceId = UUID.randomUUID().toString();
    List<Piece> pieces = Collections.singletonList(new Piece().withId(pieceId));
    PieceCollection pieceCollection = new PieceCollection().withPieces(pieces).withTotalRecords(1);
    when(restClientMock.get(any(), any(), any())).thenReturn(CompletableFuture.completedFuture(pieceCollection));
    String expectedQuery = String.format("id==%s", pieceId);
    PieceCollection retrievedPieces = pieceStorageService.getPieces(Integer.MAX_VALUE, 0, expectedQuery, requestContext).join();
    verify(restClientMock).get(any(), eq(requestContext), eq(PieceCollection.class));
    assertEquals(pieceCollection, retrievedPieces);
}
Also used : PieceCollection(org.folio.rest.jaxrs.model.PieceCollection) Piece(org.folio.rest.jaxrs.model.Piece) Test(org.junit.jupiter.api.Test)

Example 18 with Piece

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

the class PieceUpdateInventoryServiceTest method shouldDeleteHoldingIfHoldingIdIsProvidedAndFoundInDBAndNoPiecesAndItems.

@Test
void shouldDeleteHoldingIfHoldingIdIsProvidedAndFoundInDBAndNoPiecesAndItems() {
    String holdingId = UUID.randomUUID().toString();
    JsonObject holding = new JsonObject();
    holding.put(ID, holding);
    Piece piece = new Piece().withId(UUID.randomUUID().toString()).withHoldingId(holdingId);
    doReturn(completedFuture(Collections.emptyList())).when(pieceStorageService).getPiecesByHoldingId(holdingId, requestContext);
    doReturn(completedFuture(holding)).when(inventoryManager).getHoldingById(holdingId, true, requestContext);
    doReturn(completedFuture(new ArrayList<>())).when(inventoryManager).getItemsByHoldingId(holdingId, requestContext);
    pieceUpdateInventoryService.deleteHoldingConnectedToPiece(piece, requestContext);
    verify(inventoryManager, times(1)).deleteHoldingById(holdingId, true, requestContext);
}
Also used : Piece(org.folio.rest.jaxrs.model.Piece) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test)

Example 19 with Piece

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

the class DefaultPieceFlowsValidatorTest method createPieceAllowableIfCreateInventoryInTheLineAllowThatButCreateItemFlagIsFalse.

@Test
void createPieceAllowableIfCreateInventoryInTheLineAllowThatButCreateItemFlagIsFalse() {
    String orderId = UUID.randomUUID().toString();
    String locationId = UUID.randomUUID().toString();
    String lineId = UUID.randomUUID().toString();
    Piece piece = new Piece().withPoLineId(lineId).withLocationId(locationId).withFormat(Piece.Format.ELECTRONIC);
    Location loc = new Location().withLocationId(locationId).withQuantityElectronic(1).withQuantity(1);
    Cost cost = new Cost().withQuantityElectronic(1);
    Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE_HOLDING_ITEM);
    CompositePoLine originPoLine = new CompositePoLine().withIsPackage(true).withPurchaseOrderId(orderId).withOrderFormat(CompositePoLine.OrderFormat.ELECTRONIC_RESOURCE).withId(lineId).withEresource(eresource).withLocations(List.of(loc)).withCost(cost);
    defaultPieceFlowsValidator.isPieceRequestValid(piece, originPoLine, true);
}
Also used : Piece(org.folio.rest.jaxrs.model.Piece) 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)

Example 20 with Piece

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

the class DefaultPieceFlowsValidatorTest method createPieceIsForbiddenIfCreateInventoryInTheLineDonNotAllowThat.

@Test
void createPieceIsForbiddenIfCreateInventoryInTheLineDonNotAllowThat() {
    String orderId = UUID.randomUUID().toString();
    String locationId = UUID.randomUUID().toString();
    String lineId = UUID.randomUUID().toString();
    Piece piece = new Piece().withPoLineId(lineId).withLocationId(locationId).withFormat(Piece.Format.ELECTRONIC);
    Location loc = new Location().withLocationId(locationId).withQuantityElectronic(1).withQuantity(1);
    Cost cost = new Cost().withQuantityElectronic(1);
    Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE_HOLDING);
    CompositePoLine originPoLine = new CompositePoLine().withIsPackage(true).withPurchaseOrderId(orderId).withOrderFormat(CompositePoLine.OrderFormat.ELECTRONIC_RESOURCE).withId(lineId).withEresource(eresource).withLocations(List.of(loc)).withCost(cost);
    HttpException exception = Assertions.assertThrows(HttpException.class, () -> {
        defaultPieceFlowsValidator.isPieceRequestValid(piece, originPoLine, true);
    });
    boolean isErrorPresent = exception.getErrors().getErrors().stream().anyMatch(error -> error.getCode().equals(ErrorCodes.CREATE_ITEM_FOR_PIECE_IS_NOT_ALLOWED_ERROR.getCode()));
    assertEquals(true, isErrorPresent);
}
Also used : Piece(org.folio.rest.jaxrs.model.Piece) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) HttpException(org.folio.rest.core.exceptions.HttpException) 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)

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