Commit b234501a authored by Phillip Webb's avatar Phillip Webb

Polish

parent 62d9d0fd
...@@ -51,8 +51,7 @@ public class CloudFoundryWebEndpointDiscoverer extends WebEndpointDiscoverer { ...@@ -51,8 +51,7 @@ public class CloudFoundryWebEndpointDiscoverer extends WebEndpointDiscoverer {
*/ */
public CloudFoundryWebEndpointDiscoverer(ApplicationContext applicationContext, public CloudFoundryWebEndpointDiscoverer(ApplicationContext applicationContext,
ParameterValueMapper parameterValueMapper, ParameterValueMapper parameterValueMapper,
EndpointMediaTypes endpointMediaTypes, EndpointMediaTypes endpointMediaTypes, PathMapper endpointPathMapper,
PathMapper endpointPathMapper,
Collection<OperationInvokerAdvisor> invokerAdvisors, Collection<OperationInvokerAdvisor> invokerAdvisors,
Collection<EndpointFilter<ExposableWebEndpoint>> filters) { Collection<EndpointFilter<ExposableWebEndpoint>> filters) {
super(applicationContext, parameterValueMapper, endpointMediaTypes, super(applicationContext, parameterValueMapper, endpointMediaTypes,
......
...@@ -21,8 +21,8 @@ import java.util.Map; ...@@ -21,8 +21,8 @@ import java.util.Map;
import org.springframework.boot.actuate.endpoint.web.PathMapper; import org.springframework.boot.actuate.endpoint.web.PathMapper;
/** /**
* A {@link PathMapper} implementation that uses a simple {@link Map} to * A {@link PathMapper} implementation that uses a simple {@link Map} to determine the
* determine the endpoint path. * endpoint path.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
......
...@@ -65,8 +65,8 @@ class CacheMetricsRegistrarConfiguration { ...@@ -65,8 +65,8 @@ class CacheMetricsRegistrarConfiguration {
@Bean @Bean
public CacheMetricsRegistrar cacheMetricsRegistrar() { public CacheMetricsRegistrar cacheMetricsRegistrar() {
return new CacheMetricsRegistrar(this.registry, return new CacheMetricsRegistrar(this.registry, this.properties.getMetricName(),
this.properties.getMetricName(), this.binderProviders); this.binderProviders);
} }
@PostConstruct @PostConstruct
......
...@@ -68,8 +68,8 @@ public class CloudFoundryWebEndpointDiscovererTests { ...@@ -68,8 +68,8 @@ public class CloudFoundryWebEndpointDiscovererTests {
this.load((id) -> null, (id) -> id, configuration, consumer); this.load((id) -> null, (id) -> id, configuration, consumer);
} }
private void load(Function<String, Long> timeToLive, private void load(Function<String, Long> timeToLive, PathMapper endpointPathMapper,
PathMapper endpointPathMapper, Class<?> configuration, Class<?> configuration,
Consumer<CloudFoundryWebEndpointDiscoverer> consumer) { Consumer<CloudFoundryWebEndpointDiscoverer> consumer) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
configuration); configuration);
......
...@@ -54,8 +54,8 @@ public class ReactiveCloudFoundrySecurityInterceptorTests { ...@@ -54,8 +54,8 @@ public class ReactiveCloudFoundrySecurityInterceptorTests {
@Before @Before
public void setup() { public void setup() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
this.interceptor = new CloudFoundrySecurityInterceptor( this.interceptor = new CloudFoundrySecurityInterceptor(this.tokenValidator,
this.tokenValidator, this.securityService, "my-app-id"); this.securityService, "my-app-id");
} }
@Test @Test
...@@ -90,8 +90,8 @@ public class ReactiveCloudFoundrySecurityInterceptorTests { ...@@ -90,8 +90,8 @@ public class ReactiveCloudFoundrySecurityInterceptorTests {
@Test @Test
public void preHandleWhenApplicationIdIsNullShouldReturnError() { public void preHandleWhenApplicationIdIsNullShouldReturnError() {
this.interceptor = new CloudFoundrySecurityInterceptor( this.interceptor = new CloudFoundrySecurityInterceptor(this.tokenValidator,
this.tokenValidator, this.securityService, null); this.securityService, null);
MockServerWebExchange request = MockServerWebExchange MockServerWebExchange request = MockServerWebExchange
.from(MockServerHttpRequest.get("/a") .from(MockServerHttpRequest.get("/a")
.header(HttpHeaders.AUTHORIZATION, "bearer " + mockAccessToken()) .header(HttpHeaders.AUTHORIZATION, "bearer " + mockAccessToken())
...@@ -105,8 +105,8 @@ public class ReactiveCloudFoundrySecurityInterceptorTests { ...@@ -105,8 +105,8 @@ public class ReactiveCloudFoundrySecurityInterceptorTests {
@Test @Test
public void preHandleWhenCloudFoundrySecurityServiceIsNullShouldReturnError() { public void preHandleWhenCloudFoundrySecurityServiceIsNullShouldReturnError() {
this.interceptor = new CloudFoundrySecurityInterceptor( this.interceptor = new CloudFoundrySecurityInterceptor(this.tokenValidator, null,
this.tokenValidator, null, "my-app-id"); "my-app-id");
MockServerWebExchange request = MockServerWebExchange.from(MockServerHttpRequest MockServerWebExchange request = MockServerWebExchange.from(MockServerHttpRequest
.get("/a").header(HttpHeaders.AUTHORIZATION, mockAccessToken()).build()); .get("/a").header(HttpHeaders.AUTHORIZATION, mockAccessToken()).build());
StepVerifier.create(this.interceptor.preHandle(request, "/a")) StepVerifier.create(this.interceptor.preHandle(request, "/a"))
......
...@@ -58,8 +58,7 @@ public class CacheMetricsConfigurationTests { ...@@ -58,8 +58,7 @@ public class CacheMetricsConfigurationTests {
@Test @Test
public void autoConfiguredCacheManagerWithCustomMetricName() { public void autoConfiguredCacheManagerWithCustomMetricName() {
this.contextRunner this.contextRunner
.withPropertyValues( .withPropertyValues("management.metrics.cache.metric-name=custom.name",
"management.metrics.cache.metric-name=custom.name",
"spring.cache.type=caffeine", "spring.cache.cache-names=cache1") "spring.cache.type=caffeine", "spring.cache.cache-names=cache1")
.run((context) -> { .run((context) -> {
MeterRegistry registry = context.getBean(MeterRegistry.class); MeterRegistry registry = context.getBean(MeterRegistry.class);
......
...@@ -38,8 +38,8 @@ public final class MissingParametersException extends InvalidEndpointRequestExce ...@@ -38,8 +38,8 @@ public final class MissingParametersException extends InvalidEndpointRequestExce
super("Failed to invoke operation because the following required " super("Failed to invoke operation because the following required "
+ "parameters were missing: " + "parameters were missing: "
+ StringUtils.collectionToCommaDelimitedString(missingParameters), + StringUtils.collectionToCommaDelimitedString(missingParameters),
"Missing parameters: " + missingParameters.stream() "Missing parameters: "
.map(OperationParameter::getName) + missingParameters.stream().map(OperationParameter::getName)
.collect(Collectors.joining(","))); .collect(Collectors.joining(",")));
this.missingParameters = missingParameters; this.missingParameters = missingParameters;
} }
......
...@@ -33,8 +33,8 @@ import org.springframework.web.bind.annotation.GetMapping; ...@@ -33,8 +33,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
/** /**
* Identifies a type as being an endpoint that is only exposed over Spring MVC or * Identifies a type as being an endpoint that is only exposed over Spring MVC or Spring
* Spring WebFlux. Mapped methods must be annotated with {@link GetMapping @GetMapping}, * WebFlux. Mapped methods must be annotated with {@link GetMapping @GetMapping},
* {@link PostMapping @PostMapping}, {@link DeleteMapping @DeleteMapping}, etc annotations * {@link PostMapping @PostMapping}, {@link DeleteMapping @DeleteMapping}, etc annotations
* rather than {@link ReadOperation @ReadOperation}, * rather than {@link ReadOperation @ReadOperation},
* {@link WriteOperation @WriteOperation}, {@link DeleteOperation @DeleteOperation}. * {@link WriteOperation @WriteOperation}, {@link DeleteOperation @DeleteOperation}.
......
...@@ -31,7 +31,8 @@ import org.springframework.core.annotation.AnnotatedElementUtils; ...@@ -31,7 +31,8 @@ import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* {@link EndpointDiscoverer} for {@link ExposableControllerEndpoint controller endpoints}. * {@link EndpointDiscoverer} for {@link ExposableControllerEndpoint controller
* endpoints}.
* *
* @author Phillip Webb * @author Phillip Webb
* @since 2.0.0 * @since 2.0.0
......
...@@ -288,8 +288,8 @@ public abstract class AbstractWebFluxEndpointHandlerMapping ...@@ -288,8 +288,8 @@ public abstract class AbstractWebFluxEndpointHandlerMapping
private Mono<ResponseEntity<Object>> handleResult(Publisher<?> result, private Mono<ResponseEntity<Object>> handleResult(Publisher<?> result,
HttpMethod httpMethod) { HttpMethod httpMethod) {
return Mono.from(result).map(this::toResponseEntity) return Mono.from(result).map(this::toResponseEntity)
.onErrorMap(InvalidEndpointRequestException.class, (ex) -> .onErrorMap(InvalidEndpointRequestException.class,
new ResponseStatusException(HttpStatus.BAD_REQUEST, (ex) -> new ResponseStatusException(HttpStatus.BAD_REQUEST,
ex.getReason())) ex.getReason()))
.defaultIfEmpty(new ResponseEntity<>(httpMethod == HttpMethod.GET .defaultIfEmpty(new ResponseEntity<>(httpMethod == HttpMethod.GET
? HttpStatus.NOT_FOUND : HttpStatus.NO_CONTENT)); ? HttpStatus.NOT_FOUND : HttpStatus.NO_CONTENT));
......
...@@ -72,8 +72,7 @@ public class ControllerEndpointHandlerMapping extends RequestMappingHandlerMappi ...@@ -72,8 +72,7 @@ public class ControllerEndpointHandlerMapping extends RequestMappingHandlerMappi
private Map<Object, ExposableControllerEndpoint> getHandlers( private Map<Object, ExposableControllerEndpoint> getHandlers(
Collection<ExposableControllerEndpoint> endpoints) { Collection<ExposableControllerEndpoint> endpoints) {
Map<Object, ExposableControllerEndpoint> handlers = new LinkedHashMap<>(); Map<Object, ExposableControllerEndpoint> handlers = new LinkedHashMap<>();
endpoints endpoints.forEach((endpoint) -> handlers.put(endpoint.getController(), endpoint));
.forEach((endpoint) -> handlers.put(endpoint.getController(), endpoint));
return Collections.unmodifiableMap(handlers); return Collections.unmodifiableMap(handlers);
} }
......
...@@ -73,8 +73,7 @@ public class ControllerEndpointHandlerMapping extends RequestMappingHandlerMappi ...@@ -73,8 +73,7 @@ public class ControllerEndpointHandlerMapping extends RequestMappingHandlerMappi
private Map<Object, ExposableControllerEndpoint> getHandlers( private Map<Object, ExposableControllerEndpoint> getHandlers(
Collection<ExposableControllerEndpoint> endpoints) { Collection<ExposableControllerEndpoint> endpoints) {
Map<Object, ExposableControllerEndpoint> handlers = new LinkedHashMap<>(); Map<Object, ExposableControllerEndpoint> handlers = new LinkedHashMap<>();
endpoints endpoints.forEach((endpoint) -> handlers.put(endpoint.getController(), endpoint));
.forEach((endpoint) -> handlers.put(endpoint.getController(), endpoint));
return Collections.unmodifiableMap(handlers); return Collections.unmodifiableMap(handlers);
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -75,12 +75,12 @@ public class RouterFunctionMetrics { ...@@ -75,12 +75,12 @@ public class RouterFunctionMetrics {
Iterable<Tag> tags) { Iterable<Tag> tags) {
return (request, next) -> { return (request, next) -> {
final long start = System.nanoTime(); final long start = System.nanoTime();
return next.handle(request).doOnSuccess(response -> { return next.handle(request).doOnSuccess((response) -> {
Iterable<Tag> allTags = Tags.concat(tags, Iterable<Tag> allTags = Tags.concat(tags,
this.defaultTags.apply(request, response)); this.defaultTags.apply(request, response));
this.registry.timer(name, allTags).record(System.nanoTime() - start, this.registry.timer(name, allTags).record(System.nanoTime() - start,
TimeUnit.NANOSECONDS); TimeUnit.NANOSECONDS);
}).doOnError(error -> { }).doOnError((error) -> {
// FIXME how do we get the response under an error condition? // FIXME how do we get the response under an error condition?
Iterable<Tag> allTags = Tags.concat(tags, Iterable<Tag> allTags = Tags.concat(tags,
this.defaultTags.apply(request, null)); this.defaultTags.apply(request, null));
......
...@@ -99,7 +99,7 @@ public class BeansEndpointTests { ...@@ -99,7 +99,7 @@ public class BeansEndpointTests {
parentRunner.run((parent) -> { parentRunner.run((parent) -> {
new ApplicationContextRunner() new ApplicationContextRunner()
.withUserConfiguration(EndpointConfiguration.class).withParent(parent) .withUserConfiguration(EndpointConfiguration.class).withParent(parent)
.run(child -> { .run((child) -> {
ApplicationBeans result = child.getBean(BeansEndpoint.class).beans(); ApplicationBeans result = child.getBean(BeansEndpoint.class).beans();
assertThat(result.getContexts().get(parent.getId()).getBeans()) assertThat(result.getContexts().get(parent.getId()).getBeans())
.containsKey("bean"); .containsKey("bean");
......
...@@ -42,7 +42,7 @@ public class ConfigurationPropertiesReportEndpointParentTests { ...@@ -42,7 +42,7 @@ public class ConfigurationPropertiesReportEndpointParentTests {
.run((parent) -> { .run((parent) -> {
new ApplicationContextRunner() new ApplicationContextRunner()
.withUserConfiguration(ClassConfigurationProperties.class) .withUserConfiguration(ClassConfigurationProperties.class)
.withParent(parent).run(child -> { .withParent(parent).run((child) -> {
ConfigurationPropertiesReportEndpoint endpoint = child ConfigurationPropertiesReportEndpoint endpoint = child
.getBean(ConfigurationPropertiesReportEndpoint.class); .getBean(ConfigurationPropertiesReportEndpoint.class);
ApplicationConfigurationProperties applicationProperties = endpoint ApplicationConfigurationProperties applicationProperties = endpoint
...@@ -65,7 +65,7 @@ public class ConfigurationPropertiesReportEndpointParentTests { ...@@ -65,7 +65,7 @@ public class ConfigurationPropertiesReportEndpointParentTests {
new ApplicationContextRunner() new ApplicationContextRunner()
.withUserConfiguration( .withUserConfiguration(
BeanMethodConfigurationProperties.class) BeanMethodConfigurationProperties.class)
.withParent(parent).run(child -> { .withParent(parent).run((child) -> {
ConfigurationPropertiesReportEndpoint endpoint = child ConfigurationPropertiesReportEndpoint endpoint = child
.getBean(ConfigurationPropertiesReportEndpoint.class); .getBean(ConfigurationPropertiesReportEndpoint.class);
ApplicationConfigurationProperties applicationProperties = endpoint ApplicationConfigurationProperties applicationProperties = endpoint
......
...@@ -159,9 +159,8 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable ...@@ -159,9 +159,8 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
@Test @Test
public void readOperationWithMappingFailureProducesBadRequestResponse() { public void readOperationWithMappingFailureProducesBadRequestResponse() {
load(QueryEndpointConfiguration.class, (client) -> { load(QueryEndpointConfiguration.class, (client) -> {
WebTestClient.BodyContentSpec body = client.get() WebTestClient.BodyContentSpec body = client.get().uri("/query?two=two")
.uri("/query?two=two").exchange().expectStatus().isBadRequest() .exchange().expectStatus().isBadRequest().expectBody();
.expectBody();
validateErrorBody(body, HttpStatus.BAD_REQUEST, "/endpoints/query", validateErrorBody(body, HttpStatus.BAD_REQUEST, "/endpoints/query",
"Missing parameters: one"); "Missing parameters: one");
}); });
...@@ -282,9 +281,8 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable ...@@ -282,9 +281,8 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
@Test @Test
public void readOperationWithMissingRequiredParametersReturnsBadRequestResponse() { public void readOperationWithMissingRequiredParametersReturnsBadRequestResponse() {
load(RequiredParameterEndpointConfiguration.class, (client) -> { load(RequiredParameterEndpointConfiguration.class, (client) -> {
WebTestClient.BodyContentSpec body = client.get() WebTestClient.BodyContentSpec body = client.get().uri("/requiredparameters")
.uri("/requiredparameters").exchange().expectStatus().isBadRequest() .exchange().expectStatus().isBadRequest().expectBody();
.expectBody();
validateErrorBody(body, HttpStatus.BAD_REQUEST, validateErrorBody(body, HttpStatus.BAD_REQUEST,
"/endpoints/requiredparameters", "Missing parameters: foo"); "/endpoints/requiredparameters", "Missing parameters: foo");
}); });
...@@ -334,9 +332,8 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable ...@@ -334,9 +332,8 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
protected void validateErrorBody(WebTestClient.BodyContentSpec body, protected void validateErrorBody(WebTestClient.BodyContentSpec body,
HttpStatus status, String path, String message) { HttpStatus status, String path, String message) {
body.jsonPath("status").isEqualTo(status.value()) body.jsonPath("status").isEqualTo(status.value()).jsonPath("error")
.jsonPath("error").isEqualTo(status.getReasonPhrase()) .isEqualTo(status.getReasonPhrase()).jsonPath("path").isEqualTo(path)
.jsonPath("path").isEqualTo(path)
.jsonPath("message").isEqualTo(message); .jsonPath("message").isEqualTo(message);
} }
......
...@@ -68,8 +68,8 @@ class BaseConfiguration { ...@@ -68,8 +68,8 @@ class BaseConfiguration {
ParameterValueMapper parameterMapper = new ConversionServiceParameterValueMapper( ParameterValueMapper parameterMapper = new ConversionServiceParameterValueMapper(
DefaultConversionService.getSharedInstance()); DefaultConversionService.getSharedInstance());
return new WebEndpointDiscoverer(applicationContext, parameterMapper, return new WebEndpointDiscoverer(applicationContext, parameterMapper,
endpointMediaTypes(), PathMapper.useEndpointId(), endpointMediaTypes(), PathMapper.useEndpointId(), Collections.emptyList(),
Collections.emptyList(), Collections.emptyList()); Collections.emptyList());
} }
@Bean @Bean
......
...@@ -298,9 +298,9 @@ public class WebEndpointDiscovererTests { ...@@ -298,9 +298,9 @@ public class WebEndpointDiscovererTests {
Map<WebOperationRequestPredicate, Long> matchCounts = new HashMap<>(); Map<WebOperationRequestPredicate, Long> matchCounts = new HashMap<>();
for (WebOperationRequestPredicate predicate : predicates) { for (WebOperationRequestPredicate predicate : predicates) {
matchCounts.put(predicate, Stream.of(matchers) matchCounts.put(predicate, Stream.of(matchers)
.filter(matcher -> matcher.matches(predicate)).count()); .filter((matcher) -> matcher.matches(predicate)).count());
} }
return matchCounts.values().stream().noneMatch(count -> count != 1); return matchCounts.values().stream().noneMatch((count) -> count != 1);
}, Arrays.toString(matchers)); }, Arrays.toString(matchers));
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -100,7 +100,7 @@ public class SpringIntegrationMetricsIntegrationTests { ...@@ -100,7 +100,7 @@ public class SpringIntegrationMetricsIntegrationTests {
(e) -> e.id("toJson")) (e) -> e.id("toJson"))
.handle(String.class, this::fahrenheitToCelsius, .handle(String.class, this::fahrenheitToCelsius,
(e) -> e.id("temperatureConverter")) (e) -> e.id("temperatureConverter"))
.transform(this::extractResult, e -> e.id("toResponse")); .transform(this::extractResult, (e) -> e.id("toResponse"));
} }
private double extractResult(String json) { private double extractResult(String json) {
......
...@@ -157,7 +157,7 @@ public class FlywayAutoConfiguration { ...@@ -157,7 +157,7 @@ public class FlywayAutoConfiguration {
private String getProperty(Supplier<String> property, private String getProperty(Supplier<String> property,
Supplier<String> defaultValue) { Supplier<String> defaultValue) {
String value = property.get(); String value = property.get();
return value == null ? defaultValue.get() : value; return (value == null ? defaultValue.get() : value);
} }
private void checkLocationExists(String... locations) { private void checkLocationExists(String... locations) {
......
...@@ -57,16 +57,19 @@ public final class JettyCustomizer { ...@@ -57,16 +57,19 @@ public final class JettyCustomizer {
propertyMapper.from(jettyProperties::getSelectors).whenNonNull() propertyMapper.from(jettyProperties::getSelectors).whenNonNull()
.to(factory::setSelectors); .to(factory::setSelectors);
propertyMapper.from(serverProperties::getMaxHttpHeaderSize) propertyMapper.from(serverProperties::getMaxHttpHeaderSize)
.when(JettyCustomizer::isPositive).to(maxHttpHeaderSize -> .when(JettyCustomizer::isPositive)
customizeMaxHttpHeaderSize(factory, maxHttpHeaderSize)); .to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory,
maxHttpHeaderSize));
propertyMapper.from(jettyProperties::getMaxHttpPostSize) propertyMapper.from(jettyProperties::getMaxHttpPostSize)
.when(JettyCustomizer::isPositive) .when(JettyCustomizer::isPositive)
.to(maxHttpPostSize -> customizeMaxHttpPostSize(factory, maxHttpPostSize)); .to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory,
maxHttpPostSize));
propertyMapper.from(serverProperties::getConnectionTimeout).whenNonNull() propertyMapper.from(serverProperties::getConnectionTimeout).whenNonNull()
.to(connectionTimeout -> customizeConnectionTimeout(factory, connectionTimeout)); .to((connectionTimeout) -> customizeConnectionTimeout(factory,
connectionTimeout));
propertyMapper.from(jettyProperties::getAccesslog) propertyMapper.from(jettyProperties::getAccesslog)
.when(ServerProperties.Jetty.Accesslog::isEnabled) .when(ServerProperties.Jetty.Accesslog::isEnabled)
.to(accesslog -> customizeAccessLog(factory, accesslog)); .to((accesslog) -> customizeAccessLog(factory, accesslog));
} }
private static boolean isPositive(Integer value) { private static boolean isPositive(Integer value) {
......
...@@ -58,29 +58,35 @@ public final class TomcatCustomizer { ...@@ -58,29 +58,35 @@ public final class TomcatCustomizer {
customizeRemoteIpValve(serverProperties, environment, factory); customizeRemoteIpValve(serverProperties, environment, factory);
propertyMapper.from(tomcatProperties::getMaxThreads) propertyMapper.from(tomcatProperties::getMaxThreads)
.when(TomcatCustomizer::isPositive) .when(TomcatCustomizer::isPositive)
.to(maxThreads -> customizeMaxThreads(factory, tomcatProperties.getMaxThreads())); .to((maxThreads) -> customizeMaxThreads(factory,
tomcatProperties.getMaxThreads()));
propertyMapper.from(tomcatProperties::getMinSpareThreads) propertyMapper.from(tomcatProperties::getMinSpareThreads)
.when(TomcatCustomizer::isPositive) .when(TomcatCustomizer::isPositive)
.to(minSpareThreads -> customizeMinThreads(factory, minSpareThreads)); .to((minSpareThreads) -> customizeMinThreads(factory, minSpareThreads));
propertyMapper.from(() -> determineMaxHttpHeaderSize(serverProperties, tomcatProperties)) propertyMapper
.from(() -> determineMaxHttpHeaderSize(serverProperties,
tomcatProperties))
.when(TomcatCustomizer::isPositive) .when(TomcatCustomizer::isPositive)
.to(maxHttpHeaderSize -> customizeMaxHttpHeaderSize(factory, maxHttpHeaderSize)); .to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory,
maxHttpHeaderSize));
propertyMapper.from(tomcatProperties::getMaxHttpPostSize) propertyMapper.from(tomcatProperties::getMaxHttpPostSize)
.when(maxHttpPostSize -> maxHttpPostSize != 0) .when((maxHttpPostSize) -> maxHttpPostSize != 0)
.to(maxHttpPostSize -> customizeMaxHttpPostSize(factory, maxHttpPostSize)); .to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory,
maxHttpPostSize));
propertyMapper.from(tomcatProperties::getAccesslog) propertyMapper.from(tomcatProperties::getAccesslog)
.when(ServerProperties.Tomcat.Accesslog::isEnabled) .when(ServerProperties.Tomcat.Accesslog::isEnabled)
.to(enabled -> customizeAccessLog(tomcatProperties, factory)); .to((enabled) -> customizeAccessLog(tomcatProperties, factory));
propertyMapper.from(tomcatProperties::getUriEncoding).whenNonNull() propertyMapper.from(tomcatProperties::getUriEncoding).whenNonNull()
.to(factory::setUriEncoding); .to(factory::setUriEncoding);
propertyMapper.from(serverProperties::getConnectionTimeout).whenNonNull() propertyMapper.from(serverProperties::getConnectionTimeout).whenNonNull()
.to(connectionTimeout -> customizeConnectionTimeout(factory, connectionTimeout)); .to((connectionTimeout) -> customizeConnectionTimeout(factory,
connectionTimeout));
propertyMapper.from(tomcatProperties::getMaxConnections) propertyMapper.from(tomcatProperties::getMaxConnections)
.when(TomcatCustomizer::isPositive) .when(TomcatCustomizer::isPositive)
.to(maxConnections -> customizeMaxConnections(factory, maxConnections)); .to((maxConnections) -> customizeMaxConnections(factory, maxConnections));
propertyMapper.from(tomcatProperties::getAcceptCount) propertyMapper.from(tomcatProperties::getAcceptCount)
.when(TomcatCustomizer::isPositive) .when(TomcatCustomizer::isPositive)
.to(acceptCount -> customizeAcceptCount(factory, acceptCount)); .to((acceptCount) -> customizeAcceptCount(factory, acceptCount));
customizeStaticResources(serverProperties.getTomcat().getResource(), factory); customizeStaticResources(serverProperties.getTomcat().getResource(), factory);
} }
...@@ -234,4 +240,5 @@ public final class TomcatCustomizer { ...@@ -234,4 +240,5 @@ public final class TomcatCustomizer {
}); });
}); });
} }
} }
...@@ -63,21 +63,21 @@ public final class UndertowCustomizer { ...@@ -63,21 +63,21 @@ public final class UndertowCustomizer {
.to(factory::setAccessLogSuffix); .to(factory::setAccessLogSuffix);
propertyMapper.from(accesslogProperties::isRotate) propertyMapper.from(accesslogProperties::isRotate)
.to(factory::setAccessLogRotate); .to(factory::setAccessLogRotate);
propertyMapper.from(() -> propertyMapper
getOrDeduceUseForwardHeaders(serverProperties, environment)).to( .from(() -> getOrDeduceUseForwardHeaders(serverProperties, environment))
factory::setUseForwardHeaders); .to(factory::setUseForwardHeaders);
propertyMapper.from(serverProperties::getMaxHttpHeaderSize) propertyMapper.from(serverProperties::getMaxHttpHeaderSize)
.when(UndertowCustomizer::isPositive) .when(UndertowCustomizer::isPositive)
.to(maxHttpHeaderSize -> .to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory,
customizeMaxHttpHeaderSize(factory, maxHttpHeaderSize)); maxHttpHeaderSize));
propertyMapper.from(undertowProperties::getMaxHttpPostSize) propertyMapper.from(undertowProperties::getMaxHttpPostSize)
.when(UndertowCustomizer::isPositive) .when(UndertowCustomizer::isPositive)
.to(maxHttpPostSize -> .to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory,
customizeMaxHttpPostSize(factory, maxHttpPostSize)); maxHttpPostSize));
propertyMapper.from(serverProperties::getConnectionTimeout) propertyMapper.from(serverProperties::getConnectionTimeout)
.to(connectionTimeout -> .to((connectionTimeout) -> customizeConnectionTimeout(factory,
customizeConnectionTimeout(factory, connectionTimeout)); connectionTimeout));
factory.addDeploymentInfoCustomizers(deploymentInfo -> deploymentInfo factory.addDeploymentInfoCustomizers((deploymentInfo) -> deploymentInfo
.setEagerFilterInit(undertowProperties.isEagerFilterInit())); .setEagerFilterInit(undertowProperties.isEagerFilterInit()));
} }
......
...@@ -67,14 +67,14 @@ public class DefaultReactiveWebServerFactoryCustomizer ...@@ -67,14 +67,14 @@ public class DefaultReactiveWebServerFactoryCustomizer
map.from(this.serverProperties::getSsl).to(factory::setSsl); map.from(this.serverProperties::getSsl).to(factory::setSsl);
map.from(this.serverProperties::getCompression).to(factory::setCompression); map.from(this.serverProperties::getCompression).to(factory::setCompression);
map.from(this.serverProperties::getHttp2).to(factory::setHttp2); map.from(this.serverProperties::getHttp2).to(factory::setHttp2);
map.from(() -> factory).whenInstanceOf(TomcatReactiveWebServerFactory.class) map.from(() -> factory).whenInstanceOf(TomcatReactiveWebServerFactory.class).to(
.to(tomcatFactory -> TomcatCustomizer.customizeTomcat( (tomcatFactory) -> TomcatCustomizer.customizeTomcat(this.serverProperties,
this.serverProperties, this.environment, tomcatFactory)); this.environment, tomcatFactory));
map.from(() -> factory).whenInstanceOf(JettyReactiveWebServerFactory.class) map.from(() -> factory).whenInstanceOf(JettyReactiveWebServerFactory.class).to(
.to(jettyFactory -> JettyCustomizer.customizeJetty(this.serverProperties, (jettyFactory) -> JettyCustomizer.customizeJetty(this.serverProperties,
this.environment, jettyFactory)); this.environment, jettyFactory));
map.from(() -> factory).whenInstanceOf(UndertowReactiveWebServerFactory.class) map.from(() -> factory).whenInstanceOf(UndertowReactiveWebServerFactory.class)
.to(undertowFactory -> UndertowCustomizer.customizeUndertow( .to((undertowFactory) -> UndertowCustomizer.customizeUndertow(
this.serverProperties, this.environment, undertowFactory)); this.serverProperties, this.environment, undertowFactory));
} }
......
...@@ -83,17 +83,17 @@ public class DefaultServletWebServerFactoryCustomizer ...@@ -83,17 +83,17 @@ public class DefaultServletWebServerFactoryCustomizer
map.from(this.serverProperties::getHttp2).to(factory::setHttp2); map.from(this.serverProperties::getHttp2).to(factory::setHttp2);
map.from(this.serverProperties::getServerHeader).to(factory::setServerHeader); map.from(this.serverProperties::getServerHeader).to(factory::setServerHeader);
map.from(() -> factory).whenInstanceOf(TomcatServletWebServerFactory.class) map.from(() -> factory).whenInstanceOf(TomcatServletWebServerFactory.class)
.to(tomcatFactory -> { .to((tomcatFactory) -> {
TomcatCustomizer.customizeTomcat(this.serverProperties, TomcatCustomizer.customizeTomcat(this.serverProperties,
this.environment, tomcatFactory); this.environment, tomcatFactory);
TomcatServletCustomizer.customizeTomcat(this.serverProperties, TomcatServletCustomizer.customizeTomcat(this.serverProperties,
this.environment, tomcatFactory); this.environment, tomcatFactory);
}); });
map.from(() -> factory).whenInstanceOf(JettyServletWebServerFactory.class) map.from(() -> factory).whenInstanceOf(JettyServletWebServerFactory.class).to(
.to(jettyFactory -> JettyCustomizer.customizeJetty(this.serverProperties, (jettyFactory) -> JettyCustomizer.customizeJetty(this.serverProperties,
this.environment, jettyFactory)); this.environment, jettyFactory));
map.from(() -> factory).whenInstanceOf(UndertowServletWebServerFactory.class) map.from(() -> factory).whenInstanceOf(UndertowServletWebServerFactory.class)
.to(undertowFactory -> UndertowCustomizer.customizeUndertow( .to((undertowFactory) -> UndertowCustomizer.customizeUndertow(
this.serverProperties, this.environment, undertowFactory)); this.serverProperties, this.environment, undertowFactory));
map.from(this.serverProperties.getServlet()::getContextParameters) map.from(this.serverProperties.getServlet()::getContextParameters)
.to(factory::setInitParameters); .to(factory::setInitParameters);
......
...@@ -60,7 +60,8 @@ public class CassandraRepositoriesAutoConfigurationTests { ...@@ -60,7 +60,8 @@ public class CassandraRepositoriesAutoConfigurationTests {
@Test @Test
public void testDefaultRepositoryConfiguration() { public void testDefaultRepositoryConfiguration() {
this.contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> { this.contextRunner.withUserConfiguration(TestConfiguration.class)
.run((context) -> {
assertThat(context).hasSingleBean(CityRepository.class); assertThat(context).hasSingleBean(CityRepository.class);
assertThat(context).hasSingleBean(Cluster.class); assertThat(context).hasSingleBean(Cluster.class);
assertThat(getInitialEntitySet(context)).hasSize(1); assertThat(getInitialEntitySet(context)).hasSize(1);
......
...@@ -58,7 +58,8 @@ public class MongoReactiveRepositoriesAutoConfigurationTests { ...@@ -58,7 +58,8 @@ public class MongoReactiveRepositoriesAutoConfigurationTests {
@Test @Test
public void testDefaultRepositoryConfiguration() { public void testDefaultRepositoryConfiguration() {
this.contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> { this.contextRunner.withUserConfiguration(TestConfiguration.class)
.run((context) -> {
assertThat(context).hasSingleBean(ReactiveCityRepository.class); assertThat(context).hasSingleBean(ReactiveCityRepository.class);
assertThat(context).hasSingleBean(MongoClient.class); assertThat(context).hasSingleBean(MongoClient.class);
MongoMappingContext mappingContext = context MongoMappingContext mappingContext = context
......
...@@ -53,7 +53,8 @@ public class MongoRepositoriesAutoConfigurationTests { ...@@ -53,7 +53,8 @@ public class MongoRepositoriesAutoConfigurationTests {
@Test @Test
public void testDefaultRepositoryConfiguration() { public void testDefaultRepositoryConfiguration() {
this.contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> { this.contextRunner.withUserConfiguration(TestConfiguration.class)
.run((context) -> {
assertThat(context).hasSingleBean(CityRepository.class); assertThat(context).hasSingleBean(CityRepository.class);
assertThat(context).hasSingleBean(MongoClient.class); assertThat(context).hasSingleBean(MongoClient.class);
MongoMappingContext mappingContext = context MongoMappingContext mappingContext = context
...@@ -80,8 +81,9 @@ public class MongoRepositoriesAutoConfigurationTests { ...@@ -80,8 +81,9 @@ public class MongoRepositoriesAutoConfigurationTests {
@Test @Test
public void autoConfigurationShouldNotKickInEvenIfManualConfigDidNotCreateAnyRepositories() { public void autoConfigurationShouldNotKickInEvenIfManualConfigDidNotCreateAnyRepositories() {
this.contextRunner.withUserConfiguration(SortOfInvalidCustomConfiguration.class).run( this.contextRunner.withUserConfiguration(SortOfInvalidCustomConfiguration.class)
(context) -> assertThat(context).doesNotHaveBean(CityRepository.class)); .run((context) -> assertThat(context)
.doesNotHaveBean(CityRepository.class));
} }
@Test @Test
......
...@@ -74,7 +74,8 @@ public class AuthenticationManagerConfigurationTests { ...@@ -74,7 +74,8 @@ public class AuthenticationManagerConfigurationTests {
this.contextRunner this.contextRunner
.withUserConfiguration(TestConfigWithClientRegistrationRepository.class, .withUserConfiguration(TestConfigWithClientRegistrationRepository.class,
AuthenticationManagerConfiguration.class) AuthenticationManagerConfiguration.class)
.run(((context) -> assertThat(context).doesNotHaveBean(InMemoryUserDetailsManager.class))); .run(((context) -> assertThat(context)
.doesNotHaveBean(InMemoryUserDetailsManager.class)));
} }
private void testPasswordEncoding(Class<?> configClass, String providedPassword, private void testPasswordEncoding(Class<?> configClass, String providedPassword,
......
...@@ -70,8 +70,8 @@ class PropertiesMigrationReporter { ...@@ -70,8 +70,8 @@ class PropertiesMigrationReporter {
return report; return report;
} }
properties.forEach((name, candidates) -> { properties.forEach((name, candidates) -> {
PropertySource<?> propertySource = mapPropertiesWithReplacement(report, PropertySource<?> propertySource = mapPropertiesWithReplacement(report, name,
name, candidates); candidates);
if (propertySource != null) { if (propertySource != null) {
this.environment.getPropertySources().addBefore(name, propertySource); this.environment.getPropertySources().addBefore(name, propertySource);
} }
...@@ -84,8 +84,8 @@ class PropertiesMigrationReporter { ...@@ -84,8 +84,8 @@ class PropertiesMigrationReporter {
List<PropertyMigration> properties) { List<PropertyMigration> properties) {
List<PropertyMigration> renamed = new ArrayList<>(); List<PropertyMigration> renamed = new ArrayList<>();
List<PropertyMigration> unsupported = new ArrayList<>(); List<PropertyMigration> unsupported = new ArrayList<>();
properties.forEach((property) -> properties.forEach((property) -> (isRenamed(property) ? renamed : unsupported)
(isRenamed(property) ? renamed : unsupported).add(property)); .add(property));
report.add(name, renamed, unsupported); report.add(name, renamed, unsupported);
if (renamed.isEmpty()) { if (renamed.isEmpty()) {
return null; return null;
...@@ -133,7 +133,7 @@ class PropertiesMigrationReporter { ...@@ -133,7 +133,7 @@ class PropertiesMigrationReporter {
List<ConfigurationMetadataProperty> candidates = this.allProperties.values() List<ConfigurationMetadataProperty> candidates = this.allProperties.values()
.stream().filter(filter).collect(Collectors.toList()); .stream().filter(filter).collect(Collectors.toList());
getPropertySourcesAsMap().forEach((name, source) -> { getPropertySourcesAsMap().forEach((name, source) -> {
candidates.forEach(metadata -> { candidates.forEach((metadata) -> {
ConfigurationProperty configurationProperty = source ConfigurationProperty configurationProperty = source
.getConfigurationProperty( .getConfigurationProperty(
ConfigurationPropertyName.of(metadata.getId())); ConfigurationPropertyName.of(metadata.getId()));
......
...@@ -359,8 +359,8 @@ public class ConfigurationMetadataAnnotationProcessorTests { ...@@ -359,8 +359,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
@Test @Test
public void annotatedGetter() { public void annotatedGetter() {
ConfigurationMetadata metadata = compile(AnnotatedGetter.class); ConfigurationMetadata metadata = compile(AnnotatedGetter.class);
assertThat(metadata).has(Metadata.withGroup("specific") assertThat(metadata)
.fromSource(AnnotatedGetter.class)); .has(Metadata.withGroup("specific").fromSource(AnnotatedGetter.class));
assertThat(metadata).has(Metadata.withProperty("specific.name", String.class) assertThat(metadata).has(Metadata.withProperty("specific.name", String.class)
.fromSource(AnnotatedGetter.class)); .fromSource(AnnotatedGetter.class));
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
...@@ -94,8 +94,8 @@ class InvalidConfigurationPropertyValueFailureAnalyzer ...@@ -94,8 +94,8 @@ class InvalidConfigurationPropertyValueFailureAnalyzer
private void appendReason(StringBuilder message, private void appendReason(StringBuilder message,
InvalidConfigurationPropertyValueException cause) { InvalidConfigurationPropertyValueException cause) {
if (StringUtils.hasText(cause.getReason())) { if (StringUtils.hasText(cause.getReason())) {
message.append(String.format(" Validation failed for the following " message.append(String
+ "reason:%n%n")); .format(" Validation failed for the following " + "reason:%n%n"));
message.append(cause.getReason()); message.append(cause.getReason());
} }
else { else {
......
...@@ -75,8 +75,7 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests { ...@@ -75,8 +75,7 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException( InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException(
"test.property", "invalid", null); "test.property", "invalid", null);
FailureAnalysis analysis = performAnalysis(failure); FailureAnalysis analysis = performAnalysis(failure);
assertThat(analysis.getAction()) assertThat(analysis.getAction()).contains("Review the value of the property.");
.contains("Review the value of the property.");
assertThat(analysis.getDescription()).contains("No reason was provided.") assertThat(analysis.getDescription()).contains("No reason was provided.")
.doesNotContain("Additionally, this property is also set"); .doesNotContain("Additionally, this property is also set");
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -74,7 +74,7 @@ public abstract class AbstractDataSourcePoolMetadataTests<D extends AbstractData ...@@ -74,7 +74,7 @@ public abstract class AbstractDataSourcePoolMetadataTests<D extends AbstractData
final JdbcTemplate jdbcTemplate = new JdbcTemplate( final JdbcTemplate jdbcTemplate = new JdbcTemplate(
getDataSourceMetadata().getDataSource()); getDataSourceMetadata().getDataSource());
jdbcTemplate.execute((ConnectionCallback<Void>) (connection) -> { jdbcTemplate.execute((ConnectionCallback<Void>) (connection) -> {
jdbcTemplate.execute((ConnectionCallback<Void>) connection1 -> { jdbcTemplate.execute((ConnectionCallback<Void>) (connection1) -> {
assertThat(getDataSourceMetadata().getActive()).isEqualTo(2); assertThat(getDataSourceMetadata().getActive()).isEqualTo(2);
assertThat(getDataSourceMetadata().getUsage()).isEqualTo(1.0f); assertThat(getDataSourceMetadata().getUsage()).isEqualTo(1.0f);
return null; return null;
......
...@@ -143,7 +143,7 @@ public abstract class AbstractReactiveWebServerFactoryTests { ...@@ -143,7 +143,7 @@ public abstract class AbstractReactiveWebServerFactoryTests {
protected ReactorClientHttpConnector buildTrustAllSslConnector() { protected ReactorClientHttpConnector buildTrustAllSslConnector() {
return new ReactorClientHttpConnector( return new ReactorClientHttpConnector(
(options) -> options.sslSupport(sslContextBuilder -> { (options) -> options.sslSupport((sslContextBuilder) -> {
sslContextBuilder.sslProvider(SslProvider.JDK) sslContextBuilder.sslProvider(SslProvider.JDK)
.trustManager(InsecureTrustManagerFactory.INSTANCE); .trustManager(InsecureTrustManagerFactory.INSTANCE);
})); }));
...@@ -180,7 +180,7 @@ public abstract class AbstractReactiveWebServerFactoryTests { ...@@ -180,7 +180,7 @@ public abstract class AbstractReactiveWebServerFactoryTests {
.getInstance(KeyManagerFactory.getDefaultAlgorithm()); .getInstance(KeyManagerFactory.getDefaultAlgorithm());
clientKeyManagerFactory.init(clientKeyStore, "password".toCharArray()); clientKeyManagerFactory.init(clientKeyStore, "password".toCharArray());
return new ReactorClientHttpConnector( return new ReactorClientHttpConnector(
(options) -> options.sslSupport(sslContextBuilder -> { (options) -> options.sslSupport((sslContextBuilder) -> {
sslContextBuilder.sslProvider(SslProvider.JDK) sslContextBuilder.sslProvider(SslProvider.JDK)
.trustManager(InsecureTrustManagerFactory.INSTANCE) .trustManager(InsecureTrustManagerFactory.INSTANCE)
.keyManager(clientKeyManagerFactory); .keyManager(clientKeyManagerFactory);
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -38,7 +38,8 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -38,7 +38,8 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"management.server.port=0", "management.server.servlet.context-path=/management" }) "management.server.port=0",
"management.server.servlet.context-path=/management" })
public class ManagementPortAndPathSampleActuatorApplicationTests { public class ManagementPortAndPathSampleActuatorApplicationTests {
@LocalServerPort @LocalServerPort
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -97,8 +97,7 @@ class ApplicationBuilder { ...@@ -97,8 +97,7 @@ class ApplicationBuilder {
return resourcesJar; return resourcesJar;
} }
private void writePom(File appFolder, File resourcesJar) private void writePom(File appFolder, File resourcesJar) throws IOException {
throws IOException {
Map<String, Object> context = new HashMap<>(); Map<String, Object> context = new HashMap<>();
context.put("packaging", this.packaging); context.put("packaging", this.packaging);
context.put("container", this.container); context.put("container", this.container);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment