Skip to content

Commit 7dcb3b5

Browse files
committed
fixing broken unit test related to SPR-5429
1 parent 300e4d7 commit 7dcb3b5

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

Diff for: org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/config/DbcpDataSourceFactory.java

+18
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public class DbcpDataSourceFactory implements FactoryBean<DataSource>, Disposabl
6262

6363
private Resource dataLocation;
6464

65+
private Resource dropLocation;
66+
6567
/**
6668
* The object created by this factory.
6769
*/
@@ -115,6 +117,14 @@ public void setDataLocation(Resource testDataLocation) {
115117
this.dataLocation = testDataLocation;
116118
}
117119

120+
/**
121+
* Sets the location of the file containing the drop scripts for the database.
122+
* @param testDataLocation the location of the data file
123+
*/
124+
public void setDropLocation(Resource testDropLocation) {
125+
this.dropLocation = testDropLocation;
126+
}
127+
118128
// implementing FactoryBean
119129

120130
// this method is called by Spring to expose the DataSource as a bean
@@ -163,6 +173,14 @@ private BasicDataSource createDataSource() {
163173

164174
private void populateDataSource() {
165175
DatabasePopulator populator = new DatabasePopulator(dataSource);
176+
if (dropLocation != null) {
177+
try {
178+
populator.populate(this.dropLocation);
179+
}
180+
catch (Exception e) {
181+
// ignore
182+
}
183+
}
166184
populator.populate(this.schemaLocation);
167185
populator.populate(this.dataLocation);
168186
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
DROP TABLE visits;
2+
DROP TABLE pets;
3+
DROP TABLE owners;
4+
DROP TABLE types;
5+
DROP TABLE vet_specialties;
6+
DROP TABLE specialties;
7+
DROP TABLE vets;

Diff for: org.springframework.samples.petclinic/src/main/resources/jdbc.properties

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jdbc.password=
2525
jdbc.populate=true
2626
jdbc.schemaLocation=classpath:/META-INF/hsqldb/initDB.txt
2727
jdbc.dataLocation=classpath:/META-INF/hsqldb/populateDB.txt
28+
jdbc.dropLocation=classpath:/META-INF/hsqldb/dropTables.txt
2829

2930
# Property that determines which Hibernate dialect to use
3031
# (only applied with "applicationContext-hibernate.xml")
@@ -49,6 +50,7 @@ jpa.database=HSQL
4950
#jdbc.populate=false
5051
#jdbc.schemaLocation=
5152
#jdbc.dataLocation=
53+
#jdbc.dropLocation=
5254

5355
# Property that determines which Hibernate dialect to use
5456
# (only applied with "applicationContext-hibernate.xml")

Diff for: org.springframework.samples.petclinic/src/test/resources/org/springframework/samples/petclinic/AbstractClinicTests-context.xml

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
<tx:annotation-driven/>
1515

16-
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
17-
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
18-
p:username="${jdbc.username}" p:password="${jdbc.password}" />
19-
16+
<bean id="dataSource" class="org.springframework.samples.petclinic.config.DbcpDataSourceFactory"
17+
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
18+
p:username="${jdbc.username}" p:password="${jdbc.password}" p:populate="${jdbc.populate}"
19+
p:schemaLocation="${jdbc.schemaLocation}" p:dataLocation="${jdbc.dataLocation}"
20+
p:dropLocation="${jdbc.dropLocation}"/>
21+
2022
</beans>

Diff for: org.springframework.samples.petclinic/src/test/resources/org/springframework/samples/petclinic/jpa/applicationContext-jpaCommon.xml

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
<tx:annotation-driven />
1313

14-
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
15-
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" p:username="${jdbc.username}"
16-
p:password="${jdbc.password}" />
17-
14+
<bean id="dataSource" class="org.springframework.samples.petclinic.config.DbcpDataSourceFactory"
15+
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
16+
p:username="${jdbc.username}" p:password="${jdbc.password}" p:populate="${jdbc.populate}"
17+
p:schemaLocation="${jdbc.schemaLocation}" p:dataLocation="${jdbc.dataLocation}"
18+
p:dropLocation="${jdbc.dropLocation}"/>
19+
1820
<!-- Note: the specific "jpaAdapter" bean sits in adapter context file -->
1921
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
2022
p:dataSource-ref="dataSource" p:jpaVendorAdapter-ref="jpaAdapter">

0 commit comments

Comments
 (0)