@Test public void shouldSupportSSLParameters() throws Exception { // the default docker image we're testing against doesn't use SSL, so check that the connector fails to start when // SSL is enabled Configuration config = TestHelper.defaultConfig().with(PostgresConnectorConfig.SSL_MODE, PostgresConnectorConfig.SecureConnectionMode.REQUIRED).build(); start(PostgresConnector.class, config, (success, msg, error) -> { if (TestHelper.shouldSSLConnectionFail()) { // we expect the task to fail at startup when we're printing the server info assertThat(success).isFalse(); assertThat(error).isInstanceOf(ConnectException.class); Throwable cause = error.getCause(); assertThat(cause).isInstanceOf(SQLException.class); assertThat(PSQLState.CONNECTION_REJECTED.getState().equals(((SQLException)cause).getSQLState())); } }); if (TestHelper.shouldSSLConnectionFail()) { assertConnectorNotRunning(); } else { assertConnectorIsRunning(); Thread.sleep(10000); stopConnector(); } }
private void assertExceptionIsThrown(String queryString) { try ( Session session = openSession() ) { Transaction tx = null; try { tx = session.beginTransaction(); session.createQuery( queryString ).list(); tx.commit(); Fail.fail( "Expected exception for query: [" + queryString + "]" ); } catch ( PersistenceException e) { assertThat( e.getCause() ).isInstanceOf( HibernateException.class ); assertThat( e.getCause().getMessage() ).startsWith( "OGM000089: " ); } finally { if ( tx != null && tx.isActive() ) { tx.rollback(); } } } }
@Test public void shouldSupportSSLParameters() throws Exception { // the default docker image we're testing against doesn't use SSL, so check that the connector fails to start when // SSL is enabled Configuration config = TestHelper.defaultConfig().with(PostgresConnectorConfig.SSL_MODE, PostgresConnectorConfig.SecureConnectionMode.REQUIRED).build(); start(PostgresConnector.class, config, (success, msg, error) -> { if (TestHelper.shouldSSLConnectionFail()) { // we expect the task to fail at startup when we're printing the server info assertThat(success).isFalse(); assertThat(error).isInstanceOf(ConnectException.class); Throwable cause = error.getCause(); assertThat(cause).isInstanceOf(SQLException.class); assertThat(PSQLState.CONNECTION_REJECTED.getState().equals(((SQLException)cause).getSQLState())); } }); if (TestHelper.shouldSSLConnectionFail()) { assertConnectorNotRunning(); } else { assertConnectorIsRunning(); Thread.sleep(10000); stopConnector(); } }