Search in sources :

Example 16 with HttpException

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

the class SuffixServiceTest method testUpdateSuffixWithIdMismatchFails.

@Test
void testUpdateSuffixWithIdMismatchFails() {
    Suffix suffix = new Suffix().withId(UUID.randomUUID().toString());
    CompletionException expectedException = assertThrows(CompletionException.class, () -> {
        CompletableFuture<Void> result = suffixService.updateSuffix(UUID.randomUUID().toString(), suffix, requestContext);
        assertTrue(result.isCompletedExceptionally());
        result.join();
    });
    HttpException httpException = (HttpException) expectedException.getCause();
    assertEquals(422, httpException.getCode());
    assertEquals(MISMATCH_BETWEEN_ID_IN_PATH_AND_BODY.toError(), httpException.getError());
}
Also used : Suffix(org.folio.rest.jaxrs.model.Suffix) CompletionException(java.util.concurrent.CompletionException) HttpException(org.folio.rest.core.exceptions.HttpException) Test(org.junit.jupiter.api.Test)

Example 17 with HttpException

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

the class FiscalYearServiceTest method testShouldThrowHttpException.

@Test
void testShouldThrowHttpException() {
    CompletableFuture<FiscalYear> result = fiscalYearService.getCurrentFiscalYear(ID_DOES_NOT_EXIST, requestContextMock);
    CompletionException expectedException = assertThrows(CompletionException.class, result::join);
    HttpException httpException = (HttpException) expectedException.getCause();
    assertEquals(404, httpException.getCode());
}
Also used : FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) CompletionException(java.util.concurrent.CompletionException) HttpException(org.folio.rest.core.exceptions.HttpException) Test(org.junit.jupiter.api.Test)

Example 18 with HttpException

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

the class FundServiceTest method testShouldThrowHttpExceptionAsCauseIfFundNotFound.

@Test
void testShouldThrowHttpExceptionAsCauseIfFundNotFound() {
    // Given
    String fundId = UUID.randomUUID().toString();
    Error expError = new Error().withCode(FUNDS_NOT_FOUND.getCode()).withMessage(String.format(FUNDS_NOT_FOUND.getDescription(), fundId));
    doThrow(new CompletionException(new HttpException(404, expError))).when(restClient).get(any(), eq(requestContext), eq(CompositeFund.class));
    // When
    CompletionException thrown = assertThrows(CompletionException.class, () -> fundService.retrieveFundById(fundId, requestContext).join(), "Expected exception");
    HttpException actHttpException = (HttpException) thrown.getCause();
    Error actError = actHttpException.getError();
    assertEquals(actError.getCode(), expError.getCode());
    assertEquals(actError.getMessage(), String.format(FUNDS_NOT_FOUND.getDescription(), fundId));
    assertEquals(404, actHttpException.getCode());
    // Then
    verify(restClient).get(any(), eq(requestContext), eq(CompositeFund.class));
}
Also used : CompletionException(java.util.concurrent.CompletionException) Error(org.folio.rest.jaxrs.model.Error) HttpException(org.folio.rest.core.exceptions.HttpException) CompositeFund(org.folio.rest.acq.model.finance.CompositeFund) Test(org.junit.jupiter.api.Test)

Example 19 with HttpException

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

the class LocationsAndPiecesConsistencyValidatorTest method testVerifyLocationsAndPiecesConsistencyWhenTwoLocationWithHoldingAndPiecesWithHoldingIdAndLocationId.

@Test
public void testVerifyLocationsAndPiecesConsistencyWhenTwoLocationWithHoldingAndPiecesWithHoldingIdAndLocationId() {
    String holdingId1 = UUID.randomUUID().toString();
    String holdingId2 = UUID.randomUUID().toString();
    Location location1 = new Location().withHoldingId(holdingId1).withQuantity(1).withQuantityPhysical(1);
    Location location2 = new Location().withHoldingId(holdingId2).withQuantity(1).withQuantityPhysical(1);
    String poLineId = UUID.randomUUID().toString();
    CompositePoLine poLine = new CompositePoLine().withId(poLineId).withLocations(List.of(location1, location2));
    List<CompositePoLine> poLines = List.of(poLine);
    Piece piece1 = new Piece().withPoLineId(poLineId).withLocationId(UUID.randomUUID().toString()).withReceivingStatus(Piece.ReceivingStatus.EXPECTED);
    Piece piece2 = new Piece().withPoLineId(poLineId).withHoldingId(holdingId2).withReceivingStatus(Piece.ReceivingStatus.EXPECTED);
    PieceCollection pieces = new PieceCollection().withPieces(List.of(piece1, piece2)).withTotalRecords(2);
    // Expect
    HttpException actHttpException = assertThrows(HttpException.class, () -> LocationsAndPiecesConsistencyValidator.verifyLocationsAndPiecesConsistency(poLines, pieces), "Expected exception");
    Error actError = actHttpException.getError();
    assertEquals(PIECES_TO_BE_DELETED.getCode(), actError.getCode());
    assertEquals(VALIDATION_ERROR, actHttpException.getCode());
}
Also used : PieceCollection(org.folio.rest.jaxrs.model.PieceCollection) Piece(org.folio.rest.jaxrs.model.Piece) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Error(org.folio.rest.jaxrs.model.Error) HttpException(org.folio.rest.core.exceptions.HttpException) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test)

Example 20 with HttpException

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

the class ResponseUtilTest method testIfBadRequestMessageNotNull.

@Test
public void testIfBadRequestMessageNotNull() {
    AsyncResult reply = mock(AsyncResult.class);
    doReturn(new PgException("message", "P1", "22P02", "Detail")).when(reply).cause();
    Promise promise = Promise.promise();
    ResponseUtil.handleFailure(promise, reply);
    HttpException exception = (HttpException) promise.future().cause();
    assertEquals(exception.getCode(), 500);
}
Also used : Promise(io.vertx.core.Promise) HttpException(org.folio.rest.core.exceptions.HttpException) AsyncResult(io.vertx.core.AsyncResult) PgException(io.vertx.pgclient.PgException) 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