Search in sources :

Example 1 with PgException

use of io.vertx.pgclient.PgException 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 2 with PgException

use of io.vertx.pgclient.PgException in project raml-module-builder by folio-org.

the class PgExceptionUtilTest method getMessagePgException.

@Test
public void getMessagePgException() {
    PgException e = new PgException("my message", "my severity", "00742", "error sits in front of the screen");
    assertThat(PgExceptionUtil.getMessage(e), is("ErrorMessage(fields=[(Severity, my severity), (SQLSTATE, 00742), " + "(Message, my message), (Detail, error sits in front of the screen)])"));
}
Also used : PgException(io.vertx.pgclient.PgException) Test(org.junit.Test)

Example 3 with PgException

use of io.vertx.pgclient.PgException in project raml-module-builder by folio-org.

the class PgUtilIT method responseUniqueViolationNoMatch400.

@Test
public void responseUniqueViolationNoMatch400(TestContext testContext) throws Exception {
    Exception genericDatabaseException = new PgException("", null, "", "fooMessage");
    PgExceptionFacade exception = new PgExceptionFacade(genericDatabaseException);
    Method respond400 = ResponseImpl.class.getMethod("respond400WithTextPlain", Object.class);
    Method respond500 = ResponseImpl.class.getMethod("respond500WithTextPlain", Object.class);
    Future<Response> future = PgUtil.responseUniqueViolation("mytable", "myid", exception, null, respond400, respond500);
    assertTrue(future.succeeded());
    assertThat(future.result().getStatus(), is(400));
    assertThat(future.result().getEntity().toString(), containsString("fooMessage"));
}
Also used : Response(javax.ws.rs.core.Response) PostUsersResponse(org.folio.rest.jaxrs.model.Users.PostUsersResponse) 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 PgException

use of io.vertx.pgclient.PgException in project raml-module-builder by folio-org.

the class ValidationHelperTest method dupMsgTest.

@Test
public void dupMsgTest(TestContext context) {
    Async async = context.async();
    String msg = "duplicate _id value violates unique constraint: 55835c7c-2885-44f4-96ac-f03525b8e608";
    Throwable t = new PgException("duplicate key value violates unique constraint \"123456\"", null, "23505", "Key (_id)=(55835c7c-2885-44f4-96ac-f03525b8e608) already exists.");
    ValidationHelper.handleError(t, r -> {
        String responseMsg = ((Errors) r.result().getEntity()).getErrors().get(0).getMessage();
        context.assertEquals(msg, responseMsg);
        async.complete();
    });
}
Also used : Errors(org.folio.rest.jaxrs.model.Errors) Async(io.vertx.ext.unit.Async) PgException(io.vertx.pgclient.PgException) Test(org.junit.Test)

Example 5 with PgException

use of io.vertx.pgclient.PgException in project raml-module-builder by folio-org.

the class ValidationHelperTest method uuidTest.

@Test
public void uuidTest(TestContext context) {
    Async async = context.async();
    Throwable t = new PgException("invalid input syntax for uuid: \"1234567\"", null, "22P02", null);
    ValidationHelper.handleError(t, r -> {
        context.assertEquals(422, r.result().getStatus());
        async.complete();
    });
}
Also used : Async(io.vertx.ext.unit.Async) PgException(io.vertx.pgclient.PgException) Test(org.junit.Test)

Aggregations

PgException (io.vertx.pgclient.PgException)13 Test (org.junit.Test)10 Async (io.vertx.ext.unit.Async)5 Method (java.lang.reflect.Method)4 Response (javax.ws.rs.core.Response)4 PostUsersResponse (org.folio.rest.jaxrs.model.Users.PostUsersResponse)4 ExpectedException (org.junit.rules.ExpectedException)4 Errors (org.folio.rest.jaxrs.model.Errors)3 Test (org.junit.jupiter.api.Test)2