|
Spring Framework example source code file (ProfileValueUtils.java)
The Spring Framework ProfileValueUtils.java source code
/*
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.test.annotation;
import java.lang.reflect.Method;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/**
* General utility methods for working with <em>profile values.
*
* @author Sam Brannen
* @author Juergen Hoeller
* @since 2.5
* @see ProfileValueSource
* @see ProfileValueSourceConfiguration
* @see IfProfileValue
*/
public abstract class ProfileValueUtils {
private static final Log logger = LogFactory.getLog(ProfileValueUtils.class);
/**
* Retrieve the {@link ProfileValueSource} type for the specified
* {@link Class test class} as configured via the
* {@link ProfileValueSourceConfiguration @ProfileValueSourceConfiguration}
* annotation and instantiates a new instance of that type.
* <p>If {@link ProfileValueSourceConfiguration @ProfileValueSourceConfiguration}
* is not present on the specified class or if a custom
* {@link ProfileValueSource} is not declared, the default
* {@link SystemProfileValueSource} will be returned instead.
* @param testClass The test class for which the ProfileValueSource should be retrieved
* @return the configured (or default) ProfileValueSource for the specified class
* @see SystemProfileValueSource
*/
@SuppressWarnings("unchecked")
public static ProfileValueSource retrieveProfileValueSource(Class<?> testClass) {
Assert.notNull(testClass, "Can not retrieve a ProfileValueSource for a NULL class.");
Class<ProfileValueSourceConfiguration> annotationType = ProfileValueSourceConfiguration.class;
ProfileValueSourceConfiguration config = testClass.getAnnotation(annotationType);
if (logger.isDebugEnabled()) {
logger.debug("Retrieved @ProfileValueSourceConfiguration [" + config + "] for test class [" +
testClass.getName() + "]");
}
Class<? extends ProfileValueSource> profileValueSourceType;
if (config != null) {
profileValueSourceType = config.value();
}
else {
profileValueSourceType = (Class<? extends ProfileValueSource>) AnnotationUtils.getDefaultValue(annotationType);
}
if (logger.isDebugEnabled()) {
logger.debug("Retrieved ProfileValueSource type [" + profileValueSourceType + "] for class [" +
testClass.getName() + "]");
}
ProfileValueSource profileValueSource;
if (SystemProfileValueSource.class.equals(profileValueSourceType)) {
profileValueSource = SystemProfileValueSource.getInstance();
}
else {
try {
profileValueSource = profileValueSourceType.newInstance();
}
catch (Exception e) {
if (logger.isWarnEnabled()) {
logger.warn("Could not instantiate a ProfileValueSource of type [" + profileValueSourceType
+ "] for class [" + testClass.getName() + "]: using default.", e);
}
profileValueSource = SystemProfileValueSource.getInstance();
}
}
return profileValueSource;
}
/**
* Determine if the supplied <code>testMethod is enabled
* in the current environment, as specified by the
* {@link IfProfileValue @IfProfileValue} annotation, which may be declared
* on the test method itself or at the class-level.
* <p>Defaults to
Other Spring Framework examples (source code examples)Here is a short list of links related to this Spring Framework ProfileValueUtils.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.