Browse Source

Polish

pull/172/head
Phillip Webb 12 years ago
parent
commit
513c6a1de2
  1. 10
      spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpoint.java
  2. 3
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersAutoConfiguration.java
  3. 2
      spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersTests.java
  4. 2
      spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/JreProxySelector.java
  5. 8
      spring-boot-samples/spring-boot-sample-actuator-log4j/README.md
  6. 5
      spring-boot-samples/spring-boot-sample-actuator-log4j/src/test/java/org/springframework/boot/sample/actuator/log4j/SampleActuatorApplicationTests.java
  7. 3
      spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryTests.java
  8. 7
      spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfiguration.java
  9. 47
      spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationContextLoader.java

10
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpoint.java

@ -57,7 +57,7 @@ public class ConfigurationPropertiesReportEndpoint extends @@ -57,7 +57,7 @@ public class ConfigurationPropertiesReportEndpoint extends
return this.keysToSanitize;
}
public void setKeysToSanitize(String[] keysToSanitize) {
public void setKeysToSanitize(String... keysToSanitize) {
Assert.notNull(keysToSanitize, "KeysToSanitize must not be null");
this.keysToSanitize = keysToSanitize;
}
@ -69,10 +69,10 @@ public class ConfigurationPropertiesReportEndpoint extends @@ -69,10 +69,10 @@ public class ConfigurationPropertiesReportEndpoint extends
.getBeansWithAnnotation(ConfigurationProperties.class);
// Serialize beans into map structure and sanitize values
ObjectMapper mapper = new ObjectMapper();
for (Map.Entry<String, Object> entry : beans.entrySet()) {
ObjectMapper m = new ObjectMapper();
beans.put(entry.getKey(),
sanitize(m.convertValue(entry.getValue(), Map.class)));
Map<String, Object> value = mapper.convertValue(entry.getValue(), Map.class);
beans.put(entry.getKey(), sanitize(value));
}
return beans;
@ -94,7 +94,7 @@ public class ConfigurationPropertiesReportEndpoint extends @@ -94,7 +94,7 @@ public class ConfigurationPropertiesReportEndpoint extends
private Object sanitize(String name, Object object) {
for (String keyToSanitize : this.keysToSanitize) {
if (name.toLowerCase().endsWith(keyToSanitize)) {
return object == null ? null : "******";
return (object == null ? null : "******");
}
}
return object;

3
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersAutoConfiguration.java

@ -26,6 +26,7 @@ import javax.annotation.PostConstruct; @@ -26,6 +26,7 @@ import javax.annotation.PostConstruct;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@ -39,6 +40,8 @@ import com.fasterxml.jackson.databind.Module; @@ -39,6 +40,8 @@ import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* {@link EnableAutoConfiguration Auto-configuration} for {@link HttpMessageConverter}s.
*
* @author Dave Syer
*/
@Configuration

2
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersTests.java

@ -39,6 +39,8 @@ import static org.junit.Assert.assertTrue; @@ -39,6 +39,8 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link HttpMessageConverters}.
*
* @author Dave Syer
* @author Phillip Webb
*/

2
spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/JreProxySelector.java

@ -35,8 +35,6 @@ import org.eclipse.aether.repository.RemoteRepository; @@ -35,8 +35,6 @@ import org.eclipse.aether.repository.RemoteRepository;
/**
* (Copied from aether source code - not available yet in Maven repo.)
*
* @author dsyer
*/
public final class JreProxySelector implements ProxySelector {

8
spring-boot-samples/spring-boot-sample-actuator-log4j/README.md

@ -1,5 +1,4 @@ @@ -1,5 +1,4 @@
# Spring Boot Actuator Sample
You can build this sample using Maven (>3) or Gradle (1.6).
With Maven:
@ -9,7 +8,8 @@ $ mvn package @@ -9,7 +8,8 @@ $ mvn package
$ java -jar target/*.jar
```
Then access the app via a browser (or curl) on http://localhost:8080 (the user name is "user" and look at the INFO log output for the password to login).
Then access the app via a browser (or curl) on http://localhost:8080 (the user name is
"user" and look at the INFO log output for the password to login).
With gradle:
@ -18,4 +18,6 @@ $ gradle build @@ -18,4 +18,6 @@ $ gradle build
$ java -jar build/libs/*.jar
```
The gradle build contains an intentionally odd configuration to exclude the security dependencies from the executable JAR. So the app run like this behaves differently than the one run from the Maven-built JAR file. See comments in the `build.gradle` for details.
The gradle build contains an intentionally odd configuration to exclude the security
dependencies from the executable JAR. So the app run like this behaves differently than
the one run from the Maven-built JAR file. See comments in the `build.gradle` for details.

5
spring-boot-samples/spring-boot-sample-actuator-log4j/src/test/java/org/springframework/boot/sample/actuator/log4j/SampleActuatorApplicationTests.java

@ -16,8 +16,6 @@ @@ -16,8 +16,6 @@
package org.springframework.boot.sample.actuator.log4j;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.Callable;
@ -36,6 +34,8 @@ import org.springframework.http.client.ClientHttpResponse; @@ -36,6 +34,8 @@ import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.assertEquals;
/**
* Basic integration tests for service demo application.
*
@ -77,7 +77,6 @@ public class SampleActuatorApplicationTests { @@ -77,7 +77,6 @@ public class SampleActuatorApplicationTests {
assertEquals("Hello Phil", body.get("message"));
}
private RestTemplate getRestTemplate() {
RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {

3
spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryTests.java

@ -68,7 +68,6 @@ public class PropertiesConfigurationFactoryTests { @@ -68,7 +68,6 @@ public class PropertiesConfigurationFactoryTests {
assertEquals("blah", foo.name);
}
@Test
public void testUnderscore() throws Exception {
Foo foo = createFoo("spring_foo_baz: blah\nname: blah");
@ -141,7 +140,7 @@ public class PropertiesConfigurationFactoryTests { @@ -141,7 +140,7 @@ public class PropertiesConfigurationFactoryTests {
private String spring_foo_baz;
public String getSpringFooBaz() {
return spring_foo_baz;
return this.spring_foo_baz;
}
public void setSpringFooBaz(String spring_foo_baz) {

7
spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfiguration.java

@ -28,9 +28,14 @@ import org.springframework.context.ConfigurableApplicationContext; @@ -28,9 +28,14 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.ContextConfiguration;
/**
* Class-level annotation that is used to determine how to load and configure an
* ApplicationContext for integration tests. Similar to the standard
* {@link ContextConfiguration} but uses Spring Boot's
* {@link SpringApplicationContextLoader}.
*
* @author Dave Syer
* @see SpringApplicationContextLoader
*/
@ContextConfiguration(loader = SpringApplicationContextLoader.class)
@Documented
@Inherited

47
spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationContextLoader.java

@ -58,27 +58,15 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { @@ -58,27 +58,15 @@ public class SpringApplicationContextLoader extends AbstractContextLoader {
public ApplicationContext loadContext(MergedContextConfiguration mergedConfig)
throws Exception {
Set<Object> sources = new LinkedHashSet<Object>();
sources.addAll(Arrays.asList(mergedConfig.getClasses()));
sources.addAll(Arrays.asList(mergedConfig.getLocations()));
SpringApplication application = new SpringApplication();
application.setSources(sources);
Map<String, Object> args = new LinkedHashMap<String, Object>();
application.setSources(getSources(mergedConfig));
if (!ObjectUtils.isEmpty(mergedConfig.getActiveProfiles())) {
application.setAdditionalProfiles(Arrays.asList(mergedConfig
.getActiveProfiles()));
}
// Not running an embedded server, just setting up web context
args.put("server.port", "0");
args.put("management.port", "0");
application.setDefaultProperties(args);
List<ApplicationContextInitializer<?>> initializers = new ArrayList<ApplicationContextInitializer<?>>(
application.getInitializers());
for (Class<? extends ApplicationContextInitializer<?>> type : mergedConfig
.getContextInitializerClasses()) {
initializers.add(BeanUtils.instantiate(type));
}
application.setDefaultProperties(getArgs(mergedConfig));
List<ApplicationContextInitializer<?>> initializers = getInitializers(
mergedConfig, application);
if (mergedConfig instanceof WebMergedContextConfiguration) {
new WebConfigurer().setup(mergedConfig, application, initializers);
}
@ -86,9 +74,36 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { @@ -86,9 +74,36 @@ public class SpringApplicationContextLoader extends AbstractContextLoader {
application.setWebEnvironment(false);
}
application.setInitializers(initializers);
return application.run();
}
private Set<Object> getSources(MergedContextConfiguration mergedConfig) {
Set<Object> sources = new LinkedHashSet<Object>();
sources.addAll(Arrays.asList(mergedConfig.getClasses()));
sources.addAll(Arrays.asList(mergedConfig.getLocations()));
return sources;
}
private Map<String, Object> getArgs(MergedContextConfiguration mergedConfig) {
Map<String, Object> args = new LinkedHashMap<String, Object>();
// Not running an embedded server, just setting up web context
args.put("server.port", "0");
args.put("management.port", "0");
return args;
}
private List<ApplicationContextInitializer<?>> getInitializers(
MergedContextConfiguration mergedConfig, SpringApplication application) {
List<ApplicationContextInitializer<?>> initializers = new ArrayList<ApplicationContextInitializer<?>>();
initializers.addAll(application.getInitializers());
for (Class<? extends ApplicationContextInitializer<?>> initializerClass : mergedConfig
.getContextInitializerClasses()) {
initializers.add(BeanUtils.instantiate(initializerClass));
}
return initializers;
}
@Override
public ApplicationContext loadContext(String... locations) throws Exception {
throw new UnsupportedOperationException(

Loading…
Cancel
Save