removed embedded databases factory in favor of new useDefaultScripts builder method
This commit is contained in:
parent
f1d012bffa
commit
2e4fa28ca6
|
|
@ -94,6 +94,17 @@ public class EmbeddedDatabaseBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add default scripts to execute to populate the database.
|
||||
* The default scripts are <code>schema.sql</code> to create the db schema and <code>data.sql</code> to populate the db with data.
|
||||
* @return this, for fluent call chaining
|
||||
*/
|
||||
public EmbeddedDatabaseBuilder addDefaultScripts() {
|
||||
addScript("schema.sql");
|
||||
addScript("data.sql");
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the embedded database.
|
||||
* @return the embedded database
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.jdbc.datasource.embedded;
|
||||
|
||||
import org.springframework.core.io.ClassRelativeResourceLoader;
|
||||
|
||||
/**
|
||||
* Convenience factory for constructing commonly used EmbeddedDatabase configurations.
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public final class EmbeddedDatabases {
|
||||
|
||||
private EmbeddedDatabases() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method that creates a default EmbeddedDatabase instance.
|
||||
* <p>The default instance is HQL populated with a schema loaded from <code>classpath:schema.sql</code> and data loaded from <code>classpath:data.sql</code>.
|
||||
* @return an embedded database
|
||||
*/
|
||||
public static EmbeddedDatabase createDefault() {
|
||||
return buildDefault(new EmbeddedDatabaseBuilder());
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method that creates a default HSQL EmbeddedDatabase instance.
|
||||
* <p>The default instance is HQL populated with a schema loaded from <code>schema.sql</code> and data loaded from <code>data.sql</code>, where
|
||||
* each .sql file location is relative to the specified class.
|
||||
* @param clazz the class to load .sql resources relative to
|
||||
* @return an embedded database
|
||||
*/
|
||||
public static EmbeddedDatabase createDefault(Class<?> clazz) {
|
||||
return buildDefault(new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(clazz)));
|
||||
}
|
||||
|
||||
// internal helpers
|
||||
|
||||
private static EmbeddedDatabase buildDefault(EmbeddedDatabaseBuilder builder) {
|
||||
return builder.addScript("schema.sql").addScript("data.sql").build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -12,6 +12,13 @@ import org.springframework.jdbc.datasource.init.CannotReadScriptException;
|
|||
|
||||
public class EmbeddedDatabaseBuilderTests {
|
||||
|
||||
@Test
|
||||
public void testBuildDefaultScripts() {
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
|
||||
EmbeddedDatabase db = builder.addDefaultScripts().build();
|
||||
assertDatabaseCreatedAndShutdown(db);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuild() {
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()));
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
package org.springframework.jdbc.datasource.embedded;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
public class EmbeddedDatabasesTests {
|
||||
|
||||
@Test
|
||||
public void testCreateDefault() {
|
||||
EmbeddedDatabase db = EmbeddedDatabases.createDefault();
|
||||
assertDatabaseCreatedAndShutdown(db);
|
||||
}
|
||||
|
||||
private void assertDatabaseCreatedAndShutdown(EmbeddedDatabase db) {
|
||||
JdbcTemplate template = new JdbcTemplate(db);
|
||||
assertEquals("Keith", template.queryForObject("select NAME from T_TEST", String.class));
|
||||
db.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue