本文整理匯總了Java中org.springframework.test.context.ActiveProfiles類的典型用法代碼示例。如果您正苦於以下問題:Java ActiveProfiles類的具體用法?Java ActiveProfiles怎麽用?Java ActiveProfiles使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ActiveProfiles類屬於org.springframework.test.context包,在下文中一共展示了ActiveProfiles類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: resolve
import org.springframework.test.context.ActiveProfiles; //導入依賴的package包/類
/**
* 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);
}