Search in sources :

Example 26 with MergedContextConfiguration

use of org.springframework.test.context.MergedContextConfiguration in project spring-framework by spring-projects.

the class BootstrapTestUtilsMergedConfigTests method buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndClasses.

@Test
public void buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndClasses() {
    Class<?> testClass = PropertiesClassesFoo.class;
    Class<? extends ContextLoader> expectedContextLoaderClass = GenericPropertiesContextLoader.class;
    MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass);
    assertMergedConfig(mergedConfig, testClass, EMPTY_STRING_ARRAY, new Class<?>[] { FooConfig.class }, expectedContextLoaderClass);
}
Also used : WebMergedContextConfiguration(org.springframework.test.context.web.WebMergedContextConfiguration) MergedContextConfiguration(org.springframework.test.context.MergedContextConfiguration) Test(org.junit.Test)

Example 27 with MergedContextConfiguration

use of org.springframework.test.context.MergedContextConfiguration in project spring-framework by spring-projects.

the class DelegatingSmartContextLoaderTests method loadContextWithoutLocationsAndConfigurationClasses.

@Test
public void loadContextWithoutLocationsAndConfigurationClasses() throws Exception {
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage(startsWith("Neither"));
    expectedException.expectMessage(containsString("was able to load an ApplicationContext from"));
    MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(), EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
    loader.loadContext(mergedConfig);
}
Also used : MergedContextConfiguration(org.springframework.test.context.MergedContextConfiguration) Test(org.junit.Test)

Example 28 with MergedContextConfiguration

use of org.springframework.test.context.MergedContextConfiguration in project spring-framework by spring-projects.

the class DelegatingSmartContextLoaderTests method loadContextWithXmlConfig.

@Test
public void loadContextWithXmlConfig() throws Exception {
    MergedContextConfiguration mergedConfig = new MergedContextConfiguration(XmlTestCase.class, new String[] { "classpath:/org/springframework/test/context/support/DelegatingSmartContextLoaderTests$XmlTestCase-context.xml" }, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, loader);
    assertApplicationContextLoadsAndContainsFooString(mergedConfig);
}
Also used : MergedContextConfiguration(org.springframework.test.context.MergedContextConfiguration) Test(org.junit.Test)

Example 29 with MergedContextConfiguration

use of org.springframework.test.context.MergedContextConfiguration in project spring-framework by spring-projects.

the class DelegatingSmartContextLoaderTests method loadContextWithLocationsAndConfigurationClasses.

/**
	 * @since 4.1
	 */
@Test
public void loadContextWithLocationsAndConfigurationClasses() throws Exception {
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage(startsWith("Neither"));
    expectedException.expectMessage(endsWith("declare either 'locations' or 'classes' but not both."));
    MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(), new String[] { "test.xml" }, new Class[] { getClass() }, EMPTY_STRING_ARRAY, loader);
    loader.loadContext(mergedConfig);
}
Also used : MergedContextConfiguration(org.springframework.test.context.MergedContextConfiguration) Test(org.junit.Test)

Example 30 with MergedContextConfiguration

use of org.springframework.test.context.MergedContextConfiguration in project spring-framework by spring-projects.

the class DefaultContextCache method put.

/**
	 * {@inheritDoc}
	 */
@Override
public void put(MergedContextConfiguration key, ApplicationContext context) {
    Assert.notNull(key, "Key must not be null");
    Assert.notNull(context, "ApplicationContext must not be null");
    this.contextMap.put(key, context);
    MergedContextConfiguration child = key;
    MergedContextConfiguration parent = child.getParent();
    while (parent != null) {
        Set<MergedContextConfiguration> list = this.hierarchyMap.get(parent);
        if (list == null) {
            list = new HashSet<>();
            this.hierarchyMap.put(parent, list);
        }
        list.add(child);
        child = parent;
        parent = child.getParent();
    }
}
Also used : MergedContextConfiguration(org.springframework.test.context.MergedContextConfiguration)

Aggregations

MergedContextConfiguration (org.springframework.test.context.MergedContextConfiguration)32 Test (org.junit.Test)25 WebMergedContextConfiguration (org.springframework.test.context.web.WebMergedContextConfiguration)13 ArrayList (java.util.ArrayList)3 ContextConfigurationAttributes (org.springframework.test.context.ContextConfigurationAttributes)2 List (java.util.List)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 CacheAwareContextLoaderDelegate (org.springframework.test.context.CacheAwareContextLoaderDelegate)1 ContextConfiguration (org.springframework.test.context.ContextConfiguration)1 ContextCustomizer (org.springframework.test.context.ContextCustomizer)1 ContextHierarchy (org.springframework.test.context.ContextHierarchy)1 ContextLoader (org.springframework.test.context.ContextLoader)1 SmartContextLoader (org.springframework.test.context.SmartContextLoader)1 TestContext (org.springframework.test.context.TestContext)1