Search in sources :

Example 31 with MergedContextConfiguration

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

the class DefaultContextCache method remove.

private void remove(List<MergedContextConfiguration> removedContexts, MergedContextConfiguration key) {
    Assert.notNull(key, "Key must not be null");
    Set<MergedContextConfiguration> children = this.hierarchyMap.get(key);
    if (children != null) {
        for (MergedContextConfiguration child : children) {
            // Recurse through lower levels
            remove(removedContexts, child);
        }
        // Remove the set of children for the current context from the hierarchy map.
        this.hierarchyMap.remove(key);
    }
    // Physically remove and close leaf nodes first (i.e., on the way back up the
    // stack as opposed to prior to the recursive call).
    ApplicationContext context = this.contextMap.remove(key);
    if (context instanceof ConfigurableApplicationContext) {
        ((ConfigurableApplicationContext) context).close();
    }
    removedContexts.add(key);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) MergedContextConfiguration(org.springframework.test.context.MergedContextConfiguration)

Example 32 with MergedContextConfiguration

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

the class DefaultContextCache method remove.

/**
	 * {@inheritDoc}
	 */
@Override
public void remove(MergedContextConfiguration key, HierarchyMode hierarchyMode) {
    Assert.notNull(key, "Key must not be null");
    // startKey is the level at which to begin clearing the cache, depending
    // on the configured hierarchy mode.
    MergedContextConfiguration startKey = key;
    if (hierarchyMode == HierarchyMode.EXHAUSTIVE) {
        while (startKey.getParent() != null) {
            startKey = startKey.getParent();
        }
    }
    List<MergedContextConfiguration> removedContexts = new ArrayList<>();
    remove(removedContexts, startKey);
    // hierarchy map.
    for (MergedContextConfiguration currentKey : removedContexts) {
        for (Set<MergedContextConfiguration> children : this.hierarchyMap.values()) {
            children.remove(currentKey);
        }
    }
    // Remove empty entries from the hierarchy map.
    for (MergedContextConfiguration currentKey : this.hierarchyMap.keySet()) {
        if (this.hierarchyMap.get(currentKey).isEmpty()) {
            this.hierarchyMap.remove(currentKey);
        }
    }
}
Also used : MergedContextConfiguration(org.springframework.test.context.MergedContextConfiguration) ArrayList(java.util.ArrayList)

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