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 index 122f1e22aca..efa9dd79423 100644 --- 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 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. @@ -24,16 +24,14 @@ 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()}). + *
By using a SpEL expression to generate a random {@code database-name} + * 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. * - *
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. + *
To reproduce the problem mentioned in SPR-8849, delete the declaration
+ * of the {@code database-name} attribute of the embedded database in
+ * {@code datasource-config.xml} and run this suite.
*
* @author Sam Brannen
* @since 3.2
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
index e723980a66e..e4bc06d3261 100644
--- 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
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2015 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.
@@ -16,15 +16,18 @@
package org.springframework.test.context.junit4.spr8849;
+import javax.annotation.Resource;
import javax.sql.DataSource;
import org.junit.Test;
import org.junit.runner.RunWith;
-
-import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.ImportResource;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import static org.junit.Assert.*;
+
/**
* 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}.
@@ -38,13 +41,19 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ContextConfiguration
public class TestClass1 {
- @Autowired
- DataSource datasource;
+ @Configuration
+ @ImportResource("classpath:/org/springframework/test/context/junit4/spr8849/datasource-config.xml")
+ static class Config {
+ }
+
+
+ @Resource
+ DataSource dataSource;
@Test
public void dummyTest() {
- // it's sufficient if the ApplicationContext loads without errors.
+ assertNotNull(dataSource);
}
}
\ No newline at end of file
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
index 86492855b2b..7c8fe5d59f2 100644
--- 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
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2015 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.
@@ -16,15 +16,18 @@
package org.springframework.test.context.junit4.spr8849;
+import javax.annotation.Resource;
import javax.sql.DataSource;
import org.junit.Test;
import org.junit.runner.RunWith;
-
-import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.ImportResource;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import static org.junit.Assert.*;
+
/**
* 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}.
@@ -38,13 +41,19 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ContextConfiguration
public class TestClass2 {
- @Autowired
+ @Configuration
+ @ImportResource("classpath:/org/springframework/test/context/junit4/spr8849/datasource-config.xml")
+ static class Config {
+ }
+
+
+ @Resource
DataSource dataSource;
@Test
public void dummyTest() {
- // it's sufficient if the ApplicationContext loads without errors.
+ assertNotNull(dataSource);
}
}
\ No newline at end of file
diff --git a/spring-test/src/test/resources/org/springframework/test/context/junit4/spr8849/TestClass1-context.xml b/spring-test/src/test/resources/org/springframework/test/context/junit4/spr8849/TestClass1-context.xml
deleted file mode 100644
index 63314700662..00000000000
--- a/spring-test/src/test/resources/org/springframework/test/context/junit4/spr8849/TestClass1-context.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-