Java Code Examples for org.springframework.test.util.MetaAnnotationUtils.AnnotationDescriptor#synthesizeAnnotation()

The following examples show how to use org.springframework.test.util.MetaAnnotationUtils.AnnotationDescriptor#synthesizeAnnotation() . 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
private static List<TestPropertySourceAttributes> resolveTestPropertySourceAttributes(Class<?> testClass) {
	Assert.notNull(testClass, "Class must not be null");
	List<TestPropertySourceAttributes> attributesList = new ArrayList<>();
	Class<TestPropertySource> annotationType = TestPropertySource.class;

	AnnotationDescriptor<TestPropertySource> descriptor = findAnnotationDescriptor(testClass, annotationType);
	Assert.notNull(descriptor, String.format(
			"Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]",
			annotationType.getName(), testClass.getName()));

	while (descriptor != null) {
		TestPropertySource testPropertySource = descriptor.synthesizeAnnotation();
		Class<?> rootDeclaringClass = descriptor.getRootDeclaringClass();
		if (logger.isTraceEnabled()) {
			logger.trace(String.format("Retrieved @TestPropertySource [%s] for declaring class [%s].",
				testPropertySource, rootDeclaringClass.getName()));
		}
		TestPropertySourceAttributes attributes =
				new TestPropertySourceAttributes(rootDeclaringClass, testPropertySource);
		if (logger.isTraceEnabled()) {
			logger.trace("Resolved TestPropertySource attributes: " + attributes);
		}
		attributesList.add(attributes);
		descriptor = findAnnotationDescriptor(rootDeclaringClass.getSuperclass(), annotationType);
	}

	return attributesList;
}
 
Example 2
/**
 * Resolve the <em>bean definition profiles</em> for the given {@linkplain
 * Class test class} based on profiles configured declaratively via
 * {@link ActiveProfiles#profiles} or {@link ActiveProfiles#value}.
 * @param testClass the test class for which the profiles should be resolved;
 * never {@code null}
 * @return the list of bean definition profiles to use when loading the
 * {@code ApplicationContext}; never {@code null}
 */
@Override
public String[] resolve(Class<?> testClass) {
	Assert.notNull(testClass, "Class must not be null");

	final Set<String> activeProfiles = new LinkedHashSet<>();

	Class<ActiveProfiles> annotationType = ActiveProfiles.class;
	AnnotationDescriptor<ActiveProfiles> descriptor = findAnnotationDescriptor(testClass, annotationType);

	if (descriptor == null) {
		if (logger.isDebugEnabled()) {
			logger.debug(String.format(
				"Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]",
				annotationType.getName(), testClass.getName()));
		}
	}
	else {
		Class<?> declaringClass = descriptor.getDeclaringClass();
		ActiveProfiles annotation = descriptor.synthesizeAnnotation();

		if (logger.isTraceEnabled()) {
			logger.trace(String.format("Retrieved @ActiveProfiles [%s] for declaring class [%s].", annotation,
				declaringClass.getName()));
		}

		for (String profile : annotation.profiles()) {
			if (StringUtils.hasText(profile)) {
				activeProfiles.add(profile.trim());
			}
		}
	}

	return StringUtils.toStringArray(activeProfiles);
}
 
Example 3
private static List<TestPropertySourceAttributes> resolveTestPropertySourceAttributes(Class<?> testClass) {
	Assert.notNull(testClass, "Class must not be null");
	List<TestPropertySourceAttributes> attributesList = new ArrayList<>();
	Class<TestPropertySource> annotationType = TestPropertySource.class;

	AnnotationDescriptor<TestPropertySource> descriptor = findAnnotationDescriptor(testClass, annotationType);
	Assert.notNull(descriptor, String.format(
			"Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]",
			annotationType.getName(), testClass.getName()));

	while (descriptor != null) {
		TestPropertySource testPropertySource = descriptor.synthesizeAnnotation();
		Class<?> rootDeclaringClass = descriptor.getRootDeclaringClass();
		if (logger.isTraceEnabled()) {
			logger.trace(String.format("Retrieved @TestPropertySource [%s] for declaring class [%s].",
				testPropertySource, rootDeclaringClass.getName()));
		}
		TestPropertySourceAttributes attributes =
				new TestPropertySourceAttributes(rootDeclaringClass, testPropertySource);
		if (logger.isTraceEnabled()) {
			logger.trace("Resolved TestPropertySource attributes: " + attributes);
		}
		attributesList.add(attributes);
		descriptor = findAnnotationDescriptor(rootDeclaringClass.getSuperclass(), annotationType);
	}

	return attributesList;
}
 
Example 4
/**
 * Resolve the <em>bean definition profiles</em> for the given {@linkplain
 * Class test class} based on profiles configured declaratively via
 * {@link ActiveProfiles#profiles} or {@link ActiveProfiles#value}.
 * @param testClass the test class for which the profiles should be resolved;
 * never {@code null}
 * @return the list of bean definition profiles to use when loading the
 * {@code ApplicationContext}; never {@code null}
 */
@Override
public String[] resolve(Class<?> testClass) {
	Assert.notNull(testClass, "Class must not be null");

	final Set<String> activeProfiles = new LinkedHashSet<>();

	Class<ActiveProfiles> annotationType = ActiveProfiles.class;
	AnnotationDescriptor<ActiveProfiles> descriptor = findAnnotationDescriptor(testClass, annotationType);

	if (descriptor == null) {
		if (logger.isDebugEnabled()) {
			logger.debug(String.format(
				"Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]",
				annotationType.getName(), testClass.getName()));
		}
	}
	else {
		Class<?> declaringClass = descriptor.getDeclaringClass();
		ActiveProfiles annotation = descriptor.synthesizeAnnotation();

		if (logger.isTraceEnabled()) {
			logger.trace(String.format("Retrieved @ActiveProfiles [%s] for declaring class [%s].", annotation,
				declaringClass.getName()));
		}

		for (String profile : annotation.profiles()) {
			if (StringUtils.hasText(profile)) {
				activeProfiles.add(profile.trim());
			}
		}
	}

	return StringUtils.toStringArray(activeProfiles);
}
 
Example 5
private static List<TestPropertySourceAttributes> resolveTestPropertySourceAttributes(Class<?> testClass) {
	Assert.notNull(testClass, "Class must not be null");

	final List<TestPropertySourceAttributes> attributesList = new ArrayList<TestPropertySourceAttributes>();
	final Class<TestPropertySource> annotationType = TestPropertySource.class;
	AnnotationDescriptor<TestPropertySource> descriptor = findAnnotationDescriptor(testClass, annotationType);
	Assert.notNull(descriptor, String.format(
		"Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]",
		annotationType.getName(), testClass.getName()));

	while (descriptor != null) {
		TestPropertySource testPropertySource = descriptor.synthesizeAnnotation();
		Class<?> rootDeclaringClass = descriptor.getRootDeclaringClass();

		if (logger.isTraceEnabled()) {
			logger.trace(String.format("Retrieved @TestPropertySource [%s] for declaring class [%s].",
				testPropertySource, rootDeclaringClass.getName()));
		}

		TestPropertySourceAttributes attributes = new TestPropertySourceAttributes(rootDeclaringClass,
			testPropertySource);
		if (logger.isTraceEnabled()) {
			logger.trace("Resolved TestPropertySource attributes: " + attributes);
		}
		attributesList.add(attributes);

		descriptor = findAnnotationDescriptor(rootDeclaringClass.getSuperclass(), annotationType);
	}

	return attributesList;
}
 
Example 6
/**
 * Resolve the <em>bean definition profiles</em> for the given {@linkplain
 * Class test class} based on profiles configured declaratively via
 * {@link ActiveProfiles#profiles} or {@link ActiveProfiles#value}.
 * @param testClass the test class for which the profiles should be resolved;
 * never {@code null}
 * @return the list of bean definition profiles to use when loading the
 * {@code ApplicationContext}; never {@code null}
 */
@Override
public String[] resolve(Class<?> testClass) {
	Assert.notNull(testClass, "Class must not be null");

	final Set<String> activeProfiles = new LinkedHashSet<String>();

	Class<ActiveProfiles> annotationType = ActiveProfiles.class;
	AnnotationDescriptor<ActiveProfiles> descriptor = findAnnotationDescriptor(testClass, annotationType);

	if (descriptor == null) {
		if (logger.isDebugEnabled()) {
			logger.debug(String.format(
				"Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]",
				annotationType.getName(), testClass.getName()));
		}
	}
	else {
		Class<?> declaringClass = descriptor.getDeclaringClass();
		ActiveProfiles annotation = descriptor.synthesizeAnnotation();

		if (logger.isTraceEnabled()) {
			logger.trace(String.format("Retrieved @ActiveProfiles [%s] for declaring class [%s].", annotation,
				declaringClass.getName()));
		}

		for (String profile : annotation.profiles()) {
			if (StringUtils.hasText(profile)) {
				activeProfiles.add(profile.trim());
			}
		}
	}

	return StringUtils.toStringArray(activeProfiles);
}