|
|
|
@ -1,3 +1,19 @@ |
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
* Copyright 2002-2013 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; |
|
|
|
package org.springframework.jdbc.datasource.embedded; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
@ -10,16 +26,16 @@ import org.springframework.core.io.Resource; |
|
|
|
import org.springframework.jdbc.core.JdbcTemplate; |
|
|
|
import org.springframework.jdbc.core.JdbcTemplate; |
|
|
|
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; |
|
|
|
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @author Keith Donald |
|
|
|
|
|
|
|
*/ |
|
|
|
public class EmbeddedDatabaseFactoryBeanTests { |
|
|
|
public class EmbeddedDatabaseFactoryBeanTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testFactoryBeanLifecycle() throws Exception { |
|
|
|
public void testFactoryBeanLifecycle() throws Exception { |
|
|
|
EmbeddedDatabaseFactoryBean bean = new EmbeddedDatabaseFactoryBean(); |
|
|
|
EmbeddedDatabaseFactoryBean bean = new EmbeddedDatabaseFactoryBean(); |
|
|
|
ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); |
|
|
|
ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); |
|
|
|
populator.setScripts(new Resource[] { |
|
|
|
populator.setScripts(new ClassPathResource("db-schema.sql", getClass()), new ClassPathResource("db-test-data.sql", getClass())); |
|
|
|
new ClassPathResource("db-schema.sql", getClass()), |
|
|
|
|
|
|
|
new ClassPathResource("db-test-data.sql", getClass()) |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
bean.setDatabasePopulator(populator); |
|
|
|
bean.setDatabasePopulator(populator); |
|
|
|
bean.afterPropertiesSet(); |
|
|
|
bean.afterPropertiesSet(); |
|
|
|
DataSource ds = bean.getObject(); |
|
|
|
DataSource ds = bean.getObject(); |
|
|
|
@ -27,4 +43,5 @@ public class EmbeddedDatabaseFactoryBeanTests { |
|
|
|
assertEquals("Keith", template.queryForObject("select NAME from T_TEST", String.class)); |
|
|
|
assertEquals("Keith", template.queryForObject("select NAME from T_TEST", String.class)); |
|
|
|
bean.destroy(); |
|
|
|
bean.destroy(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|