Polish
This commit is contained in:
parent
796d400318
commit
324a00fd6d
|
|
@ -100,7 +100,8 @@ public class EndpointEnablementProvider {
|
|||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
boolean enablement = determineGlobalDefaultEnablement(defaultEnablement, exposure);
|
||||
boolean enablement = determineGlobalDefaultEnablement(defaultEnablement,
|
||||
exposure);
|
||||
String message = determineGlobalDefaultMessage(endpointId, enablement, exposure,
|
||||
defaultEnablement);
|
||||
return new EndpointEnablement(enablement, message);
|
||||
|
|
|
|||
|
|
@ -61,15 +61,16 @@ public class ConfigurationPropertiesReportEndpointAutoConfigurationTests {
|
|||
@Test
|
||||
public void keysToSanitizeCanBeConfiguredViaTheEnvironment() throws Exception {
|
||||
this.contextRunner.withUserConfiguration(Config.class)
|
||||
.withPropertyValues("endpoints.configprops.keys-to-sanitize: .*pass.*, property")
|
||||
.withPropertyValues(
|
||||
"endpoints.configprops.keys-to-sanitize: .*pass.*, property")
|
||||
.run(validateTestProperties("******", "******"));
|
||||
}
|
||||
|
||||
private ContextConsumer<AssertableApplicationContext> validateTestProperties(String dbPassword,
|
||||
String myTestProperty) {
|
||||
private ContextConsumer<AssertableApplicationContext> validateTestProperties(
|
||||
String dbPassword, String myTestProperty) {
|
||||
return context -> {
|
||||
assertThat(context).hasSingleBean(
|
||||
ConfigurationPropertiesReportEndpoint.class);
|
||||
assertThat(context)
|
||||
.hasSingleBean(ConfigurationPropertiesReportEndpoint.class);
|
||||
ConfigurationPropertiesReportEndpoint endpoint = context
|
||||
.getBean(ConfigurationPropertiesReportEndpoint.class);
|
||||
ConfigurationPropertiesDescriptor properties = endpoint
|
||||
|
|
@ -94,7 +95,7 @@ public class ConfigurationPropertiesReportEndpointAutoConfigurationTests {
|
|||
}
|
||||
|
||||
@ConfigurationProperties("test")
|
||||
private static class TestProperties {
|
||||
static class TestProperties {
|
||||
|
||||
private String dbPassword = "123456";
|
||||
|
||||
|
|
|
|||
|
|
@ -127,16 +127,14 @@ public class EndpointEnablementProviderTests {
|
|||
public void defaultEnablementNeutral() {
|
||||
EndpointEnablement enablement = getEndpointEnablement("biz",
|
||||
DefaultEnablement.NEUTRAL);
|
||||
validate(enablement, true,
|
||||
"endpoint 'biz' is enabled (default)");
|
||||
validate(enablement, true, "endpoint 'biz' is enabled (default)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultEnablementNeutralWeb() {
|
||||
EndpointEnablement enablement = getEndpointEnablement("biz",
|
||||
DefaultEnablement.NEUTRAL, EndpointExposure.WEB);
|
||||
validate(enablement, false,
|
||||
"endpoint 'default' (web) is disabled by default");
|
||||
validate(enablement, false, "endpoint 'default' (web) is disabled by default");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -151,8 +149,7 @@ public class EndpointEnablementProviderTests {
|
|||
public void defaultEnablementNeutralWithGeneralDisablement() {
|
||||
EndpointEnablement enablement = getEndpointEnablement("biz",
|
||||
DefaultEnablement.NEUTRAL, "endpoints.default.enabled=false");
|
||||
validate(enablement, false,
|
||||
"found property endpoints.default.enabled");
|
||||
validate(enablement, false, "found property endpoints.default.enabled");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -160,18 +157,15 @@ public class EndpointEnablementProviderTests {
|
|||
EndpointEnablement enablement = getEndpointEnablement("biz",
|
||||
DefaultEnablement.NEUTRAL, EndpointExposure.JMX,
|
||||
"endpoints.default.jmx.enabled=false");
|
||||
validate(enablement, false,
|
||||
"found property endpoints.default.jmx.enabled");
|
||||
validate(enablement, false, "found property endpoints.default.jmx.enabled");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultEnablementNeutralTechTakesPrecedence() {
|
||||
EndpointEnablement enablement = getEndpointEnablement("biz",
|
||||
DefaultEnablement.NEUTRAL, EndpointExposure.JMX,
|
||||
"endpoints.default.enabled=true",
|
||||
"endpoints.default.jmx.enabled=false");
|
||||
validate(enablement, false,
|
||||
"found property endpoints.default.jmx.enabled");
|
||||
"endpoints.default.enabled=true", "endpoints.default.jmx.enabled=false");
|
||||
validate(enablement, false, "found property endpoints.default.jmx.enabled");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -179,8 +173,7 @@ public class EndpointEnablementProviderTests {
|
|||
EndpointEnablement enablement = getEndpointEnablement("biz",
|
||||
DefaultEnablement.NEUTRAL, EndpointExposure.WEB,
|
||||
"endpoints.default.web.enabled=true");
|
||||
validate(enablement, true,
|
||||
"found property endpoints.default.web.enabled");
|
||||
validate(enablement, true, "found property endpoints.default.web.enabled");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -196,8 +189,7 @@ public class EndpointEnablementProviderTests {
|
|||
public void defaultEnablementNeutralWithOverride() {
|
||||
EndpointEnablement enablement = getEndpointEnablement("biz",
|
||||
DefaultEnablement.NEUTRAL, "endpoints.biz.enabled=false");
|
||||
validate(enablement, false,
|
||||
"found property endpoints.biz.enabled");
|
||||
validate(enablement, false, "found property endpoints.biz.enabled");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -205,8 +197,7 @@ public class EndpointEnablementProviderTests {
|
|||
EndpointEnablement enablement = getEndpointEnablement("biz",
|
||||
DefaultEnablement.NEUTRAL, EndpointExposure.WEB,
|
||||
"endpoints.biz.web.enabled=true");
|
||||
validate(enablement, true,
|
||||
"found property endpoints.biz.web.enabled");
|
||||
validate(enablement, true, "found property endpoints.biz.web.enabled");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -214,41 +205,33 @@ public class EndpointEnablementProviderTests {
|
|||
EndpointEnablement enablement = getEndpointEnablement("biz",
|
||||
DefaultEnablement.NEUTRAL, EndpointExposure.JMX,
|
||||
"endpoints.biz.jmx.enabled=false");
|
||||
validate(enablement, false,
|
||||
"found property endpoints.biz.jmx.enabled");
|
||||
validate(enablement, false, "found property endpoints.biz.jmx.enabled");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultEnablementNeutralTechTakesPrecedenceOnEverything() {
|
||||
EndpointEnablement enablement = getEndpointEnablement("biz",
|
||||
DefaultEnablement.NEUTRAL, EndpointExposure.JMX,
|
||||
"endpoints.default.enabled=false",
|
||||
"endpoints.default.jmx.enabled=false",
|
||||
"endpoints.biz.enabled=false",
|
||||
"endpoints.biz.jmx.enabled=true");
|
||||
validate(enablement, true,
|
||||
"found property endpoints.biz.jmx.enabled");
|
||||
"endpoints.default.enabled=false", "endpoints.default.jmx.enabled=false",
|
||||
"endpoints.biz.enabled=false", "endpoints.biz.jmx.enabled=true");
|
||||
validate(enablement, true, "found property endpoints.biz.jmx.enabled");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultEnablementNeutralSpecificTakesPrecedenceOnDefaults() {
|
||||
EndpointEnablement enablement = getEndpointEnablement("biz",
|
||||
DefaultEnablement.NEUTRAL, EndpointExposure.JMX,
|
||||
"endpoints.default.enabled=false",
|
||||
"endpoints.default.jmx.enabled=false",
|
||||
"endpoints.default.enabled=false", "endpoints.default.jmx.enabled=false",
|
||||
"endpoints.biz.enabled=true");
|
||||
validate(enablement, true,
|
||||
"found property endpoints.biz.enabled");
|
||||
validate(enablement, true, "found property endpoints.biz.enabled");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultEnablementNeutralDefaultTechTakesPrecedenceOnGeneralDefault() {
|
||||
EndpointEnablement enablement = getEndpointEnablement("biz",
|
||||
DefaultEnablement.NEUTRAL, EndpointExposure.JMX,
|
||||
"endpoints.default.enabled=false",
|
||||
"endpoints.default.jmx.enabled=true");
|
||||
validate(enablement, true,
|
||||
"found property endpoints.default.jmx.enabled");
|
||||
"endpoints.default.enabled=false", "endpoints.default.jmx.enabled=true");
|
||||
validate(enablement, true, "found property endpoints.default.jmx.enabled");
|
||||
}
|
||||
|
||||
private EndpointEnablement getEndpointEnablement(String id,
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ public class EnvironmentEndpointAutoConfigurationTests {
|
|||
.doesNotHaveBean(EnvironmentEndpoint.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void keysToSanitizeCanBeConfiguredViaTheEnvironment() throws Exception {
|
||||
this.contextRunner.withSystemProperties("dbPassword=123456", "apiKey=123456")
|
||||
|
|
@ -84,5 +83,4 @@ public class EnvironmentEndpointAutoConfigurationTests {
|
|||
.filter((source) -> name.equals(source.getName())).findFirst().get();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,8 +84,8 @@ public class HealthEndpointAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void runShouldHaveStatusEndpointBeanEvenIfDefaultIsDisabled() {
|
||||
this.contextRunner.withPropertyValues("endpoints.default.enabled:false")
|
||||
.run((context) -> assertThat(context).hasSingleBean(StatusEndpoint.class));
|
||||
this.contextRunner.withPropertyValues("endpoints.default.enabled:false").run(
|
||||
(context) -> assertThat(context).hasSingleBean(StatusEndpoint.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -55,8 +55,7 @@ public class JmxEndpointIntegrationTests {
|
|||
MBeanServer mBeanServer = context.getBean(MBeanServer.class);
|
||||
checkEndpointMBeans(mBeanServer,
|
||||
new String[] { "autoconfig", "beans", "configprops", "env", "health",
|
||||
"info", "mappings", "status", "threaddump",
|
||||
"trace" },
|
||||
"info", "mappings", "status", "threaddump", "trace" },
|
||||
new String[] { "shutdown" });
|
||||
});
|
||||
}
|
||||
|
|
@ -68,8 +67,8 @@ public class JmxEndpointIntegrationTests {
|
|||
MBeanServer mBeanServer = context.getBean(MBeanServer.class);
|
||||
checkEndpointMBeans(mBeanServer, new String[0],
|
||||
new String[] { "autoconfig", "beans", "configprops", "env",
|
||||
"health", "mappings", "shutdown",
|
||||
"threaddump", "trace" });
|
||||
"health", "mappings", "shutdown", "threaddump",
|
||||
"trace" });
|
||||
|
||||
});
|
||||
}
|
||||
|
|
@ -81,8 +80,7 @@ public class JmxEndpointIntegrationTests {
|
|||
MBeanServer mBeanServer = context.getBean(MBeanServer.class);
|
||||
checkEndpointMBeans(mBeanServer, new String[] { "beans" },
|
||||
new String[] { "autoconfig", "configprops", "env", "health",
|
||||
"mappings", "shutdown",
|
||||
"threaddump", "trace" });
|
||||
"mappings", "shutdown", "threaddump", "trace" });
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ public class LogFileWebEndpointManagementContextConfigurationTests {
|
|||
@Rule
|
||||
public TemporaryFolder temp = new TemporaryFolder();
|
||||
|
||||
|
||||
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
|
||||
.withUserConfiguration(
|
||||
LogFileWebEndpointManagementContextConfiguration.class);
|
||||
|
|
@ -81,18 +80,19 @@ public class LogFileWebEndpointManagementContextConfigurationTests {
|
|||
@Test
|
||||
public void logFileWebEndpointUsesConfiguredExternalFile() throws IOException {
|
||||
File file = this.temp.newFile("logfile");
|
||||
FileCopyUtils.copy("--TEST--" .getBytes(), file);
|
||||
FileCopyUtils.copy("--TEST--".getBytes(), file);
|
||||
this.contextRunner
|
||||
.withPropertyValues("endpoints.logfile.external-file:"
|
||||
+ file.getAbsolutePath()).run((context) -> {
|
||||
.withPropertyValues(
|
||||
"endpoints.logfile.external-file:" + file.getAbsolutePath())
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(LogFileWebEndpoint.class);
|
||||
LogFileWebEndpoint endpoint = context.getBean(LogFileWebEndpoint.class);
|
||||
LogFileWebEndpoint endpoint = context
|
||||
.getBean(LogFileWebEndpoint.class);
|
||||
Resource resource = endpoint.logFile();
|
||||
assertThat(resource).isNotNull();
|
||||
assertThat(StreamUtils.copyToString(resource.getInputStream(),
|
||||
StandardCharsets.UTF_8)).isEqualTo("--TEST--");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,8 +119,8 @@ public abstract class AnnotationEndpointDiscoverer<T extends Operation, K>
|
|||
private EndpointInfo<T> createEndpointInfo(String beanName, Class<?> beanType,
|
||||
AnnotationAttributes attributes) {
|
||||
String id = attributes.getString("id");
|
||||
DefaultEnablement defaultEnablement = (DefaultEnablement) attributes.get(
|
||||
"defaultEnablement");
|
||||
DefaultEnablement defaultEnablement = (DefaultEnablement) attributes
|
||||
.get("defaultEnablement");
|
||||
Map<Method, T> operations = discoverOperations(id, beanName, beanType);
|
||||
return new EndpointInfo<>(id, defaultEnablement, operations.values());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,8 +72,8 @@ public class SecurityProperties implements SecurityPrerequisite {
|
|||
/**
|
||||
* Security filter chain dispatcher types.
|
||||
*/
|
||||
private Set<DispatcherType> dispatcherTypes = new HashSet<>(Arrays
|
||||
.asList(DispatcherType.ASYNC, DispatcherType.ERROR, DispatcherType.REQUEST));
|
||||
private Set<DispatcherType> dispatcherTypes = new HashSet<>(Arrays.asList(
|
||||
DispatcherType.ASYNC, DispatcherType.ERROR, DispatcherType.REQUEST));
|
||||
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
|
|
|
|||
|
|
@ -31,17 +31,16 @@ import org.springframework.util.ObjectUtils;
|
|||
*/
|
||||
public class NonUniqueSessionRepositoryException extends RuntimeException {
|
||||
|
||||
private final List<Class<? extends SessionRepository<?>>> availableCandidates;
|
||||
private final List<Class<?>> availableCandidates;
|
||||
|
||||
public NonUniqueSessionRepositoryException(
|
||||
List<Class<? extends SessionRepository<?>>> availableCandidates) {
|
||||
public NonUniqueSessionRepositoryException(List<Class<?>> availableCandidates) {
|
||||
super("Multiple session repository candidates are available, set the "
|
||||
+ "'spring.session.store-type' property accordingly");
|
||||
this.availableCandidates = (!ObjectUtils.isEmpty(availableCandidates)
|
||||
? availableCandidates : Collections.emptyList());
|
||||
}
|
||||
|
||||
public List<Class<? extends SessionRepository<?>>> getAvailableCandidates() {
|
||||
public List<Class<?>> getAvailableCandidates() {
|
||||
return this.availableCandidates;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.session;
|
|||
|
||||
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
|
||||
import org.springframework.boot.diagnostics.FailureAnalysis;
|
||||
import org.springframework.session.SessionRepository;
|
||||
|
||||
/**
|
||||
* A {@link AbstractFailureAnalyzer} for {@link NonUniqueSessionRepositoryException}.
|
||||
|
|
@ -34,8 +33,7 @@ class NonUniqueSessionRepositoryFailureAnalyzer
|
|||
StringBuilder message = new StringBuilder();
|
||||
message.append(String.format("Multiple Spring Session store implementations are "
|
||||
+ "available on the classpath:%n"));
|
||||
for (Class<? extends SessionRepository<?>> candidate : cause
|
||||
.getAvailableCandidates()) {
|
||||
for (Class<?> candidate : cause.getAvailableCandidates()) {
|
||||
message.append(String.format(" - %s%n", candidate.getName()));
|
||||
}
|
||||
StringBuilder action = new StringBuilder();
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ public class SessionAutoConfiguration {
|
|||
|
||||
@PostConstruct
|
||||
public void checkAvailableImplementations() {
|
||||
List<Class<? extends SessionRepository<?>>> candidates = new ArrayList<>();
|
||||
List<Class<?>> candidates = new ArrayList<>();
|
||||
addCandidate(candidates,
|
||||
"org.springframework.session.hazelcast.HazelcastSessionRepository");
|
||||
addCandidate(candidates,
|
||||
|
|
@ -119,12 +119,9 @@ public class SessionAutoConfiguration {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void addCandidate(List<Class<? extends SessionRepository<?>>> candidates,
|
||||
String fqn) {
|
||||
private void addCandidate(List<Class<?>> candidates, String type) {
|
||||
try {
|
||||
Class<? extends SessionRepository<?>> candidate = (Class<? extends SessionRepository<?>>) this.classLoader
|
||||
.loadClass(fqn);
|
||||
Class<?> candidate = this.classLoader.loadClass(type);
|
||||
if (candidate != null) {
|
||||
candidates.add(candidate);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ public class ResourceProperties {
|
|||
|
||||
private final Chain chain = new Chain();
|
||||
|
||||
|
||||
public String[] getStaticLocations() {
|
||||
return this.staticLocations;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,7 +166,8 @@ public class WebMvcAutoConfiguration {
|
|||
@Configuration
|
||||
@Import(EnableWebMvcConfiguration.class)
|
||||
@EnableConfigurationProperties({ WebMvcProperties.class, ResourceProperties.class })
|
||||
public static class WebMvcAutoConfigurationAdapter implements WebMvcConfigurer, ResourceLoaderAware {
|
||||
public static class WebMvcAutoConfigurationAdapter
|
||||
implements WebMvcConfigurer, ResourceLoaderAware {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(WebMvcConfigurer.class);
|
||||
|
||||
|
|
@ -316,8 +317,8 @@ public class WebMvcAutoConfiguration {
|
|||
if (!registry.hasMappingForPattern(staticPathPattern)) {
|
||||
customizeResourceHandlerRegistration(
|
||||
registry.addResourceHandler(staticPathPattern)
|
||||
.addResourceLocations(
|
||||
getResourceLocations(this.resourceProperties.getStaticLocations()))
|
||||
.addResourceLocations(getResourceLocations(
|
||||
this.resourceProperties.getStaticLocations()))
|
||||
.setCachePeriod(cachePeriod));
|
||||
}
|
||||
}
|
||||
|
|
@ -329,29 +330,32 @@ public class WebMvcAutoConfiguration {
|
|||
}
|
||||
|
||||
static String[] getResourceLocations(String[] staticLocations) {
|
||||
String[] locations = new String[staticLocations.length + SERVLET_LOCATIONS.length];
|
||||
String[] locations = new String[staticLocations.length
|
||||
+ SERVLET_LOCATIONS.length];
|
||||
System.arraycopy(staticLocations, 0, locations, 0, staticLocations.length);
|
||||
System.arraycopy(SERVLET_LOCATIONS, 0, locations,
|
||||
staticLocations.length, SERVLET_LOCATIONS.length);
|
||||
System.arraycopy(SERVLET_LOCATIONS, 0, locations, staticLocations.length,
|
||||
SERVLET_LOCATIONS.length);
|
||||
return locations;
|
||||
}
|
||||
|
||||
private Optional<Resource> getWelcomePage() {
|
||||
return Arrays.stream(getResourceLocations(this.resourceProperties.getStaticLocations()))
|
||||
.map(location -> this.resourceLoader.getResource(location + "index.html"))
|
||||
.filter(resource -> {
|
||||
try {
|
||||
if (resource.exists()) {
|
||||
resource.getURL();
|
||||
return true;
|
||||
String[] locations = getResourceLocations(
|
||||
this.resourceProperties.getStaticLocations());
|
||||
return Arrays.stream(locations).map(this::getIndexHtml)
|
||||
.filter(this::isReadable).findFirst();
|
||||
}
|
||||
|
||||
private Resource getIndexHtml(String location) {
|
||||
return this.resourceLoader.getResource(location + "index.html");
|
||||
}
|
||||
|
||||
private boolean isReadable(Resource resource) {
|
||||
try {
|
||||
return resource.exists() && (resource.getURL() != null);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// Ignore
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.findFirst();
|
||||
}
|
||||
}
|
||||
|
||||
private void customizeResourceHandlerRegistration(
|
||||
|
|
@ -359,7 +363,6 @@ public class WebMvcAutoConfiguration {
|
|||
if (this.resourceHandlerRegistrationCustomizer != null) {
|
||||
this.resourceHandlerRegistrationCustomizer.customize(registration);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
|
@ -403,10 +406,11 @@ public class WebMvcAutoConfiguration {
|
|||
}
|
||||
|
||||
private List<Resource> resolveFaviconLocations() {
|
||||
String[] resourceLocations = getResourceLocations(this.resourceProperties.getStaticLocations());
|
||||
List<Resource> locations = new ArrayList<>(resourceLocations.length + 1);
|
||||
Arrays.stream(resourceLocations)
|
||||
.forEach(location -> locations.add(this.resourceLoader.getResource(location)));
|
||||
String[] staticLocations = getResourceLocations(
|
||||
this.resourceProperties.getStaticLocations());
|
||||
List<Resource> locations = new ArrayList<>(staticLocations.length + 1);
|
||||
Arrays.stream(staticLocations).map(this.resourceLoader::getResource)
|
||||
.forEach(locations::add);
|
||||
locations.add(new ClassPathResource("/"));
|
||||
return Collections.unmodifiableList(locations);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,8 +121,8 @@ public class OAuth2RestOperationsConfigurationTests {
|
|||
}
|
||||
|
||||
@Configuration
|
||||
@Import({ SecurityProperties.class,
|
||||
OAuth2ClientConfiguration.class, OAuth2RestOperationsConfiguration.class })
|
||||
@Import({ SecurityProperties.class, OAuth2ClientConfiguration.class,
|
||||
OAuth2RestOperationsConfiguration.class })
|
||||
protected static class ConfigForSessionScopedConfiguration
|
||||
extends WebApplicationConfiguration {
|
||||
|
||||
|
|
|
|||
|
|
@ -52,23 +52,22 @@ public class SessionAutoConfigurationHazelcastTests
|
|||
|
||||
@Test
|
||||
public void defaultConfig() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.session.store-type=hazelcast")
|
||||
this.contextRunner.withPropertyValues("spring.session.store-type=hazelcast")
|
||||
.run(this::validateDefaultConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultConfigWithUniqueStoreImplementation() {
|
||||
this.contextRunner.withClassLoader(new HideClassesClassLoader(
|
||||
JdbcOperationsSessionRepository.class,
|
||||
RedisOperationsSessionRepository.class)).run(
|
||||
this::validateDefaultConfig);
|
||||
this.contextRunner
|
||||
.withClassLoader(
|
||||
new HideClassesClassLoader(JdbcOperationsSessionRepository.class,
|
||||
RedisOperationsSessionRepository.class))
|
||||
.run(this::validateDefaultConfig);
|
||||
}
|
||||
|
||||
private void validateDefaultConfig(AssertableWebApplicationContext context) {
|
||||
validateSessionRepository(context, HazelcastSessionRepository.class);
|
||||
HazelcastInstance hazelcastInstance = context
|
||||
.getBean(HazelcastInstance.class);
|
||||
HazelcastInstance hazelcastInstance = context.getBean(HazelcastInstance.class);
|
||||
verify(hazelcastInstance, times(1)).getMap("spring:session:sessions");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,13 +46,13 @@ public class SessionAutoConfigurationIntegrationTests
|
|||
SessionAutoConfiguration.class))
|
||||
.withPropertyValues("spring.datasource.generate-unique-name=true");
|
||||
|
||||
|
||||
@Test
|
||||
public void severalCandidatesWithNoSessionStore() {
|
||||
this.contextRunner.withUserConfiguration(HazelcastConfiguration.class).run((context) -> {
|
||||
this.contextRunner.withUserConfiguration(HazelcastConfiguration.class)
|
||||
.run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure()
|
||||
.hasCauseInstanceOf(NonUniqueSessionRepositoryException.class);
|
||||
assertThat(context).getFailure().hasCauseInstanceOf(
|
||||
NonUniqueSessionRepositoryException.class);
|
||||
assertThat(context).getFailure().hasMessageContaining(
|
||||
"Multiple session repository candidates are available");
|
||||
assertThat(context).getFailure().hasMessageContaining(
|
||||
|
|
@ -65,12 +65,12 @@ public class SessionAutoConfigurationIntegrationTests
|
|||
this.contextRunner.withUserConfiguration(HazelcastConfiguration.class)
|
||||
.withPropertyValues("spring.session.store-type=redis").run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure()
|
||||
.hasCauseInstanceOf(SessionRepositoryUnavailableException.class);
|
||||
assertThat(context).getFailure().hasCauseInstanceOf(
|
||||
SessionRepositoryUnavailableException.class);
|
||||
assertThat(context).getFailure().hasMessageContaining(
|
||||
"No session repository could be auto-configured");
|
||||
assertThat(context).getFailure().hasMessageContaining(
|
||||
"session store type is 'redis'");
|
||||
assertThat(context).getFailure()
|
||||
.hasMessageContaining("session store type is 'redis'");
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +82,6 @@ public class SessionAutoConfigurationIntegrationTests
|
|||
JdbcOperationsSessionRepository.class));
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class HazelcastConfiguration {
|
||||
|
||||
|
|
|
|||
|
|
@ -58,8 +58,7 @@ public class SessionAutoConfigurationJdbcTests
|
|||
|
||||
@Test
|
||||
public void defaultConfig() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.session.store-type=jdbc")
|
||||
this.contextRunner.withPropertyValues("spring.session.store-type=jdbc")
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(JdbcTemplateAutoConfiguration.class))
|
||||
.run(this::validateDefaultConfig);
|
||||
|
|
@ -68,22 +67,20 @@ public class SessionAutoConfigurationJdbcTests
|
|||
@Test
|
||||
public void defaultConfigWithUniqueStoreImplementation() {
|
||||
this.contextRunner
|
||||
.withClassLoader(new HideClassesClassLoader(
|
||||
HazelcastSessionRepository.class,
|
||||
RedisOperationsSessionRepository.class)
|
||||
)
|
||||
.withClassLoader(
|
||||
new HideClassesClassLoader(HazelcastSessionRepository.class,
|
||||
RedisOperationsSessionRepository.class))
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(JdbcTemplateAutoConfiguration.class))
|
||||
.run(this::validateDefaultConfig);
|
||||
}
|
||||
|
||||
private void validateDefaultConfig(AssertableWebApplicationContext context) {
|
||||
JdbcOperationsSessionRepository repository = validateSessionRepository(
|
||||
context, JdbcOperationsSessionRepository.class);
|
||||
assertThat(new DirectFieldAccessor(repository)
|
||||
.getPropertyValue("tableName")).isEqualTo("SPRING_SESSION");
|
||||
assertThat(context.getBean(JdbcSessionProperties.class)
|
||||
.getInitializeSchema())
|
||||
JdbcOperationsSessionRepository repository = validateSessionRepository(context,
|
||||
JdbcOperationsSessionRepository.class);
|
||||
assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName"))
|
||||
.isEqualTo("SPRING_SESSION");
|
||||
assertThat(context.getBean(JdbcSessionProperties.class).getInitializeSchema())
|
||||
.isEqualTo(DatabaseInitializationMode.EMBEDDED);
|
||||
assertThat(context.getBean(JdbcOperations.class)
|
||||
.queryForList("select * from SPRING_SESSION")).isEmpty();
|
||||
|
|
|
|||
|
|
@ -50,8 +50,7 @@ public class SessionAutoConfigurationRedisTests
|
|||
|
||||
@Test
|
||||
public void defaultConfig() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.session.store-type=redis")
|
||||
this.contextRunner.withPropertyValues("spring.session.store-type=redis")
|
||||
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||
.run(validateSpringSessionUsesRedis("spring:session:event:created:",
|
||||
RedisFlushMode.ON_SAVE));
|
||||
|
|
@ -60,8 +59,8 @@ public class SessionAutoConfigurationRedisTests
|
|||
@Test
|
||||
public void defaultConfigWithUniqueStoreImplementation() {
|
||||
this.contextRunner
|
||||
.withClassLoader(new HideClassesClassLoader(
|
||||
HazelcastSessionRepository.class,
|
||||
.withClassLoader(
|
||||
new HideClassesClassLoader(HazelcastSessionRepository.class,
|
||||
JdbcOperationsSessionRepository.class))
|
||||
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||
.run(validateSpringSessionUsesRedis("spring:session:event:created:",
|
||||
|
|
|
|||
|
|
@ -66,12 +66,12 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
|
|||
this.contextRunner.withPropertyValues("spring.session.store-type=jdbc")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure()
|
||||
.hasCauseInstanceOf(SessionRepositoryUnavailableException.class);
|
||||
assertThat(context).getFailure().hasCauseInstanceOf(
|
||||
SessionRepositoryUnavailableException.class);
|
||||
assertThat(context).getFailure().hasMessageContaining(
|
||||
"No session repository could be auto-configured");
|
||||
assertThat(context).getFailure().hasMessageContaining(
|
||||
"session store type is 'jdbc'");
|
||||
assertThat(context).getFailure()
|
||||
.hasMessageContaining("session store type is 'jdbc'");
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -96,8 +96,7 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
|
|||
@Test
|
||||
public void springSessionTimeoutIsNotAValidProperty() {
|
||||
this.contextRunner.withUserConfiguration(SessionRepositoryConfiguration.class)
|
||||
.withPropertyValues("spring.session.timeout=3000")
|
||||
.run((context) -> {
|
||||
.withPropertyValues("spring.session.timeout=3000").run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure()
|
||||
.isInstanceOf(BeanCreationException.class);
|
||||
|
|
|
|||
|
|
@ -367,8 +367,8 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
|
|||
if (endpointId == null || "".equals(endpointId)) {
|
||||
return; // Can't process that endpoint
|
||||
}
|
||||
Boolean enabledByDefault = determineEnabledByDefault(elementValues.get(
|
||||
"defaultEnablement"));
|
||||
Boolean enabledByDefault = determineEnabledByDefault(
|
||||
elementValues.get("defaultEnablement"));
|
||||
String type = this.typeUtils.getQualifiedName(element);
|
||||
this.metadataCollector
|
||||
.add(ItemMetadata.newGroup(endpointKey(endpointId), type, type, null));
|
||||
|
|
|
|||
|
|
@ -123,9 +123,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
|||
.withDescription("The name of this simple properties.")
|
||||
.withDefaultValue("boot").withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class)
|
||||
.withDefaultValue(false)
|
||||
.fromSource(SimpleProperties.class).withDescription("A simple flag.")
|
||||
.withDeprecation(null, null));
|
||||
.withDefaultValue(false).fromSource(SimpleProperties.class)
|
||||
.withDescription("A simple flag.").withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.comparator"));
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty("simple.counter"));
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty("simple.size"));
|
||||
|
|
@ -163,8 +162,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
|||
.withDefaultValue(false));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-short", Short.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("simple.type.my-primitive-short", Short.class)
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-short", Short.class)
|
||||
.withDefaultValue(0));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-integer", Integer.class));
|
||||
|
|
@ -245,8 +244,7 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
|||
Class<?> type = BoxingPojo.class;
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("boxing").fromSource(type));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("boxing.flag", Boolean.class)
|
||||
assertThat(metadata).has(Metadata.withProperty("boxing.flag", Boolean.class)
|
||||
.withDefaultValue(false).fromSource(type));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("boxing.counter", Integer.class).fromSource(type));
|
||||
|
|
@ -316,8 +314,7 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
|||
.fromSource(DeprecatedMethodConfig.Foo.class)
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class)
|
||||
.withDefaultValue(false)
|
||||
.fromSource(DeprecatedMethodConfig.Foo.class)
|
||||
.withDefaultValue(false).fromSource(DeprecatedMethodConfig.Foo.class)
|
||||
.withDeprecation(null, null));
|
||||
}
|
||||
|
||||
|
|
@ -331,8 +328,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
|||
.fromSource(
|
||||
org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.Foo.class)
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class)
|
||||
.withDefaultValue(false)
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("foo.flag", Boolean.class).withDefaultValue(false)
|
||||
.fromSource(
|
||||
org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.Foo.class)
|
||||
.withDeprecation(null, null));
|
||||
|
|
@ -879,34 +876,30 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
|||
assertThat(project.getOutputFile(MetadataStore.METADATA_PATH).exists()).isFalse();
|
||||
ConfigurationMetadata metadata = project.fullBuild();
|
||||
assertThat(project.getOutputFile(MetadataStore.METADATA_PATH).exists()).isTrue();
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("foo.counter").fromSource(FooProperties.class)
|
||||
.withDefaultValue(0));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("bar.counter").fromSource(BarProperties.class)
|
||||
.withDefaultValue(0));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.counter")
|
||||
.fromSource(FooProperties.class).withDefaultValue(0));
|
||||
assertThat(metadata).has(Metadata.withProperty("bar.counter")
|
||||
.fromSource(BarProperties.class).withDefaultValue(0));
|
||||
metadata = project.incrementalBuild(BarProperties.class);
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("foo.counter").fromSource(FooProperties.class)
|
||||
.withDefaultValue(0));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("bar.counter").fromSource(BarProperties.class)
|
||||
.withDefaultValue(0));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.counter")
|
||||
.fromSource(FooProperties.class).withDefaultValue(0));
|
||||
assertThat(metadata).has(Metadata.withProperty("bar.counter")
|
||||
.fromSource(BarProperties.class).withDefaultValue(0));
|
||||
project.addSourceCode(BarProperties.class,
|
||||
BarProperties.class.getResourceAsStream("BarProperties.snippet"));
|
||||
metadata = project.incrementalBuild(BarProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("bar.extra"));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.counter")
|
||||
.withDefaultValue(0));
|
||||
assertThat(metadata).has(Metadata.withProperty("bar.counter")
|
||||
.withDefaultValue(0));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("foo.counter").withDefaultValue(0));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("bar.counter").withDefaultValue(0));
|
||||
project.revert(BarProperties.class);
|
||||
metadata = project.incrementalBuild(BarProperties.class);
|
||||
assertThat(metadata).isNotEqualTo(Metadata.withProperty("bar.extra"));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.counter")
|
||||
.withDefaultValue(0));
|
||||
assertThat(metadata).has(Metadata.withProperty("bar.counter")
|
||||
.withDefaultValue(0));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("foo.counter").withDefaultValue(0));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("bar.counter").withDefaultValue(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -914,15 +907,15 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
|||
TestProject project = new TestProject(this.temporaryFolder, FooProperties.class,
|
||||
BarProperties.class);
|
||||
ConfigurationMetadata metadata = project.fullBuild();
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.counter")
|
||||
.withDefaultValue(0));
|
||||
assertThat(metadata).has(Metadata.withProperty("bar.counter")
|
||||
.withDefaultValue(0));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("foo.counter").withDefaultValue(0));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("bar.counter").withDefaultValue(0));
|
||||
project.replaceText(BarProperties.class, "@ConfigurationProperties",
|
||||
"//@ConfigurationProperties");
|
||||
metadata = project.incrementalBuild(BarProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.counter")
|
||||
.withDefaultValue(0));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("foo.counter").withDefaultValue(0));
|
||||
assertThat(metadata).isNotEqualTo(Metadata.withProperty("bar.counter"));
|
||||
}
|
||||
|
||||
|
|
@ -931,25 +924,21 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
|||
TestProject project = new TestProject(this.temporaryFolder, FooProperties.class,
|
||||
BarProperties.class);
|
||||
ConfigurationMetadata metadata = project.fullBuild();
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("foo.counter").fromSource(FooProperties.class)
|
||||
.withDefaultValue(0));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("bar.counter").fromSource(BarProperties.class)
|
||||
.withDefaultValue(0));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.counter")
|
||||
.fromSource(FooProperties.class).withDefaultValue(0));
|
||||
assertThat(metadata).has(Metadata.withProperty("bar.counter")
|
||||
.fromSource(BarProperties.class).withDefaultValue(0));
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty("bar.counter")
|
||||
.fromSource(RenamedBarProperties.class));
|
||||
project.delete(BarProperties.class);
|
||||
project.add(RenamedBarProperties.class);
|
||||
metadata = project.incrementalBuild(RenamedBarProperties.class);
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("foo.counter").fromSource(FooProperties.class)
|
||||
.withDefaultValue(0));
|
||||
assertThat(metadata).doesNotHave(
|
||||
Metadata.withProperty("bar.counter").fromSource(BarProperties.class)
|
||||
.withDefaultValue(0));
|
||||
assertThat(metadata).has(Metadata.withProperty("bar.counter")
|
||||
.withDefaultValue(0).fromSource(RenamedBarProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.counter")
|
||||
.fromSource(FooProperties.class).withDefaultValue(0));
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty("bar.counter")
|
||||
.fromSource(BarProperties.class).withDefaultValue(0));
|
||||
assertThat(metadata).has(Metadata.withProperty("bar.counter").withDefaultValue(0)
|
||||
.fromSource(RenamedBarProperties.class));
|
||||
}
|
||||
|
||||
private void assertSimpleLombokProperties(ConfigurationMetadata metadata,
|
||||
|
|
|
|||
|
|
@ -19,4 +19,5 @@ package org.springframework.boot.configurationsample;
|
|||
public enum DefaultEnablement {
|
||||
|
||||
ENABLED, DISABLED, NEUTRAL
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import org.springframework.core.convert.converter.GenericConverter;
|
|||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
|
|
@ -67,6 +68,7 @@ public class ConfigurationPropertiesBinderBuilder {
|
|||
* @param applicationContext the application context
|
||||
*/
|
||||
public ConfigurationPropertiesBinderBuilder(ApplicationContext applicationContext) {
|
||||
Assert.notNull(applicationContext, "ApplicationContext must not be null");
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue