Loader { public Loader(DbaConfiguration configuration) throws Exception { this.configuration = configuration; } Loader(DbaConfiguration configuration); void bootstrap(); void clear(); void prepareDb(); void rollback(); Loader createDatabase(); void dropDatabase(); void execute(); static final String INITIAL_DATABASE_CREATE_TEMPLATE; static final String MODEL_COM_CHIRALBEHAVIORS_CORE_SCHEMA_CORE_XML; }
@Test public void testLoader() throws Exception { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); DbaConfiguration config = mapper.readValue(getClass().getResourceAsStream("/loader.yml"), DbaConfiguration.class); try (Connection dbaConnection = config.getDbaConnection()) { dbaConnection.setAutoCommit(true); dbaConnection.prepareStatement("DROP DATABASE IF EXISTS testme") .execute(); dbaConnection.prepareStatement("DROP ROLE IF EXISTS scott") .execute(); } config.dropDatabase = true; Loader loader = new Loader(config); try { loader.execute(); loader.execute(); loader.clear(); loader.rollback(); } finally { loader.dropDatabase(); } }