org.springframework.test.context.ActiveProfiles Java Examples
The following examples show how to use
org.springframework.test.context.ActiveProfiles.
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
Source File: DefaultActiveProfilesResolver.java From spring-analysis-note with MIT License | 5 votes |
/** * 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 #2
Source File: DefaultActiveProfilesResolver.java From java-technology-stack with MIT License | 5 votes |
/** * 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
Source File: DefaultActiveProfilesResolver.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * 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); }