Search in sources :

Example 1 with MergedContextConfiguration

use of cn.taketoday.test.context.MergedContextConfiguration in project today-infrastructure by TAKETODAY.

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.computeIfAbsent(parent, k -> new HashSet<>());
        list.add(child);
        child = parent;
        parent = child.getParent();
    }
}
Also used : MergedContextConfiguration(cn.taketoday.test.context.MergedContextConfiguration)

Example 2 with MergedContextConfiguration

use of cn.taketoday.test.context.MergedContextConfiguration in project today-infrastructure by TAKETODAY.

the class DefaultContextCache method remove.

/**
 * {@inheritDoc}
 */
@Override
public void remove(MergedContextConfiguration key, @Nullable 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.s
    MergedContextConfiguration startKey = key;
    if (hierarchyMode == HierarchyMode.EXHAUSTIVE) {
        MergedContextConfiguration parent = startKey.getParent();
        while (parent != null) {
            startKey = parent;
            parent = 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 (Map.Entry<MergedContextConfiguration, Set<MergedContextConfiguration>> entry : this.hierarchyMap.entrySet()) {
        if (entry.getValue().isEmpty()) {
            this.hierarchyMap.remove(entry.getKey());
        }
    }
}
Also used : MergedContextConfiguration(cn.taketoday.test.context.MergedContextConfiguration) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with MergedContextConfiguration

use of cn.taketoday.test.context.MergedContextConfiguration in project today-infrastructure by TAKETODAY.

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) {
        context.close();
    }
    removedContexts.add(key);
}
Also used : ConfigurableApplicationContext(cn.taketoday.context.ConfigurableApplicationContext) ConfigurableApplicationContext(cn.taketoday.context.ConfigurableApplicationContext) ApplicationContext(cn.taketoday.context.ApplicationContext) MergedContextConfiguration(cn.taketoday.test.context.MergedContextConfiguration)

Example 4 with MergedContextConfiguration

use of cn.taketoday.test.context.MergedContextConfiguration in project today-infrastructure by TAKETODAY.

the class DelegatingSmartContextLoaderTests method loadContextWithConfigurationClass.

@Test
void loadContextWithConfigurationClass() throws Exception {
    MergedContextConfiguration mergedConfig = new MergedContextConfiguration(ConfigClassTestCase.class, EMPTY_STRING_ARRAY, new Class<?>[] { ConfigClassTestCase.Config.class }, EMPTY_STRING_ARRAY, loader);
    assertApplicationContextLoadsAndContainsFooString(mergedConfig);
}
Also used : MergedContextConfiguration(cn.taketoday.test.context.MergedContextConfiguration) Test(org.junit.jupiter.api.Test)

Example 5 with MergedContextConfiguration

use of cn.taketoday.test.context.MergedContextConfiguration in project today-infrastructure by TAKETODAY.

the class BootstrapTestUtilsMergedConfigTests method buildMergedConfigWithMetaAnnotationAndClasses.

private void buildMergedConfigWithMetaAnnotationAndClasses(Class<?> testClass) {
    MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass);
    assertMergedConfig(mergedConfig, testClass, EMPTY_STRING_ARRAY, array(FooConfig.class, BarConfig.class), DelegatingSmartContextLoader.class);
}
Also used : MergedContextConfiguration(cn.taketoday.test.context.MergedContextConfiguration) WebMergedContextConfiguration(cn.taketoday.test.context.web.WebMergedContextConfiguration)

Aggregations

MergedContextConfiguration (cn.taketoday.test.context.MergedContextConfiguration)84 Test (org.junit.jupiter.api.Test)66 WebMergedContextConfiguration (cn.taketoday.test.context.web.WebMergedContextConfiguration)54 ApplicationContext (cn.taketoday.context.ApplicationContext)2 ConfigurableApplicationContext (cn.taketoday.context.ConfigurableApplicationContext)2 ContextConfiguration (cn.taketoday.test.context.ContextConfiguration)2 ContextHierarchy (cn.taketoday.test.context.ContextHierarchy)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2