Search in sources :

Example 1 with HttpException

use of org.folio.rest.core.exceptions.HttpException 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)

Example 2 with HttpException

use of org.folio.rest.core.exceptions.HttpException in project mod-orders by folio-org.

the class DefaultPieceFlowsValidatorTest method createPieceIsForbiddenIfPieceAndLIneFormatIsNotCompatible.

@Test
void createPieceIsForbiddenIfPieceAndLIneFormatIsNotCompatible() {
    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);
    CompositePoLine originPoLine = new CompositePoLine().withIsPackage(true).withPurchaseOrderId(orderId).withOrderFormat(CompositePoLine.OrderFormat.PHYSICAL_RESOURCE).withId(lineId).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.PIECE_FORMAT_IS_NOT_VALID_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) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test)

Example 3 with HttpException

use of org.folio.rest.core.exceptions.HttpException in project mod-orders by folio-org.

the class OrderInvoiceRelationServiceTest method testShouldThrowExceptionWhenOrderLineLinkedToInvoice.

@Test
void testShouldThrowExceptionWhenOrderLineLinkedToInvoice() {
    // GIVEN
    OrderInvoiceRelationshipCollection oirCollection = new OrderInvoiceRelationshipCollection().withOrderInvoiceRelationships(Collections.singletonList(new OrderInvoiceRelationship())).withTotalRecords(1);
    doReturn(completedFuture(oirCollection)).when(restClient).get(any(), any(), any());
    PoLine poLineLinkedToInvoice = new PoLine().withId(poLineIdConnectedToInvoice);
    InvoiceLine invoiceLine1 = new InvoiceLine().withInvoiceId(invoiceId).withPoLineId(poLineIdConnectedToInvoice);
    InvoiceLine invoiceLine2 = new InvoiceLine().withInvoiceId(invoiceId).withPoLineId(UUID.randomUUID().toString());
    List<InvoiceLine> invoiceLines = Arrays.asList(invoiceLine1, invoiceLine2);
    InvoiceLineCollection invoiceLineCollection = new InvoiceLineCollection();
    invoiceLineCollection.setInvoiceLines(invoiceLines);
    // WHEN
    when(invoiceLineService.getInvoiceLinesByOrderLineId(eq(poLineIdConnectedToInvoice), any())).thenReturn(completedFuture(invoiceLines));
    CompletableFuture<Void> future = orderInvoiceRelationService.checkOrderPOLineLinkedToInvoiceLine(poLineLinkedToInvoice, requestContext);
    // THEN
    CompletionException exception = assertThrows(CompletionException.class, future::join);
    HttpException httpException = (HttpException) exception.getCause();
    assertEquals(ErrorCodes.ORDER_RELATES_TO_INVOICE.getDescription(), httpException.getMessage());
}
Also used : OrderInvoiceRelationshipCollection(org.folio.rest.acq.model.OrderInvoiceRelationshipCollection) InvoiceLine(org.folio.rest.acq.model.invoice.InvoiceLine) PoLine(org.folio.rest.jaxrs.model.PoLine) CompletionException(java.util.concurrent.CompletionException) OrderInvoiceRelationship(org.folio.rest.acq.model.OrderInvoiceRelationship) HttpException(org.folio.rest.core.exceptions.HttpException) InvoiceLineCollection(org.folio.rest.acq.model.invoice.InvoiceLineCollection) Test(org.junit.jupiter.api.Test)

Example 4 with HttpException

use of org.folio.rest.core.exceptions.HttpException in project mod-orders by folio-org.

the class OrderReEncumberServiceTest method shouldThrowHttpExceptionWithFundsNotFoundCodeWhenAtLeastOneFundIsMissing.

@Test
void shouldThrowHttpExceptionWithFundsNotFoundCodeWhenAtLeastOneFundIsMissing() {
    String orderId = UUID.randomUUID().toString();
    String fundId1 = UUID.randomUUID().toString();
    String fundId2 = UUID.randomUUID().toString();
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withFundDistribution(new FundDistribution().withFundId(fundId1)).withLedgerId(UUID.randomUUID().toString());
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withFundDistribution(new FundDistribution().withFundId(fundId2));
    List<ReEncumbranceHolder> holders = List.of(holder1, holder2);
    when(purchaseOrderStorageService.getCompositeOrderById(anyString(), any())).thenReturn(completedFuture(new CompositePurchaseOrder()));
    when(spyReEncumbranceHoldersBuilder.buildReEncumbranceHoldersWithOrdersData(any())).thenReturn(holders);
    when(spyReEncumbranceHoldersBuilder.withFundsData(any(), any())).thenReturn(completedFuture(holders));
    CompletionException completionException = assertThrows(CompletionException.class, () -> orderReEncumberService.reEncumber(orderId, requestContext).join());
    assertNotNull(completionException.getCause());
    assertThat(completionException.getCause(), instanceOf(HttpException.class));
    HttpException e = (HttpException) completionException.getCause();
    assertEquals(FUNDS_NOT_FOUND.getCode(), e.getError().getCode());
    assertEquals(e.getError().getParameters(), Collections.singletonList(new Parameter().withKey("fund").withValue(fundId2)));
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) CompletionException(java.util.concurrent.CompletionException) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) Parameter(org.folio.rest.jaxrs.model.Parameter) HttpException(org.folio.rest.core.exceptions.HttpException) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Test(org.junit.jupiter.api.Test)

Example 5 with HttpException

use of org.folio.rest.core.exceptions.HttpException in project mod-orders by folio-org.

the class OrderReEncumberServiceTest method shouldThrowHttpExceptionWithRolloverNotCompletedCodeWhenAtLeastOneRolloverHasNoProgress.

@Test
void shouldThrowHttpExceptionWithRolloverNotCompletedCodeWhenAtLeastOneRolloverHasNoProgress() {
    String orderId = UUID.randomUUID().toString();
    String fundId1 = UUID.randomUUID().toString();
    String fundId2 = UUID.randomUUID().toString();
    String fundId3 = UUID.randomUUID().toString();
    String ledgerId1 = UUID.randomUUID().toString();
    String ledgerId2 = UUID.randomUUID().toString();
    String ledgerId3 = UUID.randomUUID().toString();
    String rolloverId1 = UUID.randomUUID().toString();
    String rolloverId2 = UUID.randomUUID().toString();
    String rolloverId3 = UUID.randomUUID().toString();
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withLedgerId(ledgerId1).withRollover(new LedgerFiscalYearRollover().withId(rolloverId1).withLedgerId(ledgerId1)).withFundDistribution(new FundDistribution().withFundId(fundId1));
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withLedgerId(ledgerId2).withRollover(new LedgerFiscalYearRollover().withId(rolloverId2).withLedgerId(ledgerId2)).withFundDistribution(new FundDistribution().withFundId(fundId2));
    ReEncumbranceHolder holder3 = new ReEncumbranceHolder().withLedgerId(ledgerId3).withRollover(new LedgerFiscalYearRollover().withId(rolloverId3).withLedgerId(ledgerId3)).withFundDistribution(new FundDistribution().withFundId(fundId3));
    List<ReEncumbranceHolder> holders = List.of(holder1, holder2, holder3);
    when(purchaseOrderStorageService.getCompositeOrderById(anyString(), any())).thenReturn(completedFuture(new CompositePurchaseOrder()));
    when(spyReEncumbranceHoldersBuilder.buildReEncumbranceHoldersWithOrdersData(any())).thenReturn(holders);
    when(spyReEncumbranceHoldersBuilder.withFundsData(any(), any())).thenReturn(completedFuture(holders));
    when(spyReEncumbranceHoldersBuilder.withLedgersData(any(), any())).thenReturn(completedFuture(holders));
    when(spyReEncumbranceHoldersBuilder.withCurrentFiscalYearData(any(), any())).thenReturn(completedFuture(holders));
    when(spyReEncumbranceHoldersBuilder.withRollovers(any(), any())).thenReturn(completedFuture(holders));
    when(spyReEncumbranceHoldersBuilder.withEncumbranceRollover(any())).thenReturn(holders);
    when(rolloverRetrieveService.getRolloversProgress(eq(rolloverId3), any())).thenReturn(completedFuture(Collections.singletonList(error)));
    when(rolloverRetrieveService.getRolloversProgress(AdditionalMatchers.not(eq(rolloverId3)), any())).thenReturn(completedFuture(Collections.emptyList()));
    CompletionException completionException = assertThrows(CompletionException.class, () -> orderReEncumberService.reEncumber(orderId, requestContext).join());
    assertNotNull(completionException.getCause());
    assertThat(completionException.getCause(), instanceOf(HttpException.class));
    HttpException e = (HttpException) completionException.getCause();
    assertEquals(ROLLOVER_NOT_COMPLETED.getCode(), e.getError().getCode());
    assertEquals(e.getError().getParameters(), Collections.singletonList(new Parameter().withKey("ledgerIds").withValue(ledgerId1 + ", " + ledgerId2)));
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) CompletionException(java.util.concurrent.CompletionException) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) Parameter(org.folio.rest.jaxrs.model.Parameter) HttpException(org.folio.rest.core.exceptions.HttpException) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Test(org.junit.jupiter.api.Test)

Aggregations

HttpException (org.folio.rest.core.exceptions.HttpException)54 CompletionException (java.util.concurrent.CompletionException)26 Test (org.junit.jupiter.api.Test)26 Error (org.folio.rest.jaxrs.model.Error)18 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)16 Parameter (org.folio.rest.jaxrs.model.Parameter)15 ArrayList (java.util.ArrayList)14 CompletableFuture (java.util.concurrent.CompletableFuture)14 RequestContext (org.folio.rest.core.models.RequestContext)14 List (java.util.List)13 RequestEntry (org.folio.rest.core.models.RequestEntry)13 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)13 JsonObject (io.vertx.core.json.JsonObject)12 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)12 Map (java.util.Map)11 CollectionUtils (org.apache.commons.collections4.CollectionUtils)10 LogManager (org.apache.logging.log4j.LogManager)10 Logger (org.apache.logging.log4j.Logger)10 RestClient (org.folio.rest.core.RestClient)10 Location (org.folio.rest.jaxrs.model.Location)10