-
-
Save ammachado/c564e2677a950b55b155eba4a8e85db6 to your computer and use it in GitHub Desktop.
java backup and restore of h2 for unit tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(SpringJUnit4ClassRunner.class) | |
@SpringApplicationConfiguration(classes = {SampleApplication.class}, name = "acceptanceTestContext") | |
@WebIntegrationTest | |
public abstract class AbstractAcceptanceTests { | |
@Autowired | |
protected JdbcTemplate jdbcTemplate; | |
/** | |
* Backs up the database before running this test. | |
*/ | |
@Before | |
public void setUpDatabase() { | |
//backup existing database | |
jdbcTemplate.execute("SCRIPT TO './build/tmp/h2-backup.sql'"); | |
} | |
/** | |
* Restores the database from the backup file. | |
*/ | |
@After | |
public void restoreDatabase() { | |
//restore backup from file. | |
jdbcTemplate.execute("DROP ALL OBJECTS"); | |
jdbcTemplate.execute("RUNSCRIPT FROM './build/tmp/h2-backup.sql'"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment