@Test public void createSameSchemaTwiceWithoutUniqueDbNames() throws Exception { EmbeddedDatabase db1 = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()))// .addScripts("db-schema-without-dropping.sql").build(); try { new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()))// .addScripts("db-schema-without-dropping.sql").build(); fail("Should have thrown a ScriptStatementFailedException"); } catch (ScriptStatementFailedException e) { // expected } finally { db1.shutdown(); } }
@Test public void createSameSchemaTwiceWithGeneratedUniqueDbNames() throws Exception { EmbeddedDatabase db1 = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()))// .addScripts("db-schema-without-dropping.sql", "db-test-data.sql")// .generateUniqueName(true)// .build(); JdbcTemplate template1 = new JdbcTemplate(db1); assertNumRowsInTestTable(template1, 1); template1.update("insert into T_TEST (NAME) values ('Sam')"); assertNumRowsInTestTable(template1, 2); EmbeddedDatabase db2 = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()))// .addScripts("db-schema-without-dropping.sql", "db-test-data.sql")// .generateUniqueName(true)// .build(); assertDatabaseCreated(db2); db1.shutdown(); db2.shutdown(); }
public static Resource getResource(String sourcePath) { String pathToUse = StringUtils.cleanPath(sourcePath); if (pathToUse == null) { return null; } Resource resource = null; try { if (pathToUse.startsWith(org.springframework.core.io.ResourceLoader.CLASSPATH_URL_PREFIX)) { resource = new ClassRelativeResourceLoader(ResourceLoader.class).getResource(pathToUse); } if (resource == null) { resource = new FileSystemResourceLoader().getResource(pathToUse); } } catch (Exception e) { log.error("getResource error.", e); } return resource; }
@Test public void testBuildDerby() { Assume.group(TestGroup.LONG_RUNNING); EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass())); EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.DERBY).addScript("db-schema-derby.sql").addScript("db-test-data.sql").build(); assertDatabaseCreatedAndShutdown(db); }
@Test public void testBuild() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass())); EmbeddedDatabase db = builder.addScript("db-schema.sql").addScript("db-test-data.sql").build(); assertDatabaseCreatedAndShutdown(db); }
@Test public void testBuildWithComments() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass())); EmbeddedDatabase db = builder.addScript("db-schema-comments.sql").addScript("db-test-data.sql").build(); assertDatabaseCreatedAndShutdown(db); }
@Test public void testBuildH2() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass())); EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.H2).addScript("db-schema.sql").addScript("db-test-data.sql").build(); assertDatabaseCreatedAndShutdown(db); }