use of cn.taketoday.test.context.ContextConfigurationAttributes in project today-infrastructure by TAKETODAY.
the class DelegatingSmartContextLoaderTests method processContextConfigurationWithLocation.
@Test
void processContextConfigurationWithLocation() {
String[] locations = new String[] { "classpath:/foo.xml" };
ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(getClass(), locations, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class);
loader.processContextConfiguration(configAttributes);
assertThat(configAttributes.getLocations()).isEqualTo(locations);
assertEmpty(configAttributes.getClasses());
}
use of cn.taketoday.test.context.ContextConfigurationAttributes in project today-infrastructure by TAKETODAY.
the class DelegatingSmartContextLoaderTests method processContextConfigurationWithDefaultXmlConfigGeneration.
// --- SmartContextLoader - processContextConfiguration() ------------------
@Test
void processContextConfigurationWithDefaultXmlConfigGeneration() {
ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(XmlTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class);
loader.processContextConfiguration(configAttributes);
assertThat(configAttributes.getLocations().length).isEqualTo(1);
assertEmpty(configAttributes.getClasses());
}
use of cn.taketoday.test.context.ContextConfigurationAttributes in project today-infrastructure by TAKETODAY.
the class DelegatingSmartContextLoaderTests method processContextConfigurationWithDefaultXmlConfigAndConfigurationClassGeneration.
@Test
void processContextConfigurationWithDefaultXmlConfigAndConfigurationClassGeneration() {
ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes(ImproperDuplicateDefaultXmlAndConfigClassTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class);
assertThatIllegalStateException().isThrownBy(() -> loader.processContextConfiguration(configAttributes)).withMessageContaining("both default locations AND default configuration classes were detected");
}
use of cn.taketoday.test.context.ContextConfigurationAttributes in project today-infrastructure by TAKETODAY.
the class ContextLoaderUtils method buildContextHierarchyMap.
/**
* Build a <em>context hierarchy map</em> for the supplied {@linkplain Class
* test class} and its superclasses, taking into account context hierarchies
* declared via {@link ContextHierarchy @ContextHierarchy} and
* {@link ContextConfiguration @ContextConfiguration}.
* <p>Each value in the map represents the consolidated list of {@linkplain
* ContextConfigurationAttributes context configuration attributes} for a
* given level in the context hierarchy (potentially across the test class
* hierarchy), keyed by the {@link ContextConfiguration#name() name} of the
* context hierarchy level.
* <p>If a given level in the context hierarchy does not have an explicit
* name (i.e., configured via {@link ContextConfiguration#name}), a name will
* be generated for that hierarchy level by appending the numerical level to
* the {@link #GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX}.
*
* @param testClass the class for which to resolve the context hierarchy map
* (must not be {@code null})
* @return a map of context configuration attributes for the context hierarchy,
* keyed by context hierarchy level name; never {@code null}
* @throws IllegalArgumentException if the lists of context configuration
* attributes for each level in the {@code @ContextHierarchy} do not define
* unique context configuration within the overall hierarchy.
* @see #resolveContextHierarchyAttributes(Class)
* @since 4.0
*/
static Map<String, List<ContextConfigurationAttributes>> buildContextHierarchyMap(Class<?> testClass) {
Map<String, List<ContextConfigurationAttributes>> map = new LinkedHashMap<>();
int hierarchyLevel = 1;
for (List<ContextConfigurationAttributes> configAttributesList : resolveContextHierarchyAttributes(testClass)) {
for (ContextConfigurationAttributes configAttributes : configAttributesList) {
String name = configAttributes.getName();
// Assign a generated name?
if (!StringUtils.hasText(name)) {
name = GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX + hierarchyLevel;
}
// Encountered a new context hierarchy level?
if (!map.containsKey(name)) {
hierarchyLevel++;
map.put(name, new ArrayList<>());
}
map.get(name).add(configAttributes);
}
}
// Check for uniqueness
Set<List<ContextConfigurationAttributes>> set = new HashSet<>(map.values());
if (set.size() != map.size()) {
String msg = String.format("The @ContextConfiguration elements configured via @ContextHierarchy in " + "test class [%s] and its superclasses must define unique contexts per hierarchy level.", testClass.getName());
logger.error(msg);
throw new IllegalStateException(msg);
}
return map;
}
use of cn.taketoday.test.context.ContextConfigurationAttributes in project today-infrastructure by TAKETODAY.
the class ApplicationTestContextBootstrapper method isFromConfiguration.
private boolean isFromConfiguration(MergedContextConfiguration candidateConfig, ContextConfiguration configuration) {
ContextConfigurationAttributes attributes = new ContextConfigurationAttributes(candidateConfig.getTestClass(), configuration);
Set<Class<?>> configurationClasses = new HashSet<>(Arrays.asList(attributes.getClasses()));
for (Class<?> candidate : candidateConfig.getClasses()) {
if (configurationClasses.contains(candidate)) {
return true;
}
}
return false;
}
Aggregations