Search in sources :

Example 1 with Errors

use of org.folio.rest.jaxrs.model.Errors in project raml-module-builder by folio-org.

the class PgUtilIT method respond422IllegalArgumentException.

@Test(expected = IllegalArgumentException.class)
public void respond422IllegalArgumentException() throws Throwable {
    class C {

        @SuppressWarnings("unused")
        private void privateMethod(Errors entity) {
        }
    }
    Method method = C.class.getDeclaredMethod("privateMethod", Errors.class);
    PgUtil.respond422(method, "foo", "bar", "baz");
}
Also used : Errors(org.folio.rest.jaxrs.model.Errors) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 2 with Errors

use of org.folio.rest.jaxrs.model.Errors in project raml-module-builder by folio-org.

the class PgUtilIT method putForeignKeyViolation422.

@Test
public void putForeignKeyViolation422(TestContext testContext) {
    String user1 = randomUuid();
    String user2 = randomUuid();
    String refId = randomUuid();
    post(testContext, "Folio", user1, 201);
    insertReferencing(testContext, refId, user1);
    PgUtil.put("referencing", new Referencing().withId(refId).withUserId(user2), refId, okapiHeaders, vertx.getOrCreateContext(), ResponseWith422.class, asyncAssertSuccess(testContext, 422, response -> {
        Errors errors = (Errors) response.result().getEntity();
        assertThat(errors.getErrors(), hasSize(1));
        Error error = errors.getErrors().get(0);
        assertThat(error.getMessage(), containsString("Cannot set referencing.userid = " + user2 + " because it does not exist in users.id."));
        assertThat(error.getParameters(), hasSize(1));
        assertThat(error.getParameters().get(0).getKey(), is("referencing.userid"));
        assertThat(error.getParameters().get(0).getValue(), is(user2));
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) CoreMatchers(org.hamcrest.CoreMatchers) Arrays(java.util.Arrays) XOkapiHeaders(org.folio.okapi.common.XOkapiHeaders) RoutingContext(io.vertx.ext.web.RoutingContext) VertxUtils(org.folio.rest.tools.utils.VertxUtils) Users(org.folio.rest.jaxrs.model.Users) User(org.folio.rest.jaxrs.model.User) Map(java.util.Map) UtilityClassTester(org.folio.okapi.testing.UtilityClassTester) JsonObject(io.vertx.core.json.JsonObject) Method(java.lang.reflect.Method) Errors(org.folio.rest.jaxrs.model.Errors) AfterClass(org.junit.AfterClass) UUID(java.util.UUID) Future(io.vertx.core.Future) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) List(java.util.List) Response(javax.ws.rs.core.Response) Buffer(io.vertx.core.buffer.Buffer) PostUsersResponse(org.folio.rest.jaxrs.model.Users.PostUsersResponse) Mockito.mock(org.mockito.Mockito.mock) PgException(io.vertx.pgclient.PgException) Strictness(org.mockito.quality.Strictness) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) RestVerticle(org.folio.rest.RestVerticle) BeforeClass(org.junit.BeforeClass) PostgresTesterContainer(org.folio.postgres.testing.PostgresTesterContainer) RunWith(org.junit.runner.RunWith) SchemaMaker(org.folio.rest.persist.ddlgen.SchemaMaker) Mockito.timeout(org.mockito.Mockito.timeout) Answer(org.mockito.stubbing.Answer) ResponseDelegate(org.folio.rest.jaxrs.resource.support.ResponseDelegate) Timeout(org.junit.rules.Timeout) Referencing(org.folio.rest.jaxrs.model.Referencing) MockitoJUnit(org.mockito.junit.MockitoJUnit) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AsyncResult(io.vertx.core.AsyncResult) Mockito.anyString(org.mockito.Mockito.anyString) ExpectedException(org.junit.rules.ExpectedException) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Vertx(io.vertx.core.Vertx) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AssertionFailedError(junit.framework.AssertionFailedError) Mockito.when(org.mockito.Mockito.when) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) UserdataCollection(org.folio.rest.jaxrs.model.UserdataCollection) Mockito.verify(org.mockito.Mockito.verify) Error(org.folio.rest.jaxrs.model.Error) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) TreeMap(java.util.TreeMap) MockitoRule(org.mockito.junit.MockitoRule) Handler(io.vertx.core.Handler) Collections(java.util.Collections) Errors(org.folio.rest.jaxrs.model.Errors) AssertionFailedError(junit.framework.AssertionFailedError) Error(org.folio.rest.jaxrs.model.Error) Referencing(org.folio.rest.jaxrs.model.Referencing) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 3 with Errors

use of org.folio.rest.jaxrs.model.Errors in project raml-module-builder by folio-org.

the class PgUtilIT method responseForeignKeyViolationNoMatch422.

@Test
public void responseForeignKeyViolationNoMatch422(TestContext testContext) throws Exception {
    Exception genericDatabaseException = new PgException("", null, "", "bazMessage");
    PgExceptionFacade exception = new PgExceptionFacade(genericDatabaseException);
    Method respond400 = ResponseImpl.class.getMethod("respond400WithTextPlain", Object.class);
    Method respond500 = ResponseImpl.class.getMethod("respond500WithTextPlain", Object.class);
    Method respond422 = PgUtil.respond422method(ResponseWith422.class);
    Future<Response> future = PgUtil.responseForeignKeyViolation("mytable", "myid", exception, respond422, respond400, respond500);
    assertTrue(future.succeeded());
    assertThat(future.result().getStatus(), is(422));
    Errors errors = (Errors) future.result().getEntity();
    assertThat(errors.getErrors().get(0).getMessage(), containsString("bazMessage"));
}
Also used : Response(javax.ws.rs.core.Response) PostUsersResponse(org.folio.rest.jaxrs.model.Users.PostUsersResponse) Errors(org.folio.rest.jaxrs.model.Errors) Method(java.lang.reflect.Method) PgException(io.vertx.pgclient.PgException) ExpectedException(org.junit.rules.ExpectedException) PgException(io.vertx.pgclient.PgException) Test(org.junit.Test)

Example 4 with Errors

use of org.folio.rest.jaxrs.model.Errors in project raml-module-builder by folio-org.

the class PgUtilIT method deleteByIdForeignKeyViolation422.

@Test
public void deleteByIdForeignKeyViolation422(TestContext testContext) {
    String userId = randomUuid();
    String refId = randomUuid();
    post(testContext, "Folio", userId, 201);
    insertReferencing(testContext, refId, userId);
    PgUtil.deleteById("users", userId, okapiHeaders, vertx.getOrCreateContext(), ResponseWith422.class, asyncAssertSuccess(testContext, 422, response -> {
        Errors errors = (Errors) response.result().getEntity();
        assertThat(errors.getErrors(), hasSize(1));
        Error error = errors.getErrors().get(0);
        assertThat(error.getMessage(), containsString("Cannot delete users.id = " + userId + " because id is still referenced from table referencing"));
        assertThat(error.getParameters(), hasSize(1));
        assertThat(error.getParameters().get(0).getKey(), is("users.id"));
        assertThat(error.getParameters().get(0).getValue(), is(userId));
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) CoreMatchers(org.hamcrest.CoreMatchers) Arrays(java.util.Arrays) XOkapiHeaders(org.folio.okapi.common.XOkapiHeaders) RoutingContext(io.vertx.ext.web.RoutingContext) VertxUtils(org.folio.rest.tools.utils.VertxUtils) Users(org.folio.rest.jaxrs.model.Users) User(org.folio.rest.jaxrs.model.User) Map(java.util.Map) UtilityClassTester(org.folio.okapi.testing.UtilityClassTester) JsonObject(io.vertx.core.json.JsonObject) Method(java.lang.reflect.Method) Errors(org.folio.rest.jaxrs.model.Errors) AfterClass(org.junit.AfterClass) UUID(java.util.UUID) Future(io.vertx.core.Future) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) List(java.util.List) Response(javax.ws.rs.core.Response) Buffer(io.vertx.core.buffer.Buffer) PostUsersResponse(org.folio.rest.jaxrs.model.Users.PostUsersResponse) Mockito.mock(org.mockito.Mockito.mock) PgException(io.vertx.pgclient.PgException) Strictness(org.mockito.quality.Strictness) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) RestVerticle(org.folio.rest.RestVerticle) BeforeClass(org.junit.BeforeClass) PostgresTesterContainer(org.folio.postgres.testing.PostgresTesterContainer) RunWith(org.junit.runner.RunWith) SchemaMaker(org.folio.rest.persist.ddlgen.SchemaMaker) Mockito.timeout(org.mockito.Mockito.timeout) Answer(org.mockito.stubbing.Answer) ResponseDelegate(org.folio.rest.jaxrs.resource.support.ResponseDelegate) Timeout(org.junit.rules.Timeout) Referencing(org.folio.rest.jaxrs.model.Referencing) MockitoJUnit(org.mockito.junit.MockitoJUnit) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AsyncResult(io.vertx.core.AsyncResult) Mockito.anyString(org.mockito.Mockito.anyString) ExpectedException(org.junit.rules.ExpectedException) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Vertx(io.vertx.core.Vertx) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AssertionFailedError(junit.framework.AssertionFailedError) Mockito.when(org.mockito.Mockito.when) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) UserdataCollection(org.folio.rest.jaxrs.model.UserdataCollection) Mockito.verify(org.mockito.Mockito.verify) Error(org.folio.rest.jaxrs.model.Error) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) TreeMap(java.util.TreeMap) MockitoRule(org.mockito.junit.MockitoRule) Handler(io.vertx.core.Handler) Collections(java.util.Collections) Errors(org.folio.rest.jaxrs.model.Errors) AssertionFailedError(junit.framework.AssertionFailedError) Error(org.folio.rest.jaxrs.model.Error) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 5 with Errors

use of org.folio.rest.jaxrs.model.Errors in project raml-module-builder by folio-org.

the class ValidationHelper method createValidationErrorMessage.

public static Errors createValidationErrorMessage(String field, String value, String message) {
    Errors e = new Errors();
    Error error = new Error();
    Parameter p = new Parameter();
    p.setKey(field);
    p.setValue(value);
    error.getParameters().add(p);
    error.setMessage(message);
    error.setCode("-1");
    error.setType(DomainModelConsts.VALIDATION_FIELD_ERROR);
    List<Error> l = new ArrayList<>();
    l.add(error);
    e.setErrors(l);
    return e;
}
Also used : Errors(org.folio.rest.jaxrs.model.Errors) ArrayList(java.util.ArrayList) Error(org.folio.rest.jaxrs.model.Error) Parameter(org.folio.rest.jaxrs.model.Parameter)

Aggregations

Errors (org.folio.rest.jaxrs.model.Errors)14 Test (org.junit.Test)7 PgException (io.vertx.pgclient.PgException)6 Method (java.lang.reflect.Method)6 Response (javax.ws.rs.core.Response)6 JsonObject (io.vertx.core.json.JsonObject)5 Error (org.folio.rest.jaxrs.model.Error)5 PostUsersResponse (org.folio.rest.jaxrs.model.Users.PostUsersResponse)5 ExpectedException (org.junit.rules.ExpectedException)5 Async (io.vertx.ext.unit.Async)4 AsyncResult (io.vertx.core.AsyncResult)3 Future (io.vertx.core.Future)3 Handler (io.vertx.core.Handler)3 Vertx (io.vertx.core.Vertx)3 Buffer (io.vertx.core.buffer.Buffer)3 Json (io.vertx.core.json.Json)3 TestContext (io.vertx.ext.unit.TestContext)3 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)3 RoutingContext (io.vertx.ext.web.RoutingContext)3 Arrays (java.util.Arrays)3