Browse Source

fixing broken unit test related to SPR-5429

pull/23217/head
Scott Andrews 17 years ago
parent
commit
7dcb3b5841
  1. 18
      org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/config/DbcpDataSourceFactory.java
  2. 7
      org.springframework.samples.petclinic/src/main/resources/META-INF/hsqldb/dropTables.txt
  3. 2
      org.springframework.samples.petclinic/src/main/resources/jdbc.properties
  4. 10
      org.springframework.samples.petclinic/src/test/resources/org/springframework/samples/petclinic/AbstractClinicTests-context.xml
  5. 10
      org.springframework.samples.petclinic/src/test/resources/org/springframework/samples/petclinic/jpa/applicationContext-jpaCommon.xml

18
org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/config/DbcpDataSourceFactory.java

@ -62,6 +62,8 @@ public class DbcpDataSourceFactory implements FactoryBean<DataSource>, Disposabl @@ -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 @@ -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 @@ -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);
}

7
org.springframework.samples.petclinic/src/main/resources/META-INF/hsqldb/dropTables.txt

@ -0,0 +1,7 @@ @@ -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;

2
org.springframework.samples.petclinic/src/main/resources/jdbc.properties

@ -25,6 +25,7 @@ jdbc.password= @@ -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 @@ -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")

10
org.springframework.samples.petclinic/src/test/resources/org/springframework/samples/petclinic/AbstractClinicTests-context.xml

@ -13,8 +13,10 @@ @@ -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>

10
org.springframework.samples.petclinic/src/test/resources/org/springframework/samples/petclinic/jpa/applicationContext-jpaCommon.xml

@ -11,10 +11,12 @@ @@ -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…
Cancel
Save