parent
c88877f1c4
commit
b057e503ef
|
|
@ -51,15 +51,16 @@ import static org.junit.Assert.*;
|
|||
abstract class AbstractContextConfigurationUtilsTests {
|
||||
|
||||
static final Class<?>[] EMPTY_CLASS_ARRAY = new Class<?>[0];
|
||||
|
||||
static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
static final Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> EMPTY_INITIALIZER_CLASSES = //
|
||||
Collections.<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> emptySet();
|
||||
|
||||
static final Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>>
|
||||
EMPTY_INITIALIZER_CLASSES = Collections.<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> emptySet();
|
||||
|
||||
|
||||
MergedContextConfiguration buildMergedContextConfiguration(Class<?> testClass) {
|
||||
CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate = Mockito.mock(CacheAwareContextLoaderDelegate.class);
|
||||
BootstrapContext bootstrapContext = BootstrapTestUtils.buildBootstrapContext(testClass,
|
||||
cacheAwareContextLoaderDelegate);
|
||||
BootstrapContext bootstrapContext = BootstrapTestUtils.buildBootstrapContext(testClass, cacheAwareContextLoaderDelegate);
|
||||
TestContextBootstrapper bootstrapper = BootstrapTestUtils.resolveTestContextBootstrapper(bootstrapContext);
|
||||
return bootstrapper.buildMergedContextConfiguration();
|
||||
}
|
||||
|
|
@ -67,6 +68,7 @@ abstract class AbstractContextConfigurationUtilsTests {
|
|||
void assertAttributes(ContextConfigurationAttributes attributes, Class<?> expectedDeclaringClass,
|
||||
String[] expectedLocations, Class<?>[] expectedClasses,
|
||||
Class<? extends ContextLoader> expectedContextLoaderClass, boolean expectedInheritLocations) {
|
||||
|
||||
assertEquals("declaring class", expectedDeclaringClass, attributes.getDeclaringClass());
|
||||
assertArrayEquals("locations", expectedLocations, attributes.getLocations());
|
||||
assertArrayEquals("classes", expectedClasses, attributes.getClasses());
|
||||
|
|
@ -77,8 +79,9 @@ abstract class AbstractContextConfigurationUtilsTests {
|
|||
void assertMergedConfig(MergedContextConfiguration mergedConfig, Class<?> expectedTestClass,
|
||||
String[] expectedLocations, Class<?>[] expectedClasses,
|
||||
Class<? extends ContextLoader> expectedContextLoaderClass) {
|
||||
|
||||
assertMergedConfig(mergedConfig, expectedTestClass, expectedLocations, expectedClasses,
|
||||
EMPTY_INITIALIZER_CLASSES, expectedContextLoaderClass);
|
||||
EMPTY_INITIALIZER_CLASSES, expectedContextLoaderClass);
|
||||
}
|
||||
|
||||
void assertMergedConfig(
|
||||
|
|
@ -88,6 +91,7 @@ abstract class AbstractContextConfigurationUtilsTests {
|
|||
Class<?>[] expectedClasses,
|
||||
Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> expectedInitializerClasses,
|
||||
Class<? extends ContextLoader> expectedContextLoaderClass) {
|
||||
|
||||
assertNotNull(mergedConfig);
|
||||
assertEquals(expectedTestClass, mergedConfig.getTestClass());
|
||||
assertNotNull(mergedConfig.getLocations());
|
||||
|
|
@ -159,7 +163,7 @@ abstract class AbstractContextConfigurationUtilsTests {
|
|||
static class MetaLocationsFooWithOverrides {
|
||||
}
|
||||
|
||||
@MetaLocationsFooConfigWithOverrides(locations = { "foo1.xml", "foo2.xml" }, profiles = { "foo1", "foo2" })
|
||||
@MetaLocationsFooConfigWithOverrides(locations = {"foo1.xml", "foo2.xml"}, profiles = {"foo1", "foo2"})
|
||||
static class MetaLocationsFooWithOverriddenAttributes {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,22 +45,22 @@ public class ContextLoaderUtilsConfigurationAttributesTests extends AbstractCont
|
|||
|
||||
private void assertLocationsFooAttributes(ContextConfigurationAttributes attributes) {
|
||||
assertAttributes(attributes, LocationsFoo.class, new String[] { "/foo.xml" }, EMPTY_CLASS_ARRAY,
|
||||
ContextLoader.class, false);
|
||||
ContextLoader.class, false);
|
||||
}
|
||||
|
||||
private void assertClassesFooAttributes(ContextConfigurationAttributes attributes) {
|
||||
assertAttributes(attributes, ClassesFoo.class, EMPTY_STRING_ARRAY, new Class<?>[] { FooConfig.class },
|
||||
ContextLoader.class, false);
|
||||
assertAttributes(attributes, ClassesFoo.class, EMPTY_STRING_ARRAY, new Class<?>[] {FooConfig.class},
|
||||
ContextLoader.class, false);
|
||||
}
|
||||
|
||||
private void assertLocationsBarAttributes(ContextConfigurationAttributes attributes) {
|
||||
assertAttributes(attributes, LocationsBar.class, new String[] { "/bar.xml" }, EMPTY_CLASS_ARRAY,
|
||||
AnnotationConfigContextLoader.class, true);
|
||||
assertAttributes(attributes, LocationsBar.class, new String[] {"/bar.xml"}, EMPTY_CLASS_ARRAY,
|
||||
AnnotationConfigContextLoader.class, true);
|
||||
}
|
||||
|
||||
private void assertClassesBarAttributes(ContextConfigurationAttributes attributes) {
|
||||
assertAttributes(attributes, ClassesBar.class, EMPTY_STRING_ARRAY, new Class<?>[] { BarConfig.class },
|
||||
AnnotationConfigContextLoader.class, true);
|
||||
assertAttributes(attributes, ClassesBar.class, EMPTY_STRING_ARRAY, new Class<?>[] {BarConfig.class},
|
||||
AnnotationConfigContextLoader.class, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -68,12 +68,12 @@ public class ContextLoaderUtilsConfigurationAttributesTests extends AbstractCont
|
|||
exception.expect(AnnotationConfigurationException.class);
|
||||
exception.expectMessage(containsString(ConflictingLocations.class.getName()));
|
||||
exception.expectMessage(either(
|
||||
containsString("attribute [value] and its alias [locations]")).or(
|
||||
containsString("attribute [locations] and its alias [value]")));
|
||||
containsString("attribute 'value' and its alias 'locations'")).or(
|
||||
containsString("attribute 'locations' and its alias 'value'")));
|
||||
exception.expectMessage(either(
|
||||
containsString("values of [{x}] and [{y}]")).or(
|
||||
containsString("values of [{y}] and [{x}]")));
|
||||
exception.expectMessage(containsString("but only one declaration is permitted"));
|
||||
exception.expectMessage(containsString("but only one is permitted"));
|
||||
resolveContextConfigurationAttributes(ConflictingLocations.class);
|
||||
}
|
||||
|
||||
|
|
@ -83,8 +83,8 @@ public class ContextLoaderUtilsConfigurationAttributesTests extends AbstractCont
|
|||
List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(testClass);
|
||||
assertNotNull(attributesList);
|
||||
assertEquals(1, attributesList.size());
|
||||
assertAttributes(attributesList.get(0), testClass, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, ContextLoader.class,
|
||||
true);
|
||||
assertAttributes(attributesList.get(0),
|
||||
testClass, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, ContextLoader.class, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -101,8 +101,8 @@ public class ContextLoaderUtilsConfigurationAttributesTests extends AbstractCont
|
|||
List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(testClass);
|
||||
assertNotNull(attributesList);
|
||||
assertEquals(1, attributesList.size());
|
||||
assertAttributes(attributesList.get(0), testClass, new String[] { "/foo.xml" }, EMPTY_CLASS_ARRAY,
|
||||
ContextLoader.class, true);
|
||||
assertAttributes(attributesList.get(0),
|
||||
testClass, new String[] {"/foo.xml"}, EMPTY_CLASS_ARRAY, ContextLoader.class, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -111,8 +111,8 @@ public class ContextLoaderUtilsConfigurationAttributesTests extends AbstractCont
|
|||
List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(testClass);
|
||||
assertNotNull(attributesList);
|
||||
assertEquals(1, attributesList.size());
|
||||
assertAttributes(attributesList.get(0), testClass, new String[] { "/foo.xml" }, EMPTY_CLASS_ARRAY,
|
||||
ContextLoader.class, true);
|
||||
assertAttributes(attributesList.get(0),
|
||||
testClass, new String[] {"/foo.xml"}, EMPTY_CLASS_ARRAY, ContextLoader.class, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -121,8 +121,8 @@ public class ContextLoaderUtilsConfigurationAttributesTests extends AbstractCont
|
|||
List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(testClass);
|
||||
assertNotNull(attributesList);
|
||||
assertEquals(1, attributesList.size());
|
||||
assertAttributes(attributesList.get(0), testClass, new String[] { "foo1.xml", "foo2.xml" }, EMPTY_CLASS_ARRAY,
|
||||
ContextLoader.class, true);
|
||||
assertAttributes(attributesList.get(0),
|
||||
testClass, new String[] {"foo1.xml", "foo2.xml"}, EMPTY_CLASS_ARRAY, ContextLoader.class, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -131,10 +131,10 @@ public class ContextLoaderUtilsConfigurationAttributesTests extends AbstractCont
|
|||
List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(testClass);
|
||||
assertNotNull(attributesList);
|
||||
assertEquals(2, attributesList.size());
|
||||
assertAttributes(attributesList.get(0), testClass, new String[] { "/bar.xml" }, EMPTY_CLASS_ARRAY,
|
||||
ContextLoader.class, true);
|
||||
assertAttributes(attributesList.get(1), MetaLocationsFoo.class, new String[] { "/foo.xml" },
|
||||
EMPTY_CLASS_ARRAY, ContextLoader.class, true);
|
||||
assertAttributes(attributesList.get(0),
|
||||
testClass, new String[] {"/bar.xml"}, EMPTY_CLASS_ARRAY, ContextLoader.class, true);
|
||||
assertAttributes(attributesList.get(1),
|
||||
MetaLocationsFoo.class, new String[] {"/foo.xml"}, EMPTY_CLASS_ARRAY, ContextLoader.class, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in New Issue