ProductionLiquibaseRunner implements PreHook { @Override public void prepare(DataSource datasource) throws SQLException { try(Connection connect = datasource.getConnection()) { UkelonnLiquibase liquibase = createUkelonnLiquibase(); try { liquibase.createInitialSchema(connect); insertInitialDataInDatabase(datasource); liquibase.updateSchema(connect); } finally { connect.setAutoCommit(true); } } catch (Exception e) { logService.log(LogService.LOG_ERROR, "Failed to create ukelonn database schema in the PostgreSQL ukelonn database", e); } }  @Reference void setLogService(LogService logService); @Activate void activate(); @Override void prepare(DataSource datasource);  }
@Test public void testPrepare() throws Exception { ProductionLiquibaseRunner runner = new ProductionLiquibaseRunner(); UkelonnLiquibase ukelonnLiquibase = mock(UkelonnLiquibase.class); UkelonnLiquibaseFactory ukelonnLiquibaseFactory = mock(UkelonnLiquibaseFactory.class); when(ukelonnLiquibaseFactory.create()).thenReturn(ukelonnLiquibase); runner.setUkelonnLiquibaseFactory(ukelonnLiquibaseFactory); Liquibase liquibase = mock(Liquibase.class); LiquibaseFactory liquibaseFactory = mock(LiquibaseFactory.class); when(liquibaseFactory.create(anyString(), any(), any())).thenReturn(liquibase); runner.setLiquibaseFactory(liquibaseFactory); MockLogService logservice = new MockLogService(); DataSource datasource = mock(DataSource.class); Connection connection = mock(Connection.class); when(datasource.getConnection()).thenReturn(connection); runner.setLogService(logservice); runner.activate(); runner.prepare(datasource); assertEquals(0, logservice.getLogmessagecount()); }