|
|
|
@ -13,21 +13,19 @@ |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* limitations under the License. |
|
|
|
* limitations under the License. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package org.springframework.context.annotation; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
package org.springframework.context.annotation; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; |
|
|
|
|
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
|
|
|
|
import org.springframework.context.annotation.ConfigurationClassParser; |
|
|
|
|
|
|
|
import org.springframework.context.annotation.Import; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; |
|
|
|
import org.springframework.tests.sample.beans.TestBean; |
|
|
|
import org.springframework.tests.sample.beans.TestBean; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* TCK-style unit tests for handling circular use of the {@link Import} annotation. Explore |
|
|
|
* TCK-style unit tests for handling circular use of the {@link Import} annotation. |
|
|
|
* subclass hierarchy for specific concrete implementations. |
|
|
|
* Explore the subclass hierarchy for specific concrete implementations. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Chris Beams |
|
|
|
* @author Chris Beams |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -37,23 +35,23 @@ public abstract class AbstractCircularImportDetectionTests { |
|
|
|
|
|
|
|
|
|
|
|
protected abstract String loadAsConfigurationSource(Class<?> clazz) throws Exception; |
|
|
|
protected abstract String loadAsConfigurationSource(Class<?> clazz) throws Exception; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void simpleCircularImportIsDetected() throws Exception { |
|
|
|
public void simpleCircularImportIsDetected() throws Exception { |
|
|
|
boolean threw = false; |
|
|
|
boolean threw = false; |
|
|
|
try { |
|
|
|
try { |
|
|
|
newParser().parse(loadAsConfigurationSource(A.class), "A"); |
|
|
|
newParser().parse(loadAsConfigurationSource(A.class), "A"); |
|
|
|
} catch (BeanDefinitionParsingException ex) { |
|
|
|
} |
|
|
|
|
|
|
|
catch (BeanDefinitionParsingException ex) { |
|
|
|
assertTrue("Wrong message. Got: " + ex.getMessage(), |
|
|
|
assertTrue("Wrong message. Got: " + ex.getMessage(), |
|
|
|
ex.getMessage().contains( |
|
|
|
ex.getMessage().contains( |
|
|
|
"Illegal attempt by @Configuration class 'AbstractCircularImportDetectionTests.B' " + |
|
|
|
"Illegal attempt by @Configuration class 'AbstractCircularImportDetectionTests.B' " + |
|
|
|
"to import class 'AbstractCircularImportDetectionTests.A'")); |
|
|
|
"to import class 'AbstractCircularImportDetectionTests.A'")); |
|
|
|
threw = true; |
|
|
|
threw = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertTrue(threw); |
|
|
|
assertTrue(threw); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void complexCircularImportIsDetected() throws Exception { |
|
|
|
public void complexCircularImportIsDetected() throws Exception { |
|
|
|
boolean threw = false; |
|
|
|
boolean threw = false; |
|
|
|
@ -67,10 +65,10 @@ public abstract class AbstractCircularImportDetectionTests { |
|
|
|
"to import class 'AbstractCircularImportDetectionTests.Z'")); |
|
|
|
"to import class 'AbstractCircularImportDetectionTests.Z'")); |
|
|
|
threw = true; |
|
|
|
threw = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assertTrue(threw); |
|
|
|
assertTrue(threw); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@Import(B.class) |
|
|
|
@Import(B.class) |
|
|
|
static class A { |
|
|
|
static class A { |
|
|
|
|