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);
}
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);
}
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());
}
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)));
}
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)));
}
Aggregations