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();
}
}
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());
}
}
}
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);
}
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);
}
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);
}
Aggregations