fixing broken unit test related to SPR-5429
This commit is contained in:
parent
300e4d7284
commit
7dcb3b5841
|
@ -62,6 +62,8 @@ public class DbcpDataSourceFactory implements FactoryBean<DataSource>, Disposabl
|
|||
|
||||
private Resource dataLocation;
|
||||
|
||||
private Resource dropLocation;
|
||||
|
||||
/**
|
||||
* The object created by this factory.
|
||||
*/
|
||||
|
@ -115,6 +117,14 @@ public class DbcpDataSourceFactory implements FactoryBean<DataSource>, Disposabl
|
|||
this.dataLocation = testDataLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the location of the file containing the drop scripts for the database.
|
||||
* @param testDataLocation the location of the data file
|
||||
*/
|
||||
public void setDropLocation(Resource testDropLocation) {
|
||||
this.dropLocation = testDropLocation;
|
||||
}
|
||||
|
||||
// implementing FactoryBean
|
||||
|
||||
// this method is called by Spring to expose the DataSource as a bean
|
||||
|
@ -163,6 +173,14 @@ public class DbcpDataSourceFactory implements FactoryBean<DataSource>, Disposabl
|
|||
|
||||
private void populateDataSource() {
|
||||
DatabasePopulator populator = new DatabasePopulator(dataSource);
|
||||
if (dropLocation != null) {
|
||||
try {
|
||||
populator.populate(this.dropLocation);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
populator.populate(this.schemaLocation);
|
||||
populator.populate(this.dataLocation);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
DROP TABLE visits;
|
||||
DROP TABLE pets;
|
||||
DROP TABLE owners;
|
||||
DROP TABLE types;
|
||||
DROP TABLE vet_specialties;
|
||||
DROP TABLE specialties;
|
||||
DROP TABLE vets;
|
|
@ -25,6 +25,7 @@ jdbc.password=
|
|||
jdbc.populate=true
|
||||
jdbc.schemaLocation=classpath:/META-INF/hsqldb/initDB.txt
|
||||
jdbc.dataLocation=classpath:/META-INF/hsqldb/populateDB.txt
|
||||
jdbc.dropLocation=classpath:/META-INF/hsqldb/dropTables.txt
|
||||
|
||||
# Property that determines which Hibernate dialect to use
|
||||
# (only applied with "applicationContext-hibernate.xml")
|
||||
|
@ -49,6 +50,7 @@ jpa.database=HSQL
|
|||
#jdbc.populate=false
|
||||
#jdbc.schemaLocation=
|
||||
#jdbc.dataLocation=
|
||||
#jdbc.dropLocation=
|
||||
|
||||
# Property that determines which Hibernate dialect to use
|
||||
# (only applied with "applicationContext-hibernate.xml")
|
||||
|
|
|
@ -13,8 +13,10 @@
|
|||
|
||||
<tx:annotation-driven/>
|
||||
|
||||
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
|
||||
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
|
||||
p:username="${jdbc.username}" p:password="${jdbc.password}" />
|
||||
|
||||
<bean id="dataSource" class="org.springframework.samples.petclinic.config.DbcpDataSourceFactory"
|
||||
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
|
||||
p:username="${jdbc.username}" p:password="${jdbc.password}" p:populate="${jdbc.populate}"
|
||||
p:schemaLocation="${jdbc.schemaLocation}" p:dataLocation="${jdbc.dataLocation}"
|
||||
p:dropLocation="${jdbc.dropLocation}"/>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -11,10 +11,12 @@
|
|||
|
||||
<tx:annotation-driven />
|
||||
|
||||
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
|
||||
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" p:username="${jdbc.username}"
|
||||
p:password="${jdbc.password}" />
|
||||
|
||||
<bean id="dataSource" class="org.springframework.samples.petclinic.config.DbcpDataSourceFactory"
|
||||
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
|
||||
p:username="${jdbc.username}" p:password="${jdbc.password}" p:populate="${jdbc.populate}"
|
||||
p:schemaLocation="${jdbc.schemaLocation}" p:dataLocation="${jdbc.dataLocation}"
|
||||
p:dropLocation="${jdbc.dropLocation}"/>
|
||||
|
||||
<!-- Note: the specific "jpaAdapter" bean sits in adapter context file -->
|
||||
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
|
||||
p:dataSource-ref="dataSource" p:jpaVendorAdapter-ref="jpaAdapter">
|
||||
|
|
Loading…
Reference in New Issue