Polish and fix sonar warnings
This commit is contained in:
@@ -118,41 +118,54 @@ class BeanDefinitionLoader {
|
||||
private int load(Object source) {
|
||||
Assert.notNull(source, "Source must not be null");
|
||||
if (source instanceof Class<?>) {
|
||||
Class<?> type = (Class<?>) source;
|
||||
if (isComponent(type)) {
|
||||
this.annotatedReader.register(type);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
return load((Class<?>) source);
|
||||
}
|
||||
|
||||
if (source instanceof Resource) {
|
||||
return this.xmlReader.loadBeanDefinitions((Resource) source);
|
||||
return load((Resource) source);
|
||||
}
|
||||
|
||||
if (source instanceof Package) {
|
||||
// FIXME register the scanned package for data to pick up
|
||||
return this.scanner.scan(((Package) source).getName());
|
||||
return load((Package) source);
|
||||
}
|
||||
|
||||
if (source instanceof CharSequence) {
|
||||
try {
|
||||
return load(Class.forName(source.toString()));
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
}
|
||||
return load((CharSequence) source);
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid source type " + source.getClass());
|
||||
}
|
||||
|
||||
Resource loadedResource = (this.resourceLoader != null ? this.resourceLoader
|
||||
: DEFAULT_RESOURCE_LOADER).getResource(source.toString());
|
||||
if (loadedResource != null && loadedResource.exists()) {
|
||||
return load(loadedResource);
|
||||
}
|
||||
Package packageResource = Package.getPackage(source.toString());
|
||||
if (packageResource != null) {
|
||||
return load(packageResource);
|
||||
}
|
||||
private int load(Class<?> source) {
|
||||
if (isComponent(source)) {
|
||||
this.annotatedReader.register(source);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int load(Resource source) {
|
||||
return this.xmlReader.loadBeanDefinitions(source);
|
||||
}
|
||||
|
||||
private int load(Package source) {
|
||||
// FIXME register the scanned package for data to pick up
|
||||
return this.scanner.scan(source.getName());
|
||||
}
|
||||
|
||||
private int load(CharSequence source) {
|
||||
try {
|
||||
return load(Class.forName(source.toString()));
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// swallow exception and continue
|
||||
}
|
||||
|
||||
Resource loadedResource = (this.resourceLoader != null ? this.resourceLoader
|
||||
: DEFAULT_RESOURCE_LOADER).getResource(source.toString());
|
||||
if (loadedResource != null && loadedResource.exists()) {
|
||||
return load(loadedResource);
|
||||
}
|
||||
Package packageResource = Package.getPackage(source.toString());
|
||||
if (packageResource != null) {
|
||||
return load(packageResource);
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid source '" + source + "'");
|
||||
}
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ public class SpringApplication {
|
||||
initialize();
|
||||
}
|
||||
|
||||
protected void initialize() {
|
||||
private void initialize() {
|
||||
this.webEnvironment = deduceWebEnvironment();
|
||||
this.initializers = new ArrayList<ApplicationContextInitializer<?>>();
|
||||
@SuppressWarnings("rawtypes")
|
||||
@@ -376,8 +376,8 @@ public class SpringApplication {
|
||||
String optionName;
|
||||
String optionValue = "";
|
||||
if (optionText.contains("=")) {
|
||||
optionName = optionText.substring(0, optionText.indexOf("="));
|
||||
optionValue = optionText.substring(optionText.indexOf("=") + 1,
|
||||
optionName = optionText.substring(0, optionText.indexOf('='));
|
||||
optionValue = optionText.substring(optionText.indexOf('=') + 1,
|
||||
optionText.length());
|
||||
}
|
||||
else {
|
||||
@@ -439,8 +439,8 @@ public class SpringApplication {
|
||||
try {
|
||||
runner.run(args);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to execute CommandLineRunner", e);
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Failed to execute CommandLineRunner", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -617,8 +617,8 @@ public class SpringApplication {
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
exitCode = (exitCode == 0 ? 1 : exitCode);
|
||||
}
|
||||
return exitCode;
|
||||
@@ -633,9 +633,9 @@ public class SpringApplication {
|
||||
exitCode = value;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
exitCode = (exitCode == 0 ? 1 : exitCode);
|
||||
e.printStackTrace();
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return exitCode;
|
||||
|
||||
@@ -75,8 +75,8 @@ public class CustomPropertyConstructor extends Constructor {
|
||||
try {
|
||||
typeMap.put(alias, this.propertyUtils.getProperty(type, name));
|
||||
}
|
||||
catch (IntrospectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
catch (IntrospectionException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,8 +38,8 @@ public class InetAddressEditor extends PropertyEditorSupport implements Property
|
||||
try {
|
||||
setValue(InetAddress.getByName(text));
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
throw new IllegalArgumentException("Cannot locate host", e);
|
||||
catch (UnknownHostException ex) {
|
||||
throw new IllegalArgumentException("Cannot locate host", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,7 @@ import org.springframework.validation.Validator;
|
||||
public class PropertiesConfigurationFactory<T> implements FactoryBean<T>,
|
||||
MessageSourceAware, InitializingBean {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(PropertiesConfigurationFactory.class);
|
||||
private final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private boolean ignoreUnknownFields = true;
|
||||
|
||||
@@ -193,23 +192,23 @@ public class PropertiesConfigurationFactory<T> implements FactoryBean<T>,
|
||||
Assert.state(this.properties != null || this.propertySources != null,
|
||||
"Properties or propertySources should not be null");
|
||||
try {
|
||||
if (logger.isTraceEnabled()) {
|
||||
if (this.logger.isTraceEnabled()) {
|
||||
if (this.properties != null) {
|
||||
logger.trace("Properties:\n" + this.properties);
|
||||
this.logger.trace("Properties:\n" + this.properties);
|
||||
}
|
||||
else {
|
||||
logger.trace("Property Sources: " + this.propertySources);
|
||||
this.logger.trace("Property Sources: " + this.propertySources);
|
||||
}
|
||||
}
|
||||
this.hasBeenBound = true;
|
||||
doBindPropertiesToTarget();
|
||||
}
|
||||
catch (BindException e) {
|
||||
catch (BindException ex) {
|
||||
if (this.exceptionIfInvalid) {
|
||||
throw e;
|
||||
throw ex;
|
||||
}
|
||||
logger.error("Failed to load Properties validation bean. "
|
||||
+ "Your Properties may be invalid.", e);
|
||||
this.logger.error("Failed to load Properties validation bean. "
|
||||
+ "Your Properties may be invalid.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,10 +240,11 @@ public class PropertiesConfigurationFactory<T> implements FactoryBean<T>,
|
||||
dataBinder.validate();
|
||||
BindingResult errors = dataBinder.getBindingResult();
|
||||
if (errors.hasErrors()) {
|
||||
logger.error("Properties configuration failed validation");
|
||||
this.logger.error("Properties configuration failed validation");
|
||||
for (ObjectError error : errors.getAllErrors()) {
|
||||
logger.error(this.messageSource != null ? this.messageSource.getMessage(
|
||||
error, Locale.getDefault()) + " (" + error + ")" : error);
|
||||
this.logger.error(this.messageSource != null ? this.messageSource
|
||||
.getMessage(error, Locale.getDefault()) + " (" + error + ")"
|
||||
: error);
|
||||
}
|
||||
if (this.exceptionIfInvalid) {
|
||||
BindException summary = new BindException(errors);
|
||||
|
||||
@@ -199,6 +199,7 @@ public class RelaxedDataBinder extends DataBinder {
|
||||
}
|
||||
}
|
||||
catch (InvalidPropertyException ex) {
|
||||
// swallow and contrinue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ import org.yaml.snakeyaml.error.YAMLException;
|
||||
public class YamlConfigurationFactory<T> implements FactoryBean<T>, MessageSourceAware,
|
||||
InitializingBean {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(YamlConfigurationFactory.class);
|
||||
private final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private Class<?> type;
|
||||
|
||||
@@ -128,44 +128,45 @@ public class YamlConfigurationFactory<T> implements FactoryBean<T>, MessageSourc
|
||||
Charset.defaultCharset());
|
||||
}
|
||||
|
||||
Assert.state(
|
||||
this.yaml != null,
|
||||
"Yaml document should not be null: either set it directly or set the resource to load it from");
|
||||
Assert.state(this.yaml != null, "Yaml document should not be null: "
|
||||
+ "either set it directly or set the resource to load it from");
|
||||
|
||||
try {
|
||||
logger.trace("Yaml document is\n" + this.yaml);
|
||||
if (this.logger.isTraceEnabled()) {
|
||||
this.logger.trace("Yaml document is\n" + this.yaml);
|
||||
}
|
||||
Constructor constructor = new CustomPropertyConstructor(this.type,
|
||||
this.propertyAliases);
|
||||
this.configuration = (T) (new Yaml(constructor)).load(this.yaml);
|
||||
|
||||
if (this.validator != null) {
|
||||
BindingResult errors = new BeanPropertyBindingResult(this.configuration,
|
||||
"configuration");
|
||||
this.validator.validate(this.configuration, errors);
|
||||
|
||||
if (errors.hasErrors()) {
|
||||
logger.error("YAML configuration failed validation");
|
||||
for (ObjectError error : errors.getAllErrors()) {
|
||||
logger.error(this.messageSource != null ? this.messageSource
|
||||
.getMessage(error, Locale.getDefault())
|
||||
+ " ("
|
||||
+ error
|
||||
+ ")" : error);
|
||||
}
|
||||
if (this.exceptionIfInvalid) {
|
||||
BindException summary = new BindException(errors);
|
||||
throw summary;
|
||||
}
|
||||
}
|
||||
validate();
|
||||
}
|
||||
}
|
||||
catch (YAMLException e) {
|
||||
catch (YAMLException ex) {
|
||||
if (this.exceptionIfInvalid) {
|
||||
throw e;
|
||||
throw ex;
|
||||
}
|
||||
this.logger.error("Failed to load YAML validation bean. "
|
||||
+ "Your YAML file may be invalid.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void validate() throws BindException {
|
||||
BindingResult errors = new BeanPropertyBindingResult(this.configuration,
|
||||
"configuration");
|
||||
this.validator.validate(this.configuration, errors);
|
||||
|
||||
if (errors.hasErrors()) {
|
||||
this.logger.error("YAML configuration failed validation");
|
||||
for (ObjectError error : errors.getAllErrors()) {
|
||||
this.logger.error(this.messageSource != null ? this.messageSource
|
||||
.getMessage(error, Locale.getDefault()) + " (" + error + ")"
|
||||
: error);
|
||||
}
|
||||
if (this.exceptionIfInvalid) {
|
||||
BindException summary = new BindException(errors);
|
||||
throw summary;
|
||||
}
|
||||
logger.error(
|
||||
"Failed to load YAML validation bean. Your YAML file may be invalid.",
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.zero.config;
|
||||
|
||||
import java.util.List;
|
||||
@@ -29,26 +30,24 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
public class JacksonJsonParser implements JsonParser {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> parseMap(String json) {
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = new ObjectMapper().readValue(json, Map.class);
|
||||
return map;
|
||||
return new ObjectMapper().readValue(json, Map.class);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalArgumentException("Cannot parse JSON", e);
|
||||
catch (Exception ex) {
|
||||
throw new IllegalArgumentException("Cannot parse JSON", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Object> parseList(String json) {
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> list = new ObjectMapper().readValue(json, List.class);
|
||||
return list;
|
||||
return new ObjectMapper().readValue(json, List.class);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalArgumentException("Cannot parse JSON", e);
|
||||
catch (Exception ex) {
|
||||
throw new IllegalArgumentException("Cannot parse JSON", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.zero.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.util.ClassUtils;
|
||||
* @see YamlJsonParser
|
||||
* @see SimpleJsonParser
|
||||
*/
|
||||
public class JsonParserFactory {
|
||||
public abstract class JsonParserFactory {
|
||||
|
||||
/**
|
||||
* Static factory for the "best" JSON parser available on the classpath. Tries Jackson
|
||||
|
||||
@@ -30,17 +30,15 @@ import org.yaml.snakeyaml.Yaml;
|
||||
public class YamlJsonParser implements JsonParser {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, Object> parseMap(String json) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = new Yaml().loadAs(json, Map.class);
|
||||
return map;
|
||||
return new Yaml().loadAs(json, Map.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Object> parseList(String json) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> list = new Yaml().loadAs(json, List.class);
|
||||
return list;
|
||||
return new Yaml().loadAs(json, List.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,35 +38,7 @@ import org.yaml.snakeyaml.Yaml;
|
||||
*/
|
||||
public class YamlProcessor {
|
||||
|
||||
public interface MatchCallback {
|
||||
void process(Properties properties, Map<String, Object> map);
|
||||
}
|
||||
|
||||
public interface DocumentMatcher {
|
||||
MatchStatus matches(Properties properties);
|
||||
}
|
||||
|
||||
private static final Log logger = LogFactory.getLog(YamlProcessor.class);
|
||||
|
||||
public static enum ResolutionMethod {
|
||||
OVERRIDE, OVERRIDE_AND_IGNORE, FIRST_FOUND
|
||||
}
|
||||
|
||||
public static enum MatchStatus {
|
||||
|
||||
/**
|
||||
* A match was found.
|
||||
*/
|
||||
FOUND,
|
||||
/**
|
||||
* A match was not found.
|
||||
*/
|
||||
NOT_FOUND,
|
||||
/**
|
||||
* Not enough information to decide.
|
||||
*/
|
||||
ABSTAIN
|
||||
}
|
||||
private final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private ResolutionMethod resolutionMethod = ResolutionMethod.OVERRIDE;
|
||||
|
||||
@@ -139,7 +111,7 @@ public class YamlProcessor {
|
||||
* @param resources the resources to set
|
||||
*/
|
||||
public void setResources(Resource[] resources) {
|
||||
this.resources = resources;
|
||||
this.resources = (resources == null ? null : resources.clone());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,52 +126,56 @@ public class YamlProcessor {
|
||||
*/
|
||||
protected void process(MatchCallback callback) {
|
||||
Yaml yaml = new Yaml();
|
||||
boolean found = false;
|
||||
for (Resource resource : this.resources) {
|
||||
try {
|
||||
logger.info("Loading from YAML: " + resource);
|
||||
int count = 0;
|
||||
for (Object object : yaml.loadAll(resource.getInputStream())) {
|
||||
if (this.resolutionMethod != ResolutionMethod.FIRST_FOUND || !found) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = (Map<String, Object>) object;
|
||||
if (map != null) {
|
||||
found = process(map, callback);
|
||||
if (found) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("Loaded " + count + " document" + (count > 1 ? "s" : "")
|
||||
+ " from YAML resource: " + resource);
|
||||
|
||||
if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND && found) {
|
||||
// No need to load any more resources
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND
|
||||
|| this.resolutionMethod == ResolutionMethod.OVERRIDE_AND_IGNORE) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Could not load map from " + resource + ": "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
boolean found = process(callback, yaml, resource);
|
||||
if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND && found) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean process(MatchCallback callback, Yaml yaml, Resource resource) {
|
||||
int count = 0;
|
||||
try {
|
||||
this.logger.info("Loading from YAML: " + resource);
|
||||
for (Object object : yaml.loadAll(resource.getInputStream())) {
|
||||
if (object != null && process(asMap(object), callback)) {
|
||||
count++;
|
||||
if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.logger.info("Loaded " + count + " document" + (count > 1 ? "s" : "")
|
||||
+ " from YAML resource: " + resource);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
handleProcessError(resource, ex);
|
||||
}
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
private void handleProcessError(Resource resource, IOException ex) {
|
||||
if (this.resolutionMethod != ResolutionMethod.FIRST_FOUND
|
||||
&& this.resolutionMethod != ResolutionMethod.OVERRIDE_AND_IGNORE) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
if (this.logger.isWarnEnabled()) {
|
||||
this.logger.warn("Could not load map from " + resource + ": "
|
||||
+ ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> asMap(Object object) {
|
||||
return (Map<String, Object>) object;
|
||||
}
|
||||
|
||||
private boolean process(Map<String, Object> map, MatchCallback callback) {
|
||||
Properties properties = new Properties();
|
||||
assignProperties(properties, map, null);
|
||||
if (this.documentMatchers.isEmpty()) {
|
||||
logger.debug("Merging document (no matchers set)" + map);
|
||||
this.logger.debug("Merging document (no matchers set)" + map);
|
||||
callback.process(properties, map);
|
||||
}
|
||||
else {
|
||||
@@ -209,7 +185,8 @@ public class YamlProcessor {
|
||||
MatchStatus match = matcher.matches(properties);
|
||||
result = match.ordinal() < result.ordinal() ? match : result;
|
||||
if (match == MatchStatus.FOUND) {
|
||||
logger.debug("Matched document with document matcher: " + properties);
|
||||
this.logger.debug("Matched document with document matcher: "
|
||||
+ properties);
|
||||
callback.process(properties, map);
|
||||
valueFound = true;
|
||||
// No need to check for more matches
|
||||
@@ -217,11 +194,11 @@ public class YamlProcessor {
|
||||
}
|
||||
}
|
||||
if (result == MatchStatus.ABSTAIN && this.matchDefault) {
|
||||
logger.debug("Matched document with default matcher: " + map);
|
||||
this.logger.debug("Matched document with default matcher: " + map);
|
||||
callback.process(properties, map);
|
||||
}
|
||||
else if (!valueFound) {
|
||||
logger.debug("Unmatched document");
|
||||
this.logger.debug("Unmatched document");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -268,13 +245,26 @@ public class YamlProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
public interface MatchCallback {
|
||||
void process(Properties properties, Map<String, Object> map);
|
||||
}
|
||||
|
||||
public interface DocumentMatcher {
|
||||
MatchStatus matches(Properties properties);
|
||||
}
|
||||
|
||||
public static enum ResolutionMethod {
|
||||
OVERRIDE, OVERRIDE_AND_IGNORE, FIRST_FOUND
|
||||
}
|
||||
|
||||
public static enum MatchStatus {
|
||||
FOUND, NOT_FOUND, ABSTAIN
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches a document containing a given key and where the value of that key is an
|
||||
* array containing one of the given values, or where one of the values matches one of
|
||||
* the given values (interpreted as regexes).
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public static class ArrayDocumentMatcher implements DocumentMatcher {
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ import org.springframework.util.ReflectionUtils.MethodCallback;
|
||||
*/
|
||||
abstract class AbstractOnBeanCondition implements ConfigurationCondition {
|
||||
|
||||
protected Log logger = LogFactory.getLog(getClass());
|
||||
private final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
protected abstract Class<?> annotationClass();
|
||||
|
||||
@@ -79,7 +79,8 @@ abstract class AbstractOnBeanCondition implements ConfigurationCondition {
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
// swallow exception and continue
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,6 +120,7 @@ abstract class AbstractOnBeanCondition implements ConfigurationCondition {
|
||||
}
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// swallow exception and continue
|
||||
}
|
||||
}
|
||||
for (String beanName : beanNames) {
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.core.type.MethodMetadata;
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class ConditionLogUtils {
|
||||
public abstract class ConditionLogUtils {
|
||||
|
||||
public static String getPrefix(Log logger, AnnotatedTypeMetadata metadata) {
|
||||
String prefix = "";
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.zero.context.condition;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
@@ -77,7 +77,8 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
|
||||
* @param port the port number for the embedded servlet container
|
||||
*/
|
||||
public AbstractEmbeddedServletContainerFactory(int port) {
|
||||
setPort(port);
|
||||
checkPort(port);
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,8 +88,10 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
|
||||
* @param port the port number for the embedded servlet container
|
||||
*/
|
||||
public AbstractEmbeddedServletContainerFactory(String contextPath, int port) {
|
||||
setContextPath(contextPath);
|
||||
setPort(port);
|
||||
checkContextPath(contextPath);
|
||||
checkPort(port);
|
||||
this.contextPath = contextPath;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,6 +103,11 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
|
||||
*/
|
||||
@Override
|
||||
public void setContextPath(String contextPath) {
|
||||
checkContextPath(contextPath);
|
||||
this.contextPath = contextPath;
|
||||
}
|
||||
|
||||
private void checkContextPath(String contextPath) {
|
||||
Assert.notNull(contextPath, "ContextPath must not be null");
|
||||
if (contextPath.length() > 0) {
|
||||
if ("/".equals(contextPath)) {
|
||||
@@ -111,7 +119,6 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
|
||||
"ContextPath must start with '/ and not end with '/'");
|
||||
}
|
||||
}
|
||||
this.contextPath = contextPath;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,10 +138,14 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
|
||||
*/
|
||||
@Override
|
||||
public void setPort(int port) {
|
||||
checkPort(port);
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
private void checkPort(int port) {
|
||||
if (port < 0 || port > 65535) {
|
||||
throw new IllegalArgumentException("Port must be between 1 and 65535");
|
||||
}
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -333,32 +344,33 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
|
||||
* warning and returning {@code null} otherwise.
|
||||
*/
|
||||
protected final File getValidDocumentRoot() {
|
||||
|
||||
// User specified
|
||||
if (getDocumentRoot() != null) {
|
||||
return getDocumentRoot();
|
||||
File file = getDocumentRoot();
|
||||
file = file != null ? file : getWarFileDocumentRoot();
|
||||
file = file != null ? file : getCommonDocumentRoot();
|
||||
if (file == null && this.logger.isWarnEnabled()) {
|
||||
this.logger.warn("None of the document roots "
|
||||
+ Arrays.asList(COMMON_DOC_ROOTS)
|
||||
+ " point to a directory and will be ignored.");
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
// Packaged as a WAR file
|
||||
private File getWarFileDocumentRoot() {
|
||||
File warFile = getCodeSourceArchive();
|
||||
if (warFile.exists() && !warFile.isDirectory()
|
||||
&& warFile.getName().toLowerCase().endsWith(".war")) {
|
||||
return warFile.getAbsoluteFile();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Common DocRoots
|
||||
private File getCommonDocumentRoot() {
|
||||
for (String commonDocRoot : COMMON_DOC_ROOTS) {
|
||||
File root = new File(commonDocRoot);
|
||||
if (root != null && root.exists() && root.isDirectory()) {
|
||||
return root.getAbsoluteFile();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.logger.isWarnEnabled()) {
|
||||
this.logger.warn("None of the document roots "
|
||||
+ Arrays.asList(COMMON_DOC_ROOTS)
|
||||
+ " point to a directory and will be ignored.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -379,7 +391,7 @@ public abstract class AbstractEmbeddedServletContainerFactory implements
|
||||
}
|
||||
return new File(path);
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (IOException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.zero.context.embedded;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.BeanNameGenerator;
|
||||
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
|
||||
@@ -152,7 +153,7 @@ public class AnnotationConfigEmbeddedWebApplicationContext extends
|
||||
* @see #scan(String...)
|
||||
* @see #refresh()
|
||||
*/
|
||||
public void register(Class<?>... annotatedClasses) {
|
||||
public final void register(Class<?>... annotatedClasses) {
|
||||
this.annotatedClasses = annotatedClasses;
|
||||
Assert.notEmpty(annotatedClasses,
|
||||
"At least one annotated class must be specified");
|
||||
@@ -165,7 +166,7 @@ public class AnnotationConfigEmbeddedWebApplicationContext extends
|
||||
* @see #register(Class...)
|
||||
* @see #refresh()
|
||||
*/
|
||||
public void scan(String... basePackages) {
|
||||
public final void scan(String... basePackages) {
|
||||
this.basePackages = basePackages;
|
||||
Assert.notEmpty(basePackages, "At least one base package must be specified");
|
||||
}
|
||||
@@ -187,4 +188,9 @@ public class AnnotationConfigEmbeddedWebApplicationContext extends
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void refresh() throws BeansException, IllegalStateException {
|
||||
super.refresh();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.zero.context.embedded;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -136,9 +136,9 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext
|
||||
try {
|
||||
getSelfInitializer().onStartup(getServletContext());
|
||||
}
|
||||
catch (ServletException e) {
|
||||
catch (ServletException ex) {
|
||||
throw new ApplicationContextException(
|
||||
"Cannot initialize servlet context", e);
|
||||
"Cannot initialize servlet context", ex);
|
||||
}
|
||||
}
|
||||
WebApplicationContextUtils.registerWebApplicationScopes(getBeanFactory(),
|
||||
|
||||
@@ -84,8 +84,13 @@ public class FilterRegistrationBean extends RegistrationBean {
|
||||
*/
|
||||
public FilterRegistrationBean(Filter filter,
|
||||
ServletRegistrationBean... servletRegistrationBeans) {
|
||||
setFilter(filter);
|
||||
addServletRegistrationBeans(servletRegistrationBeans);
|
||||
Assert.notNull(filter, "Filter must not be null");
|
||||
Assert.notNull(servletRegistrationBeans,
|
||||
"ServletRegistrationBeans must not be null");
|
||||
this.filter = filter;
|
||||
for (ServletRegistrationBean servletRegistrationBean : servletRegistrationBeans) {
|
||||
this.servletRegistrationBeans.add(servletRegistrationBean);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -69,8 +69,10 @@ public class ServletRegistrationBean extends RegistrationBean {
|
||||
* @param urlMappings the URLs being mapped
|
||||
*/
|
||||
public ServletRegistrationBean(Servlet servlet, String... urlMappings) {
|
||||
setServlet(servlet);
|
||||
addUrlMappings(urlMappings);
|
||||
Assert.notNull(servlet, "Servlet must not be null");
|
||||
Assert.notNull(urlMappings, "UrlMappings must not be null");
|
||||
this.servlet = servlet;
|
||||
this.urlMappings.addAll(Arrays.asList(urlMappings));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.zero.context.embedded;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
@@ -46,7 +47,7 @@ public class XmlEmbeddedWebApplicationContext extends EmbeddedWebApplicationCont
|
||||
* {@linkplain #load loaded} and then manually {@link #refresh refreshed}.
|
||||
*/
|
||||
public XmlEmbeddedWebApplicationContext() {
|
||||
reader.setEnvironment(this.getEnvironment());
|
||||
this.reader.setEnvironment(this.getEnvironment());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,7 +106,7 @@ public class XmlEmbeddedWebApplicationContext extends EmbeddedWebApplicationCont
|
||||
* Load bean definitions from the given XML resources.
|
||||
* @param resources one or more resources to load from
|
||||
*/
|
||||
public void load(Resource... resources) {
|
||||
public final void load(Resource... resources) {
|
||||
this.reader.loadBeanDefinitions(resources);
|
||||
}
|
||||
|
||||
@@ -113,7 +114,7 @@ public class XmlEmbeddedWebApplicationContext extends EmbeddedWebApplicationCont
|
||||
* Load bean definitions from the given XML resources.
|
||||
* @param resourceLocations one or more resource locations to load from
|
||||
*/
|
||||
public void load(String... resourceLocations) {
|
||||
public final void load(String... resourceLocations) {
|
||||
this.reader.loadBeanDefinitions(resourceLocations);
|
||||
}
|
||||
|
||||
@@ -123,11 +124,16 @@ public class XmlEmbeddedWebApplicationContext extends EmbeddedWebApplicationCont
|
||||
* specified resource name
|
||||
* @param resourceNames relatively-qualified names of resources to load
|
||||
*/
|
||||
public void load(Class<?> relativeClass, String... resourceNames) {
|
||||
public final void load(Class<?> relativeClass, String... resourceNames) {
|
||||
Resource[] resources = new Resource[resourceNames.length];
|
||||
for (int i = 0; i < resourceNames.length; i++) {
|
||||
resources[i] = new ClassPathResource(resourceNames[i], relativeClass);
|
||||
}
|
||||
this.load(resources);
|
||||
this.reader.loadBeanDefinitions(resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void refresh() throws BeansException, IllegalStateException {
|
||||
super.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,8 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
|
||||
try {
|
||||
this.tomcat.stop();
|
||||
}
|
||||
catch (LifecycleException e) {
|
||||
catch (LifecycleException ex) {
|
||||
// swallow and continue
|
||||
}
|
||||
this.tomcat.destroy();
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ import org.springframework.core.env.PropertiesPropertySource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.PropertiesLoaderUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.zero.config.YamlPropertiesFactoryBean;
|
||||
import org.springframework.zero.config.YamlProcessor.ArrayDocumentMatcher;
|
||||
import org.springframework.zero.config.YamlProcessor.DocumentMatcher;
|
||||
import org.springframework.zero.config.YamlProcessor.MatchStatus;
|
||||
import org.springframework.zero.config.YamlPropertiesFactoryBean;
|
||||
|
||||
/**
|
||||
* {@link ApplicationContextInitializer} that configures the context environment by
|
||||
@@ -82,7 +82,7 @@ public class ConfigFileApplicationContextInitializer implements
|
||||
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext applicationContext) {
|
||||
List<String> candidates = getCandidateLocations(applicationContext);
|
||||
List<String> candidates = getCandidateLocations();
|
||||
|
||||
// Initial load allows profiles to be activated
|
||||
for (String candidate : candidates) {
|
||||
@@ -97,8 +97,7 @@ public class ConfigFileApplicationContextInitializer implements
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getCandidateLocations(
|
||||
ConfigurableApplicationContext applicationContext) {
|
||||
private List<String> getCandidateLocations() {
|
||||
List<String> candidates = new ArrayList<String>();
|
||||
for (String searchLocation : this.searchLocations) {
|
||||
for (Loader loader : LOADERS) {
|
||||
@@ -150,7 +149,7 @@ public class ConfigFileApplicationContextInitializer implements
|
||||
* Set the search locations that will be considered.
|
||||
*/
|
||||
public void setSearchLocations(String[] searchLocations) {
|
||||
this.searchLocations = searchLocations;
|
||||
this.searchLocations = (searchLocations == null ? null : searchLocations.clone());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,9 +199,9 @@ public class ConfigFileApplicationContextInitializer implements
|
||||
.getDescription(), properties));
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("Could not load properties file from "
|
||||
+ resource, e);
|
||||
+ resource, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -171,14 +171,10 @@ public class LoggingApplicationContextInitializer implements
|
||||
try {
|
||||
doInit(applicationContext, configLocation);
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
throw ex;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Cannot initialize logging from "
|
||||
+ configLocation, ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected abstract void doInit(ApplicationContext applicationContext,
|
||||
|
||||
@@ -41,15 +41,12 @@ public abstract class JavaLoggerConfigurer {
|
||||
LogManager.getLogManager().readConfiguration(
|
||||
ResourceUtils.getURL(resolvedLocation).openStream());
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
if (ex instanceof FileNotFoundException) {
|
||||
throw (FileNotFoundException) ex;
|
||||
}
|
||||
throw new IllegalArgumentException("Could not initialize logging from "
|
||||
+ location, e);
|
||||
+ location, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,9 +48,9 @@ public abstract class LogbackConfigurer {
|
||||
try {
|
||||
new ContextInitializer(context).configureByResource(url);
|
||||
}
|
||||
catch (JoranException e) {
|
||||
catch (JoranException ex) {
|
||||
throw new IllegalArgumentException("Could not initialize logging from "
|
||||
+ location, e);
|
||||
+ location, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2012-2013 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.zero.web;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
@@ -28,8 +44,7 @@ import org.springframework.zero.context.embedded.AnnotationConfigEmbeddedWebAppl
|
||||
*/
|
||||
public abstract class SpringServletInitializer implements WebApplicationInitializer {
|
||||
|
||||
/** Logger available to subclasses. */
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
private final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
@Override
|
||||
public void onStartup(ServletContext servletContext) throws ServletException {
|
||||
@@ -44,9 +59,9 @@ public abstract class SpringServletInitializer implements WebApplicationInitiali
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.logger
|
||||
.debug("No ContextLoaderListener registered, as "
|
||||
+ "createRootApplicationContext() did not return an application context");
|
||||
this.logger.debug("No ContextLoaderListener registered, as "
|
||||
+ "createRootApplicationContext() did not "
|
||||
+ "return an application context");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +70,7 @@ public abstract class SpringServletInitializer implements WebApplicationInitiali
|
||||
ApplicationContext parent = null;
|
||||
Object object = servletContext
|
||||
.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
|
||||
if (object != null && object instanceof ApplicationContext) {
|
||||
if (object instanceof ApplicationContext) {
|
||||
this.logger.info("Root context already created (using as parent).");
|
||||
parent = (ApplicationContext) object;
|
||||
servletContext.setAttribute(
|
||||
|
||||
@@ -23,9 +23,11 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
|
||||
/**
|
||||
* General test utilities.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class TestUtils {
|
||||
public abstract class TestUtils {
|
||||
|
||||
public static void addEnviroment(ConfigurableApplicationContext context,
|
||||
String... pairs) {
|
||||
|
||||
@@ -24,11 +24,11 @@ import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.validation.DataBinder;
|
||||
import org.springframework.zero.bind.PropertySourcesPropertyValues;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests for {@link PropertySourcesPropertyValues}.
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class PropertySourcesPropertyValuesTests {
|
||||
|
||||
@@ -28,12 +28,13 @@ import org.springframework.context.support.StaticMessageSource;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.Validator;
|
||||
import org.springframework.validation.beanvalidation.SpringValidatorAdapter;
|
||||
import org.springframework.zero.bind.YamlConfigurationFactory;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests for {@link YamlConfigurationFactory}
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class YamlConfigurationFactoryTests {
|
||||
|
||||
@@ -13,14 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.zero.config;
|
||||
|
||||
import org.springframework.zero.config.JacksonJsonParser;
|
||||
import org.springframework.zero.config.JsonParser;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* Tests for {@link JsonParser}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class JacksonParserTests extends SimpleJsonParserTests {
|
||||
|
||||
|
||||
@@ -13,20 +13,20 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.zero.config;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.zero.config.JsonParser;
|
||||
import org.springframework.zero.config.SimpleJsonParser;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* Tests for {@link SimpleJsonParser}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class SimpleJsonParserTests {
|
||||
|
||||
|
||||
@@ -13,16 +13,16 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.zero.config;
|
||||
|
||||
import org.springframework.zero.config.JsonParser;
|
||||
import org.springframework.zero.config.YamlJsonParser;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* Tests for {@link YamlJsonParser}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class YamlParserTests extends SimpleJsonParserTests {
|
||||
public class YamlJsonParserTests extends SimpleJsonParserTests {
|
||||
|
||||
@Override
|
||||
protected JsonParser getParser() {
|
||||
@@ -25,12 +25,13 @@ import org.springframework.core.io.AbstractResource;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.zero.config.YamlMapFactoryBean;
|
||||
import org.springframework.zero.config.YamlProcessor.ResolutionMethod;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests for {@link YamlMapFactoryBean}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class YamlMapFactoryBeanTests {
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.junit.Test;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.zero.config.YamlPropertiesFactoryBean;
|
||||
import org.springframework.zero.config.YamlProcessor.DocumentMatcher;
|
||||
import org.springframework.zero.config.YamlProcessor.MatchStatus;
|
||||
import org.springframework.zero.config.YamlProcessor.ResolutionMethod;
|
||||
@@ -34,6 +33,8 @@ import org.yaml.snakeyaml.Yaml;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests for {@link YamlPropertiesFactoryBean}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class YamlPropertiesFactoryBeanTests {
|
||||
|
||||
@@ -28,6 +28,8 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for {@link OnClassCondition}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class OnClassConditionTests {
|
||||
|
||||
@@ -20,13 +20,14 @@ import org.junit.Test;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.zero.context.condition.ConditionalOnExpression;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for {@link OnExpressionCondition}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class OnExpressionConditionTests {
|
||||
|
||||
@@ -26,6 +26,8 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for {@link OnMissingClassCondition}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class OnMissingClassConditionTests {
|
||||
|
||||
@@ -28,9 +28,11 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for {@link OnNotWebApplicationCondition}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class NotWebApplicationConditionTests {
|
||||
public class OnNotWebApplicationConditionTests {
|
||||
|
||||
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
|
||||
@@ -20,13 +20,14 @@ import org.junit.Test;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.zero.context.condition.ConditionalOnResource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for {@link OnResourceCondition}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class OnResourceConditionTests {
|
||||
|
||||
@@ -29,9 +29,11 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for {@link OnWebApplicationCondition}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class WebApplicationConditionTests {
|
||||
public class OnWebApplicationConditionTests {
|
||||
|
||||
private AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
||||
|
||||
@@ -80,7 +80,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
||||
try {
|
||||
this.container.stop();
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,19 +13,20 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.zero.context.initializer;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.zero.TestUtils;
|
||||
import org.springframework.zero.context.initializer.ContextIdApplicationContextInitializer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* Tests for {@link ContextIdApplicationContextInitializer}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class ContextIdApplicationContextInitializerTests {
|
||||
|
||||
|
||||
@@ -13,19 +13,20 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.zero.context.initializer;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.zero.TestUtils;
|
||||
import org.springframework.zero.context.initializer.VcapApplicationContextInitializer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* Tests for {@link VcapApplicationContextInitializer}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class VcapApplicationContextInitializerTests {
|
||||
|
||||
|
||||
@@ -25,11 +25,12 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.zero.logging.JavaLoggerConfigurer;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for {@link JavaLoggerConfigurer}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class JavaLoggerConfigurerTests {
|
||||
|
||||
@@ -29,6 +29,8 @@ import org.junit.Test;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for {@link LogbackConfigurer}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class LogbackConfigurerTests {
|
||||
|
||||
@@ -32,9 +32,11 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for {@link LoggingApplicationContextInitializer}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class LoggingInitializerTests {
|
||||
public class LoggingApplicationContextInitializerTests {
|
||||
|
||||
private LoggingApplicationContextInitializer initializer = new LoggingApplicationContextInitializer();
|
||||
|
||||
@@ -65,7 +67,7 @@ public class LoggingInitializerTests {
|
||||
public void testDefaultConfigLocation() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
this.initializer.initialize(context);
|
||||
Log logger = LogFactory.getLog(LoggingInitializerTests.class);
|
||||
Log logger = LogFactory.getLog(LoggingApplicationContextInitializerTests.class);
|
||||
logger.info("Hello world");
|
||||
String output = getOutput().trim();
|
||||
assertTrue("Wrong output:\n" + output, output.contains("Hello world"));
|
||||
@@ -87,7 +89,7 @@ public class LoggingInitializerTests {
|
||||
}
|
||||
});
|
||||
this.initializer.initialize(context);
|
||||
Log logger = LogFactory.getLog(LoggingInitializerTests.class);
|
||||
Log logger = LogFactory.getLog(LoggingApplicationContextInitializerTests.class);
|
||||
logger.info("Hello world");
|
||||
String output = getOutput().trim();
|
||||
assertTrue("Wrong output:\n" + output, output.contains("Hello world"));
|
||||
@@ -112,7 +114,7 @@ public class LoggingInitializerTests {
|
||||
}
|
||||
});
|
||||
this.initializer.initialize(context);
|
||||
Log logger = LogFactory.getLog(LoggingInitializerTests.class);
|
||||
Log logger = LogFactory.getLog(LoggingApplicationContextInitializerTests.class);
|
||||
logger.info("Hello world");
|
||||
String output = getOutput().trim();
|
||||
assertTrue("Wrong output:\n" + output, output.startsWith("foo.log"));
|
||||
@@ -135,7 +137,7 @@ public class LoggingInitializerTests {
|
||||
}
|
||||
});
|
||||
this.initializer.initialize(context);
|
||||
Log logger = LogFactory.getLog(LoggingInitializerTests.class);
|
||||
Log logger = LogFactory.getLog(LoggingApplicationContextInitializerTests.class);
|
||||
logger.info("Hello world");
|
||||
String output = getOutput().trim();
|
||||
assertTrue("Wrong output:\n" + output, output.startsWith("foo/springzero.log"));
|
||||
@@ -20,6 +20,8 @@ import java.util.logging.Formatter;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
/**
|
||||
* Simple test {@link Formatter}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class TestFormatter extends Formatter {
|
||||
|
||||
Reference in New Issue
Block a user