MysqlConfigurator { public void setup() { try ( Connection connection = connectionProvider.getConnection(); Statement stmt = connection.createStatement() ) { List<String> tableColumnNames = tableMetadata.getColumnNames(tableName); ReactiveTrigger insertTrigger = ReactiveTriggerFactory.afterInsert(tableName, tableColumnNames); ReactiveTrigger updateTrigger = ReactiveTriggerFactory.afterUpdate(tableName, tableColumnNames); ReactiveTrigger deleteTrigger = ReactiveTriggerFactory.afterDelete(tableName, tableColumnNames); stmt.execute(insertTrigger.getCreateSql()); stmt.execute(updateTrigger.getCreateSql()); stmt.execute(deleteTrigger.getCreateSql()); } catch (SQLException sqle) { throw new ConfigurationException("Couldn't configure table " + tableName + " as a reactive source", sqle); } } MysqlConfigurator(ConnectionProvider connectionProvider, String tableName); void setup(); void cleanup();  }
@Test(groups = INTEGRATION) public void testSetupCreatesInsertTrigger() throws SQLException { MysqlConfigurator configurator = new MysqlConfigurator(provider, TEST_TABLE_NAME); configurator.setup(); int initialEventsCount = getEventsCount(); insertToTestTable(1, "value"); assertEquals(getEventsCount(), initialEventsCount + 1); }
@Test(groups = INTEGRATION) public void testSetupCreatesUpdateTrigger() throws SQLException { MysqlConfigurator configurator = new MysqlConfigurator(provider, TEST_TABLE_NAME); insertToTestTable(1, "value"); configurator.setup(); int initialEventsCount = getEventsCount(); updateTestValue(1, "value2"); assertEquals(getEventsCount(), initialEventsCount + 1); }
@Test(groups = INTEGRATION) public void testSetupCreatesDeleteTrigger() throws SQLException { MysqlConfigurator configurator = new MysqlConfigurator(provider, TEST_TABLE_NAME); insertToTestTable(1, "value"); configurator.setup(); int initialEventsCount = getEventsCount(); deleteTestValue(1); assertEquals(getEventsCount(), initialEventsCount + 1); }
@Test(groups = SMALL, expectedExceptions = ConfigurationException.class) public void testThrowsConfigurationExceptionWhenSqlExceptionOccures() throws SQLException { ConnectionProvider mockedProvider = mock(ConnectionProvider.class); Connection mockedConnection = mock(Connection.class); when(mockedProvider.getConnection()).thenReturn(mockedConnection); when(mockedConnection.createStatement()).thenThrow(new SQLException()); MysqlConfigurator configurator = new MysqlConfigurator(mockedProvider, TEST_TABLE_NAME); configurator.setup(); }