diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/Spr8849Tests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/Spr8849Tests.java new file mode 100644 index 00000000000..fa0412abc1b --- /dev/null +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/Spr8849Tests.java @@ -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 + * SPR-8849. + * + *

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()}). + * + *

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 suite. + * + * @author Sam Brannen + * @since 3.2 + */ +@RunWith(Suite.class) +@SuiteClasses({ TestClass1.class, TestClass2.class }) +public class Spr8849Tests { + +} diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass1-context.xml b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass1-context.xml new file mode 100644 index 00000000000..63314700662 --- /dev/null +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass1-context.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass1.java b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass1.java new file mode 100644 index 00000000000..b45b6d76a71 --- /dev/null +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass1.java @@ -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. + } + +} \ No newline at end of file diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass2-context.xml b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass2-context.xml new file mode 100644 index 00000000000..63314700662 --- /dev/null +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass2-context.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass2.java b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass2.java new file mode 100644 index 00000000000..bc8a7800549 --- /dev/null +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/TestClass2.java @@ -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. + } + +} \ No newline at end of file diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/datasource-config.xml b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/datasource-config.xml new file mode 100644 index 00000000000..ed82b6f301b --- /dev/null +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/datasource-config.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/spr8849-schema.sql b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/spr8849-schema.sql new file mode 100644 index 00000000000..a17d13a9d92 --- /dev/null +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/spr8849-schema.sql @@ -0,0 +1,3 @@ +CREATE TABLE enigma ( + id INTEGER NOT NULL IDENTITY PRIMARY KEY +);