Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <jdbc:embedded-database id="dataSource">
- <jdbc:script location="classpath:schema.sql"/>
- <jdbc:script location="classpath:test-data.sql"/>
- </jdbc:embedded-database>
- @Service
- public class DbCleanup {
- @Resource
- private DataSource ds;
- @PreDestroy
- public cleanUpDb() {
- //do your cleanup with DB
- }
- }
- package com.obecto.fixtures;
- public interface Fixture {
- void prepare();
- }
- package com.avaco2.fixtures;
- import java.util.logging.Logger;
- import org.apache.commons.dbcp.BasicDataSource;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.core.io.ClassPathResource;
- import org.springframework.core.io.Resource;
- import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
- import org.springframework.stereotype.Component;
- import org.springframework.test.jdbc.SimpleJdbcTestUtils;
- import com.obecto.fixtures.Fixture;
- @Component(value="logEventsSQLFixture")
- public class LogEventsSQLFixture implements Fixture {
- private static String IMPORT_SQL = "import-LogEvents.sql";
- private static Logger LOG = Logger.getLogger(LogEventsSQLFixture.class.getName());
- @Autowired
- private BasicDataSource dataSource;
- @Override
- public void prepare() {
- SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);
- Resource sqlScript = new ClassPathResource(IMPORT_SQL);
- try {
- SimpleJdbcTestUtils.executeSqlScript(jdbcTemplate, sqlScript, true);
- } catch (Exception e) {
- LOG.severe("Cannot import " + IMPORT_SQL);
- }
- }
- }
Add Comment
Please, Sign In to add comment