use of org.folio.circulation.support.BadRequestFailure in project mod-circulation by folio-org.
the class RequestByInstanceIdResourceTests method getExpectedErrorMessages.
@Test
void getExpectedErrorMessages() {
HttpFailure validationError = ValidationErrorFailure.singleValidationError(new ValidationError("validationError", "someParam", "null"));
String errorMessage = RequestByInstanceIdResource.getErrorMessage(validationError);
assertTrue(errorMessage.contains("validationError"));
HttpFailure serverErrorFailure = new ServerErrorFailure("serverError");
errorMessage = RequestByInstanceIdResource.getErrorMessage(serverErrorFailure);
assertEquals("serverError", errorMessage);
HttpFailure badRequestFailure = new BadRequestFailure("badRequestFailure");
errorMessage = RequestByInstanceIdResource.getErrorMessage(badRequestFailure);
assertEquals("badRequestFailure", errorMessage);
Response fakeResponse = new Response(500, "fakeResponseFailure", "text/javascript");
HttpFailure forwardOnFailure = new ForwardOnFailure(fakeResponse);
errorMessage = RequestByInstanceIdResource.getErrorMessage(forwardOnFailure);
assertEquals("fakeResponseFailure", errorMessage);
}
use of org.folio.circulation.support.BadRequestFailure in project mod-circulation by folio-org.
the class JsonSchemaValidationTest method validationFailsForInvalidJson.
@Test
void validationFailsForInvalidJson() throws IOException {
final JsonSchemaValidator validator = JsonSchemaValidator.fromResource("/check-in-by-barcode-request.json");
final Result<String> result = validator.validate("foo blah");
assertThat(result.succeeded(), is(false));
assertThat(result.cause(), instanceOf(BadRequestFailure.class));
final BadRequestFailure badRequestFailure = (BadRequestFailure) result.cause();
assertThat(badRequestFailure.getReason(), is("Cannot parse \"foo blah\" as JSON"));
}
use of org.folio.circulation.support.BadRequestFailure in project mod-circulation by folio-org.
the class RequestFromRepresentationService method validateStatus.
private Result<Request> validateStatus(Request request) {
JsonObject representation = request.getRequestRepresentation();
RequestStatus status = RequestStatus.from(representation);
if (!status.isValid()) {
return failed(new BadRequestFailure(RequestStatus.invalidStatusErrorMessage()));
} else {
status.writeTo(representation);
return succeeded(request);
}
}
Aggregations