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