Java Code Examples for org.springframework.test.util.MetaAnnotationUtils

The following examples show how to use org.springframework.test.util.MetaAnnotationUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public final MergedContextConfiguration buildMergedContextConfiguration() {
	Class<?> testClass = getBootstrapContext().getTestClass();
	CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate = getCacheAwareContextLoaderDelegate();

	if (MetaAnnotationUtils.findAnnotationDescriptorForTypes(
			testClass, ContextConfiguration.class, ContextHierarchy.class) == null) {
		return buildDefaultMergedContextConfiguration(testClass, cacheAwareContextLoaderDelegate);
	}

	if (AnnotationUtils.findAnnotation(testClass, ContextHierarchy.class) != null) {
		Map<String, List<ContextConfigurationAttributes>> hierarchyMap =
				ContextLoaderUtils.buildContextHierarchyMap(testClass);
		MergedContextConfiguration parentConfig = null;
		MergedContextConfiguration mergedConfig = null;

		for (List<ContextConfigurationAttributes> list : hierarchyMap.values()) {
			List<ContextConfigurationAttributes> reversedList = new ArrayList<>(list);
			Collections.reverse(reversedList);

			// Don't use the supplied testClass; instead ensure that we are
			// building the MCC for the actual test class that declared the
			// configuration for the current level in the context hierarchy.
			Assert.notEmpty(reversedList, "ContextConfigurationAttributes list must not be empty");
			Class<?> declaringClass = reversedList.get(0).getDeclaringClass();

			mergedConfig = buildMergedContextConfiguration(
					declaringClass, reversedList, parentConfig, cacheAwareContextLoaderDelegate, true);
			parentConfig = mergedConfig;
		}

		// Return the last level in the context hierarchy
		Assert.state(mergedConfig != null, "No merged context configuration");
		return mergedConfig;
	}
	else {
		return buildMergedContextConfiguration(testClass,
				ContextLoaderUtils.resolveContextConfigurationAttributes(testClass),
				null, cacheAwareContextLoaderDelegate, true);
	}
}
 
Example 2
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public final MergedContextConfiguration buildMergedContextConfiguration() {
	Class<?> testClass = getBootstrapContext().getTestClass();
	CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate = getCacheAwareContextLoaderDelegate();

	if (MetaAnnotationUtils.findAnnotationDescriptorForTypes(
			testClass, ContextConfiguration.class, ContextHierarchy.class) == null) {
		return buildDefaultMergedContextConfiguration(testClass, cacheAwareContextLoaderDelegate);
	}

	if (AnnotationUtils.findAnnotation(testClass, ContextHierarchy.class) != null) {
		Map<String, List<ContextConfigurationAttributes>> hierarchyMap =
				ContextLoaderUtils.buildContextHierarchyMap(testClass);
		MergedContextConfiguration parentConfig = null;
		MergedContextConfiguration mergedConfig = null;

		for (List<ContextConfigurationAttributes> list : hierarchyMap.values()) {
			List<ContextConfigurationAttributes> reversedList = new ArrayList<>(list);
			Collections.reverse(reversedList);

			// Don't use the supplied testClass; instead ensure that we are
			// building the MCC for the actual test class that declared the
			// configuration for the current level in the context hierarchy.
			Assert.notEmpty(reversedList, "ContextConfigurationAttributes list must not be empty");
			Class<?> declaringClass = reversedList.get(0).getDeclaringClass();

			mergedConfig = buildMergedContextConfiguration(
					declaringClass, reversedList, parentConfig, cacheAwareContextLoaderDelegate, true);
			parentConfig = mergedConfig;
		}

		// Return the last level in the context hierarchy
		Assert.state(mergedConfig != null, "No merged context configuration");
		return mergedConfig;
	}
	else {
		return buildMergedContextConfiguration(testClass,
				ContextLoaderUtils.resolveContextConfigurationAttributes(testClass),
				null, cacheAwareContextLoaderDelegate, true);
	}
}
 
Example 3
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public final MergedContextConfiguration buildMergedContextConfiguration() {
	Class<?> testClass = getBootstrapContext().getTestClass();
	CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate = getCacheAwareContextLoaderDelegate();

	if (MetaAnnotationUtils.findAnnotationDescriptorForTypes(testClass, ContextConfiguration.class,
		ContextHierarchy.class) == null) {
		if (logger.isInfoEnabled()) {
			logger.info(String.format(
				"Neither @ContextConfiguration nor @ContextHierarchy found for test class [%s]",
				testClass.getName()));
		}
		return new MergedContextConfiguration(testClass, null, null, null, null);
	}

	if (AnnotationUtils.findAnnotation(testClass, ContextHierarchy.class) != null) {
		Map<String, List<ContextConfigurationAttributes>> hierarchyMap = ContextLoaderUtils.buildContextHierarchyMap(testClass);
		MergedContextConfiguration parentConfig = null;
		MergedContextConfiguration mergedConfig = null;

		for (List<ContextConfigurationAttributes> list : hierarchyMap.values()) {
			List<ContextConfigurationAttributes> reversedList = new ArrayList<ContextConfigurationAttributes>(list);
			Collections.reverse(reversedList);

			// Don't use the supplied testClass; instead ensure that we are
			// building the MCC for the actual test class that declared the
			// configuration for the current level in the context hierarchy.
			Assert.notEmpty(reversedList, "ContextConfigurationAttributes list must not be empty");
			Class<?> declaringClass = reversedList.get(0).getDeclaringClass();

			mergedConfig = buildMergedContextConfiguration(declaringClass, reversedList, parentConfig,
				cacheAwareContextLoaderDelegate);
			parentConfig = mergedConfig;
		}

		// Return the last level in the context hierarchy
		return mergedConfig;
	}
	else {
		return buildMergedContextConfiguration(testClass,
			ContextLoaderUtils.resolveContextConfigurationAttributes(testClass), null,
			cacheAwareContextLoaderDelegate);
	}
}