Search in sources :

Example 1 with BadRequestFailure

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);
}
Also used : Response(org.folio.circulation.support.http.client.Response) ServerErrorFailure(org.folio.circulation.support.ServerErrorFailure) HttpFailure(org.folio.circulation.support.HttpFailure) BadRequestFailure(org.folio.circulation.support.BadRequestFailure) ValidationError(org.folio.circulation.support.http.server.ValidationError) ForwardOnFailure(org.folio.circulation.support.ForwardOnFailure) Test(org.junit.jupiter.api.Test)

Example 2 with BadRequestFailure

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"));
}
Also used : BadRequestFailure(org.folio.circulation.support.BadRequestFailure) Test(org.junit.jupiter.api.Test)

Example 3 with BadRequestFailure

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);
    }
}
Also used : BadRequestFailure(org.folio.circulation.support.BadRequestFailure) JsonObject(io.vertx.core.json.JsonObject) RequestStatus(org.folio.circulation.domain.RequestStatus)

Aggregations

BadRequestFailure (org.folio.circulation.support.BadRequestFailure)3 Test (org.junit.jupiter.api.Test)2 JsonObject (io.vertx.core.json.JsonObject)1 RequestStatus (org.folio.circulation.domain.RequestStatus)1 ForwardOnFailure (org.folio.circulation.support.ForwardOnFailure)1 HttpFailure (org.folio.circulation.support.HttpFailure)1 ServerErrorFailure (org.folio.circulation.support.ServerErrorFailure)1 Response (org.folio.circulation.support.http.client.Response)1 ValidationError (org.folio.circulation.support.http.server.ValidationError)1