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"));
}
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)])"));
}
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"));
}
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();
});
}
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();
});
}
Aggregations