类org.springframework.test.context.ActiveProfiles源码实例Demo

下面列出了怎么用org.springframework.test.context.ActiveProfiles的API类实例代码及写法,或者点击链接到github查看源代码。

/**
 * 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);
}
 
/**
 * 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);
}
 
/**
 * 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);
}
 
 同包方法