org.postgresql.util.PSQLState Java Examples

The following examples show how to use org.postgresql.util.PSQLState. 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: ManagerTest.java    From passopolis-server with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testExtractPSQLException() {
  PSQLException psqlException = new PSQLException("fake error", PSQLState.UNEXPECTED_ERROR);
  // passing in the exception itself works
  assertEquals(psqlException, Manager.extractPSQLException(psqlException));

  // wrapping the exception in a SQLException (as done by ORMLite) works
  SQLException wrap1 = new SQLException("wrapper", psqlException);
  assertEquals(psqlException, Manager.extractPSQLException(wrap1));

  // ORMLite can also double wrap the exception
  SQLException wrap2 = new SQLException("double", wrap1);
  assertEquals(psqlException, Manager.extractPSQLException(wrap2));

  // SQLException with some other kind of exception: null
  SQLException other = new SQLException("other", new RuntimeException("cause"));
  assertNull(Manager.extractPSQLException(other));
  
  Throwable t = new Throwable("hello", psqlException);
  assertEquals(psqlException, Manager.extractPSQLException(t));
}
 
Example #2
Source File: PostgresITest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyStatement() throws Exception {
    try (Connection conn = DriverManager.getConnection(url(RW), properties)) {
        assertThat(conn.createStatement().execute(""), is(false));

        try {
            conn.createStatement().executeQuery("");
            fail("executeQuery with empty query should throw a 'No results were returned by the query' error");
        } catch (PSQLException e) {
            // can't use expectedException.expectMessage because error messages are localized and locale is randomized
            assertThat(e.getSQLState(), is(PSQLState.NO_DATA.getState()));
        }
    }
}