@Test public void shouldNotStartWithInvalidConfiguration() throws Exception { // use an empty configuration which should be invalid because of the lack of DB connection details Configuration config = Configuration.create().build(); // we expect the engine will log at least one error, so preface it ... logger.info("Attempting to start the connector with an INVALID configuration, so MULTIPLE error messages & one exceptions will appear in the log"); start(PostgresConnector.class, config, (success, msg, error) -> { assertThat(success).isFalse(); assertThat(error).isNotNull(); }); assertConnectorNotRunning(); }
@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(); } }
@Test public void cannotInsertSameEntityTwice() throws Exception { em.getTransaction().begin(); // given MakeupArtist wibke = new MakeupArtist( "wibke", "halloween" ); em.persist( wibke ); em.getTransaction().commit(); em.clear(); em.getTransaction().begin(); // when MakeupArtist notWibke = new MakeupArtist( "wibke", "glamorous" ); em.persist( notWibke ); try { em.getTransaction().commit(); fail( "Expected exception wasn't raised" ); } catch ( Exception e ) { // then assertThat( e.getCause() ).isExactlyInstanceOf( PersistenceException.class ); assertThat( e.getCause().getMessage() ).matches( ".*OGM000067.*" ); } em.clear(); em.getTransaction().begin(); MakeupArtist loadedMakeupArtist = em.find( MakeupArtist.class, "wibke" ); assertThat( loadedMakeupArtist ).isNotNull(); assertThat( loadedMakeupArtist.getFavoriteStyle() ).describedAs( "Second insert should not be applied" ) .isEqualTo( "halloween" ); em.remove( loadedMakeupArtist ); em.getTransaction().commit(); }
assertThat( invocation.getException() ).isExactlyInstanceOf( TupleAlreadyExistsException.class );
/** * Verifies that the connector doesn't run with an invalid configuration. This does not actually connect to the MySQL server. */ @Test public void shouldNotStartWithInvalidConfiguration() { config = Configuration.create() .with(MongoDbConnectorConfig.AUTO_DISCOVER_MEMBERS, "true") .build(); // we expect the engine will log at least one error, so preface it ... logger.info("Attempting to start the connector with an INVALID configuration, so MULTIPLE error messages & one exceptions will appear in the log"); start(MongoDbConnector.class, config, (success, msg, error) -> { assertThat(success).isFalse(); assertThat(error).isNotNull(); }); assertConnectorNotRunning(); }
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(); } } } }
/** * Verifies that the connector doesn't run with an invalid configuration. This does not actually connect to the MySQL server. */ @Test public void shouldNotStartWithInvalidConfiguration() { config = Configuration.create() .with(MySqlConnectorConfig.SERVER_NAME, "myserver") .with(KafkaDatabaseHistory.TOPIC, "myserver") .with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class) .with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH) .build(); // we expect the engine will log at least one error, so preface it ... logger.info("Attempting to start the connector with an INVALID configuration, so MULTIPLE error messages and exceptions will appear in the log"); start(MySqlConnector.class, config, (success, msg, error) -> { assertThat(success).isFalse(); assertThat(error).isNotNull(); }); assertConnectorNotRunning(); }
@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(); } }
@Test public void shouldThrowWhenMerchantNotFound() { when(merchantRepository.findByNumber(merchantNumber)).thenThrow(new NotFoundException()); //catchException(bookKeeper, NotFoundException.class).registerPaybackFor(...); assertThat(caughtException()).isNotNull(); }
@Test public void shouldThrowWhenAccountNotFound() { when(accountRepository.findByCreditCard(creditCardNumber)).thenThrow(new NotFoundException()); //catchException(bookKeeper, NotFoundException.class).registerPaybackFor(...); assertThat(caughtException()).isNotNull(); }
@Test public void shouldThrowWhenAccountNotFound() { when(accountRepository.findByCreditCard(creditCardNumber)).thenThrow(new NotFoundException()); catchException(bookKeeper, NotFoundException.class).registerPaybackFor(purchase); assertThat(caughtException()).isNotNull(); }
@Test public void shouldThrowWhenMerchantNotFound() { when(merchantRepository.findByNumber(merchantNumber)).thenThrow(new NotFoundException()); catchException(bookKeeper, NotFoundException.class).registerPaybackFor(purchase); assertThat(caughtException()).isNotNull(); }
@Test public void shouldThrowWhenAccountNotFound() { Purchase purchase = new Purchase(Money.of(EUR, 100L), "4321432143214321", merchantNumber, now()); catchException(bookKeeper, EmptyResultDataAccessException.class).registerPaybackFor(purchase); assertThat(caughtException()).isNotNull(); }
@Test public void shouldThrowWhenMerchantNotFound() { Purchase purchase = new Purchase(Money.of(EUR, 100L), creditCardNumber, "1111111111", now()); catchException(bookKeeper, EmptyResultDataAccessException.class).registerPaybackFor(purchase); assertThat(caughtException()).isNotNull(); }
@Test public void shouldThrowWhenMerchantNotFound() { purchase = new Purchase(Money.of(EUR, 100L), creditCardNumber, "1111111111", now()); catchException(bookKeeper, EmptyResultDataAccessException.class).registerPaybackFor(purchase); assertThat(caughtException()).isNotNull(); }
@Test public void shouldThrowWhenMerchantNotFound() { catchException(repository, EmptyResultDataAccessException.class).findByNumber("111111111"); assertThat(caughtException()).isNotNull(); }
@Test public void shouldThrowWhenAccountNotFound() { Purchase purchase = new Purchase(Money.of(EUR, 100L), "4321432143214321", merchantNumber, now()); catchException(bookKeeper, EmptyResultDataAccessException.class).registerPaybackFor(purchase); assertThat(caughtException()).isNotNull(); }
@Test public void shouldThrowWhenAccountNotFound() { purchase = new Purchase(Money.of(EUR, 100L), "4321432143214321", merchantNumber, now()); catchException(bookKeeper, EmptyResultDataAccessException.class).registerPaybackFor(purchase); assertThat(caughtException()).isNotNull(); }
@Test public void shouldThrowWhenMerchantNotFound() { purchase = new Purchase(Money.of(EUR, 100L), creditCardNumber, "1111111111", now()); catchException(bookKeeper, EmptyResultDataAccessException.class).registerPaybackFor(purchase); assertThat(caughtException()).isNotNull(); }
@Test public void shouldThrowWhenMerchantNotFound() { Purchase purchase = new Purchase(Money.of(EUR, 100L), creditCardNumber, "1111111111", now()); catchException(bookKeeper, EmptyResultDataAccessException.class).registerPaybackFor(purchase); assertThat(caughtException()).isNotNull(); }