Search in sources :

Example 1 with ServerErrorFailure

use of org.folio.circulation.support.ServerErrorFailure 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 ServerErrorFailure

use of org.folio.circulation.support.ServerErrorFailure in project mod-circulation by folio-org.

the class LogCheckInServiceTest method logCheckInOperationPropagatesException.

@Test
void logCheckInOperationPropagatesException() {
    final CheckInContext context = checkInProcessRecords();
    final ServerErrorFailure postError = new ServerErrorFailure("ServerError");
    when(checkInStorageClient.post(any(JsonObject.class))).thenReturn(CompletableFuture.completedFuture(Result.failed(postError)));
    final CompletableFuture<Result<CheckInContext>> logCheckInOperation = logCheckInService.logCheckInOperation(context);
    final Result<CheckInContext> logResult = logCheckInOperation.getNow(Result.failed(new ServerErrorFailure("Uncompleted")));
    assertThat(logResult.failed(), is(true));
    assertThat(logResult.cause(), is(postError));
}
Also used : ServerErrorFailure(org.folio.circulation.support.ServerErrorFailure) CheckInContext(org.folio.circulation.domain.CheckInContext) JsonObject(io.vertx.core.json.JsonObject) Result(org.folio.circulation.support.results.Result) Test(org.junit.jupiter.api.Test)

Example 3 with ServerErrorFailure

use of org.folio.circulation.support.ServerErrorFailure in project mod-circulation by folio-org.

the class ResponseInterpretationTests method shouldCaptureErrorWhenMappingFailsAtRuntime.

@Test
void shouldCaptureErrorWhenMappingFailsAtRuntime() {
    final JsonObject body = new JsonObject().put("foo", "hello").put("bar", "world");
    Result<JsonObject> result = new ResponseInterpreter<JsonObject>().flatMapOn(200, response -> {
        throw new RuntimeException("Not good");
    }).apply(new Response(200, body.toString(), ""));
    assertThat(result.succeeded(), is(false));
    assertThat(result.cause(), instanceOf(ServerErrorFailure.class));
    final ServerErrorFailure cause = (ServerErrorFailure) result.cause();
    assertThat(cause.getReason(), containsString("Not good"));
    assertThat(cause.getReason(), containsString("RuntimeException"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MultiMap.caseInsensitiveMultiMap(io.vertx.core.MultiMap.caseInsensitiveMultiMap) Result.of(org.folio.circulation.support.results.Result.of) TEXT_PLAIN(org.folio.circulation.support.http.ContentType.TEXT_PLAIN) Result(org.folio.circulation.support.results.Result) ServerErrorFailure(org.folio.circulation.support.ServerErrorFailure) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Test(org.junit.jupiter.api.Test) APPLICATION_JSON(org.folio.circulation.support.http.ContentType.APPLICATION_JSON) Function.identity(java.util.function.Function.identity) JsonObject(io.vertx.core.json.JsonObject) ResponseMapping.mapUsingJson(org.folio.circulation.support.http.ResponseMapping.mapUsingJson) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ServerErrorFailure(org.folio.circulation.support.ServerErrorFailure) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test)

Example 4 with ServerErrorFailure

use of org.folio.circulation.support.ServerErrorFailure in project mod-circulation by folio-org.

the class MoreThanOneLoanValidatorTests method allowSingleLoan.

@Test
void allowSingleLoan() {
    final MoreThanOneLoanValidator validator = new MoreThanOneLoanValidator(() -> new ServerErrorFailure("More than one loan"));
    final Result<MultipleRecords<Loan>> multipleLoans = multipleLoansResult(generateLoan());
    final Result<MultipleRecords<Loan>> result = validator.failWhenMoreThanOneLoan(multipleLoans);
    assertThat(result.succeeded(), is(true));
}
Also used : ServerErrorFailure(org.folio.circulation.support.ServerErrorFailure) MultipleRecords(org.folio.circulation.domain.MultipleRecords) Test(org.junit.jupiter.api.Test)

Example 5 with ServerErrorFailure

use of org.folio.circulation.support.ServerErrorFailure in project mod-circulation by folio-org.

the class MoreThanOneLoanValidatorTests method failWhenMoreThanOneLoan.

@Test
void failWhenMoreThanOneLoan() {
    final MoreThanOneLoanValidator validator = new MoreThanOneLoanValidator(() -> new ServerErrorFailure("More than one loan"));
    final Result<MultipleRecords<Loan>> multipleLoans = multipleLoansResult(generateLoan(), generateLoan());
    final Result<MultipleRecords<Loan>> result = validator.failWhenMoreThanOneLoan(multipleLoans);
    assertThat(result, isErrorFailureContaining("More than one loan"));
}
Also used : ServerErrorFailure(org.folio.circulation.support.ServerErrorFailure) MultipleRecords(org.folio.circulation.domain.MultipleRecords) Test(org.junit.jupiter.api.Test)

Aggregations

ServerErrorFailure (org.folio.circulation.support.ServerErrorFailure)20 Test (org.junit.jupiter.api.Test)15 Result (org.folio.circulation.support.results.Result)6 JsonObject (io.vertx.core.json.JsonObject)5 MultiMap.caseInsensitiveMultiMap (io.vertx.core.MultiMap.caseInsensitiveMultiMap)3 Function.identity (java.util.function.Function.identity)3 lombok.val (lombok.val)3 MultipleRecords (org.folio.circulation.domain.MultipleRecords)3 APPLICATION_JSON (org.folio.circulation.support.http.ContentType.APPLICATION_JSON)3 TEXT_PLAIN (org.folio.circulation.support.http.ContentType.TEXT_PLAIN)3 ResponseMapping.mapUsingJson (org.folio.circulation.support.http.ResponseMapping.mapUsingJson)3 Result.of (org.folio.circulation.support.results.Result.of)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 CoreMatchers.instanceOf (org.hamcrest.CoreMatchers.instanceOf)3 CoreMatchers.is (org.hamcrest.CoreMatchers.is)3 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)3 Optional (java.util.Optional)2 HttpFailure (org.folio.circulation.support.HttpFailure)2 Description (org.hamcrest.Description)2 TypeSafeDiagnosingMatcher (org.hamcrest.TypeSafeDiagnosingMatcher)2