Reproduce claims raised in SPR-8849
This commit introduces a test suite (Spr8849Tests) that demonstrates
the claims made in SPR-8849.
Specifically, if <jdbc:embedded-database id="xyz" /> is used to create
an embedded HSQL database in an XML configuration file and that
configuration file is imported in different sets of configuration files
that are used to load ApplicationContexts for different integration
tests, the embedded database will be initialized multiple times using
any nested <jdbc:script /> elements. If such a script is used to create
a table, for example, subsequent attempts to initialize the database
named "xyz" will fail since an embedded database named "xyz" already
exists in the JVM.
As a work-around, this test suite uses a SpEL expression to generate a
random string for each embedded database instance:
id="#{T(java.util.UUID).randomUUID().toString()}"
See the Javadoc in Spr8849Tests for further information.
Issue: SPR-8849
This commit is contained in:
parent
67d5a1238f
commit
04a6827290
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.test.context.junit4.spr8849;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
/**
|
||||
* Test suite to investigate claims raised in
|
||||
* <a href="https://jira.springsource.org/browse/SPR-8849">SPR-8849</a>.
|
||||
*
|
||||
* <p>By using a SpEL expression to generate a random {@code id} for the
|
||||
* embedded database (see {@code datasource-config.xml}), we ensure that each
|
||||
* {@code ApplicationContext} that imports the common configuration will create
|
||||
* an embedded database with a unique name (since the {@code id} is used as the
|
||||
* database name within
|
||||
* {@link org.springframework.jdbc.config.EmbeddedDatabaseBeanDefinitionParser#useIdAsDatabaseNameIfGiven()}).
|
||||
*
|
||||
* <p>To reproduce the problem mentioned in SPEX-8849, change the {@code id} of
|
||||
* the embedded database in {@code datasource-config.xml} to "dataSource" (or
|
||||
* anything else that is not random) and run this <em>suite</em>.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 3.2
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({ TestClass1.class, TestClass2.class })
|
||||
public class Spr8849Tests {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
||||
|
||||
<import resource="datasource-config.xml"/>
|
||||
|
||||
</beans>
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.test.context.junit4.spr8849;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* This name of this class intentionally does not end with "Test" or "Tests"
|
||||
* since it should only be run as part of the test suite: {@link Spr8849Tests}.
|
||||
*
|
||||
* @author Mickael Leduque
|
||||
* @author Sam Brannen
|
||||
* @since 3.2
|
||||
* @see Spr8849Tests
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class TestClass1 {
|
||||
|
||||
@Autowired
|
||||
DataSource datasource;
|
||||
|
||||
|
||||
@Test
|
||||
public void dummyTest() {
|
||||
// it's sufficient if the ApplicationContext loads without errors.
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
||||
|
||||
<import resource="datasource-config.xml"/>
|
||||
|
||||
</beans>
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.test.context.junit4.spr8849;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* This name of this class intentionally does not end with "Test" or "Tests"
|
||||
* since it should only be run as part of the test suite: {@link Spr8849Tests}.
|
||||
*
|
||||
* @author Mickael Leduque
|
||||
* @author Sam Brannen
|
||||
* @since 3.2
|
||||
* @see Spr8849Tests
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class TestClass2 {
|
||||
|
||||
@Autowired
|
||||
DataSource dataSource;
|
||||
|
||||
|
||||
@Test
|
||||
public void dummyTest() {
|
||||
// it's sufficient if the ApplicationContext loads without errors.
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd">
|
||||
|
||||
<jdbc:embedded-database id="#{T(java.util.UUID).randomUUID().toString()}">
|
||||
<jdbc:script location="classpath:/org/springframework/test/context/junit4/spr8849/spr8849-schema.sql" />
|
||||
</jdbc:embedded-database>
|
||||
|
||||
</beans>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
CREATE TABLE enigma (
|
||||
id INTEGER NOT NULL IDENTITY PRIMARY KEY
|
||||
);
|
||||
Loading…
Reference in New Issue