io.vertx.pgclient.PgException Java Examples

The following examples show how to use io.vertx.pgclient.PgException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResponseHelper.java    From vertx-sql-client with Apache License 2.0 6 votes vote down vote up
public static PgException getCompletePgException() {
  ErrorResponse errorResponse = new ErrorResponse();
  errorResponse.setMessage("myMessage");
  errorResponse.setSeverity("mySeverity");
  errorResponse.setCode("myCode");
  errorResponse.setDetail("myDetail");
  errorResponse.setHint("myHint");
  errorResponse.setPosition("myPosition");
  errorResponse.setHint("myHint");
  errorResponse.setPosition("myPosition");
  errorResponse.setInternalPosition("myInternalPosition");
  errorResponse.setInternalQuery("myInternalQuery");
  errorResponse.setWhere("myWhere");
  errorResponse.setFile("myFile");
  errorResponse.setLine("myLine");
  errorResponse.setRoutine("myRoutine");
  errorResponse.setSchema("mySchema");
  errorResponse.setTable("myTable");
  errorResponse.setColumn("myColumn");
  errorResponse.setDataType("myDataType");
  errorResponse.setConstraint("myConstraint");
  return errorResponse.toException();
}
 
Example #2
Source File: ValidationHelperTest.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
@Test
public void authTest(TestContext context) {
  Async async = context.async();
  Throwable t = new PgException(
      "password authentication failed for user \"harvard9_mod_configuration\"",
      null, "28P01", null);
  ValidationHelper.handleError(t, r -> {
    context.assertEquals(401, r.result().getStatus());
    async.complete();
  });
}
 
Example #3
Source File: ValidationHelperTest.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
@Test
public void fkTest(TestContext context) {
  Async async = context.async();
  Throwable t = new PgException(
      "insert or update on table \"item\" violates foreign key constraint \"item_permanentloantypeid_fkey\"",
      null,
      "23503",
  "Key (permanentloantypeid)=(2b94c631-fca9-4892-a730-03ee529ffe27) is not present in table \"loan_type\".");
  ValidationHelper.handleError(t, r -> {
    context.assertEquals(422, r.result().getStatus());
    async.complete();
  });
}
 
Example #4
Source File: PgExceptionUtil.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
public static Map<Character, String> getBadRequestFields(Throwable throwable) {
  if (!(throwable instanceof PgException)) {
    return null;
  }
  Map<Character, String> map = new HashMap<>();
  map.put('M', ((PgException) throwable).getMessage());
  map.put('D', ((PgException) throwable).getDetail());
  map.put('S', ((PgException) throwable).getSeverity());
  map.put('C', ((PgException) throwable).getCode());
  return map;
}
 
Example #5
Source File: ValidationHelperTest.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
@Test
public void dupTest(TestContext context) {
  Async async = context.async();
  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 -> {
    context.assertEquals(422, r.result().getStatus());
    async.complete();
  });
}
 
Example #6
Source File: PgExceptionFacadeTest.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
@Test
void getter() {
  PgExceptionFacade f = new PgExceptionFacade(new PgException("msg", "FINAL WARNING", "22P02", "very bad"));
  assertThat(f.getMessage(), is("msg"));
  assertThat(f.getSeverity(), is("FINAL WARNING"));
  assertThat(f.getSqlState(), is("22P02"));
  assertThat(f.getDetail(), is("very bad"));
  Map<Character,String> fields = f.getFields();
  assertThat(fields.get('M'), is("msg"));
  assertThat(fields.get('S'), is("FINAL WARNING"));
  assertThat(fields.get('C'), is("22P02"));
  assertThat(fields.get('D'), is("very bad"));
}
 
Example #7
Source File: PgExceptionFacadeTest.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
@Test
void isInvalidTextRepresentation() {
  PgExceptionFacade f = new PgExceptionFacade(new PgException(null, null, "22P02", null));
  assertThat(f.isInvalidTextRepresentation(), is(true));
  PgExceptionFacade f2 = new PgExceptionFacade(new PgException(null, null, "22P03", null));
  assertThat(f2.isInvalidTextRepresentation(), is(false));
}
 
Example #8
Source File: ValidationHelperTest.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
@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();
  });
}
 
Example #9
Source File: PgUtilIT.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
@Test
public void responseUniqueViolationNoMatch422(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);
  Method respond422 = PgUtil.respond422method(ResponseWith422.class);
  Future<Response> future = PgUtil.responseUniqueViolation("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("fooMessage"));
}
 
Example #10
Source File: PgExceptionUtilTest.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
@Test
public void isForeignKeyViolation() {
  assertThat(PgExceptionUtil.isForeignKeyViolation(new PgException("", null, "23503", "")), is(true));
  assertThat(PgExceptionUtil.isForeignKeyViolation(new PgException("", null, "22P02", "")), is(false));
  assertThat(PgExceptionUtil.isForeignKeyViolation(new PgException("", null, "", "")), is(false));
  assertThat(PgExceptionUtil.isForeignKeyViolation(null), is(false));
}
 
Example #11
Source File: PgUtilIT.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
@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"));
}
 
Example #12
Source File: PgUtilIT.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
@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"));
}
 
Example #13
Source File: PgUtilIT.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
@Test
public void responseForeignKeyViolationNoMatch400(TestContext testContext) throws Exception {
  Exception genericDatabaseException = new PgException("", null, "", "barMessage");
  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.responseForeignKeyViolation("mytable", "myid", exception, null, respond400, respond500);
  assertTrue(future.succeeded());
  assertThat(future.result().getStatus(), is(400));
  assertThat(future.result().getEntity().toString(), containsString("barMessage"));
}
 
Example #14
Source File: PgExceptionUtilTest.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
@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)])"));
}
 
Example #15
Source File: SomethingDaoTest.java    From vertx-jooq with MIT License 4 votes vote down vote up
@Override
protected void assertDuplicateKeyException(Throwable x) {
    assertException(PgException.class, x, pgException -> Assert.assertEquals("23505", pgException.getCode()));
}
 
Example #16
Source File: SomethingCompositeDaoTest.java    From vertx-jooq with MIT License 4 votes vote down vote up
@Override
protected void assertDuplicateKeyException(Throwable x) {
    assertException(PgException.class, x, pgException -> Assert.assertEquals("23505", pgException.getCode()));
}
 
Example #17
Source File: SomethingDaoTest.java    From vertx-jooq with MIT License 4 votes vote down vote up
@Override
protected void assertDuplicateKeyException(Throwable x) {
    assertException(PgException.class, x, pgException -> Assert.assertEquals("23505", pgException.getCode()));
}
 
Example #18
Source File: SomethingCompositeDaoTest.java    From vertx-jooq with MIT License 4 votes vote down vote up
@Override
protected void assertDuplicateKeyException(Throwable x) {
    assertException(PgException.class, x, pgException -> Assert.assertEquals("23505", pgException.getCode()));
}
 
Example #19
Source File: SomethingDaoTest.java    From vertx-jooq with MIT License 4 votes vote down vote up
@Override
protected void assertDuplicateKeyException(Throwable x) {
    Assert.assertEquals(PgException.class, x.getClass());
    PgException pgException = (PgException) x;
    Assert.assertEquals("23505", pgException.getCode());
}
 
Example #20
Source File: SomethingCompositeDaoTest.java    From vertx-jooq with MIT License 4 votes vote down vote up
@Override
protected void assertDuplicateKeyException(Throwable x) {
    assertException(PgException.class, x, pgException -> Assert.assertEquals("23505", pgException.getCode()));
}
 
Example #21
Source File: SomethingDaoTest.java    From vertx-jooq with MIT License 4 votes vote down vote up
@Override
protected void assertDuplicateKeyException(Throwable x) {
    assertException(PgException.class, x, pgException -> Assert.assertEquals("23505", pgException.getCode()));
}
 
Example #22
Source File: SomethingCompositeDaoTest.java    From vertx-jooq with MIT License 4 votes vote down vote up
@Override
protected void assertDuplicateKeyException(Throwable x) {
    Assert.assertEquals(PgException.class, x.getClass());
    PgException pgException = (PgException) x;
    Assert.assertEquals("23505", pgException.getCode());
}
 
Example #23
Source File: SomethingDaoTest.java    From vertx-jooq with MIT License 4 votes vote down vote up
@Override
protected void assertDuplicateKeyException(Throwable x) {
    Assert.assertEquals(PgException.class, x.getClass());
    PgException pgException = (PgException) x;
    Assert.assertEquals("23505", pgException.getCode());
}
 
Example #24
Source File: SomethingCompositeDaoTest.java    From vertx-jooq with MIT License 4 votes vote down vote up
@Override
protected void assertDuplicateKeyException(Throwable x) {
    Assert.assertEquals(PgException.class, x.getClass());
    PgException pgException = (PgException) x;
    Assert.assertEquals("23505", pgException.getCode());
}
 
Example #25
Source File: EventsVerticle.java    From vertx-in-action with MIT License 4 votes vote down vote up
private boolean duplicateKeyInsert(Throwable err) {
  return (err instanceof PgException) && "23505".equals(((PgException) err).getCode());
}
 
Example #26
Source File: SomethingDaoTest.java    From vertx-jooq with MIT License 4 votes vote down vote up
@Override
protected void assertDuplicateKeyException(Throwable x) {
    assertException(PgException.class, x, pgException -> Assert.assertEquals("23505", pgException.getCode()));
}
 
Example #27
Source File: SomethingCompositeDaoTest.java    From vertx-jooq with MIT License 4 votes vote down vote up
@Override
protected void assertDuplicateKeyException(Throwable x) {
    assertException(PgException.class, x, pgException -> Assert.assertEquals("23505", pgException.getCode()));
}
 
Example #28
Source File: PgExceptionUtilTest.java    From raml-module-builder with Apache License 2.0 4 votes vote down vote up
private void assertString(String sqlstate, String detail, String message, String expected) {
  String actual = PgExceptionUtil.badRequestMessage(new PgException(message, null, sqlstate, detail));
  assertThat(actual, is(expected));
}
 
Example #29
Source File: PgExceptionUtilTest.java    From raml-module-builder with Apache License 2.0 4 votes vote down vote up
@Test
public void isInvalidTextRepresentationn() {
  assertThat(PgExceptionUtil.isInvalidTextRepresentation(new PgException("", null, "22P02", "")), is(true));
  assertThat(PgExceptionUtil.isInvalidTextRepresentation(new PgException("", null, "23503", "")), is(false));
}
 
Example #30
Source File: PgExceptionUtilTest.java    From raml-module-builder with Apache License 2.0 4 votes vote down vote up
@Test
public void isUniqueViolation() {
  assertThat(PgExceptionUtil.isUniqueViolation(new PgException("", null, "23505", "")), is(true));
  assertThat(PgExceptionUtil.isUniqueViolation(new PgException("", null, "23503", "")), is(false));
}