Formatting

pull/13266/merge
Phillip Webb 7 years ago
parent 2215709165
commit 3702da4573

@ -44,8 +44,8 @@ public abstract class CompositeReactiveHealthIndicatorConfiguration<H extends Re
return createHealthIndicator(beans.values().iterator().next());
}
ReactiveHealthIndicatorRegistry registry = new DefaultReactiveHealthIndicatorRegistry();
beans.forEach((name, source) -> registry.register(name,
createHealthIndicator(source)));
beans.forEach(
(name, source) -> registry.register(name, createHealthIndicator(source)));
return new CompositeReactiveHealthIndicator(this.healthAggregator, registry);
}

@ -89,9 +89,11 @@ public class HealthIndicatorAutoConfiguration {
public ReactiveHealthIndicatorRegistry reactiveHealthIndicatorRegistry(
ObjectProvider<Map<String, ReactiveHealthIndicator>> reactiveHealthIndicators,
ObjectProvider<Map<String, HealthIndicator>> healthIndicators) {
return new ReactiveHealthIndicatorRegistryFactory().createReactiveHealthIndicatorRegistry(
reactiveHealthIndicators.getIfAvailable(Collections::emptyMap),
healthIndicators.getIfAvailable(Collections::emptyMap));
return new ReactiveHealthIndicatorRegistryFactory()
.createReactiveHealthIndicatorRegistry(
reactiveHealthIndicators
.getIfAvailable(Collections::emptyMap),
healthIndicators.getIfAvailable(Collections::emptyMap));
}
}

@ -57,10 +57,12 @@ public class PropertiesMeterFilter implements MeterFilter {
private static MeterFilter createMapFilter(Map<String, String> tags) {
if (tags.isEmpty()) {
return new MeterFilter() { };
return new MeterFilter() {
};
}
Tags commonTags = Tags.of(tags.entrySet().stream().map((entry) ->
Tag.of(entry.getKey(), entry.getValue())).collect(Collectors.toList()));
Tags commonTags = Tags.of(tags.entrySet().stream()
.map((entry) -> Tag.of(entry.getKey(), entry.getValue()))
.collect(Collectors.toList()));
return MeterFilter.commonTags(commonTags);
}

@ -73,8 +73,8 @@ public class CloudFoundryWebEndpointDiscovererTests {
return operation;
}
}
throw new IllegalStateException("No main read operation found from "
+ endpoint.getOperations());
throw new IllegalStateException(
"No main read operation found from " + endpoint.getOperations());
}
private void load(Class<?> configuration,

@ -61,8 +61,7 @@ public class HealthEndpointDocumentationTests extends MockMvcEndpointDocumentati
fieldWithPath("status")
.description("Status of a specific part of the application"),
subsectionWithPath("details").description(
"Details of the health of a specific part of the"
+ " application."));
"Details of the health of a specific part of the" + " application."));
@Test
public void health() throws Exception {
@ -111,18 +110,17 @@ public class HealthEndpointDocumentationTests extends MockMvcEndpointDocumentati
}
@Bean
public DataSourceHealthIndicator dbHealthIndicator(
DataSource dataSource) {
public DataSourceHealthIndicator dbHealthIndicator(DataSource dataSource) {
return new DataSourceHealthIndicator(dataSource);
}
@Bean
public CompositeHealthIndicator brokerHealthIndicator() {
Map<String, HealthIndicator> indicators = new LinkedHashMap<>();
indicators.put("us1", () -> Health.up().withDetail("version", "1.0.2")
.build());
indicators.put("us2", () -> Health.up().withDetail("version", "1.0.4")
.build());
indicators.put("us1",
() -> Health.up().withDetail("version", "1.0.2").build());
indicators.put("us2",
() -> Health.up().withDetail("version", "1.0.4").build());
return new CompositeHealthIndicator(new OrderedHealthAggregator(),
new DefaultHealthIndicatorRegistry(indicators));
}

@ -53,8 +53,7 @@ import static org.mockito.Mockito.mock;
public class HealthEndpointWebExtensionTests {
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withUserConfiguration(HealthIndicatorsConfiguration.class)
.withConfiguration(
.withUserConfiguration(HealthIndicatorsConfiguration.class).withConfiguration(
AutoConfigurations.of(HealthIndicatorAutoConfiguration.class,
HealthEndpointAutoConfiguration.class));
@ -96,8 +95,9 @@ public class HealthEndpointWebExtensionTests {
this.contextRunner.run((context) -> {
HealthEndpointWebExtension extension = context
.getBean(HealthEndpointWebExtension.class);
assertThat(extension.health(mock(SecurityContext.class)).getBody()
.getDetails()).isEmpty();
assertThat(
extension.health(mock(SecurityContext.class)).getBody().getDetails())
.isEmpty();
});
}
@ -124,9 +124,8 @@ public class HealthEndpointWebExtensionTests {
SecurityContext securityContext = mock(SecurityContext.class);
given(securityContext.getPrincipal())
.willReturn(mock(Principal.class));
assertThat(
extension.health(securityContext).getBody().getDetails())
.isNotEmpty();
assertThat(extension.health(securityContext).getBody().getDetails())
.isNotEmpty();
});
}
@ -165,9 +164,8 @@ public class HealthEndpointWebExtensionTests {
given(securityContext.getPrincipal())
.willReturn(mock(Principal.class));
given(securityContext.isUserInRole("ACTUATOR")).willReturn(false);
assertThat(
extension.health(securityContext).getBody().getDetails())
.isEmpty();
assertThat(extension.health(securityContext).getBody().getDetails())
.isEmpty();
});
}
@ -182,9 +180,8 @@ public class HealthEndpointWebExtensionTests {
given(securityContext.getPrincipal())
.willReturn(mock(Principal.class));
given(securityContext.isUserInRole("ACTUATOR")).willReturn(true);
assertThat(
extension.health(securityContext).getBody().getDetails())
.isNotEmpty();
assertThat(extension.health(securityContext).getBody().getDetails())
.isNotEmpty();
});
}
@ -193,8 +190,8 @@ public class HealthEndpointWebExtensionTests {
this.contextRunner.run((context) -> {
HealthEndpointWebExtension extension = context
.getBean(HealthEndpointWebExtension.class);
assertDetailsNotFound(extension.healthForComponent(
mock(SecurityContext.class), "simple"));
assertDetailsNotFound(
extension.healthForComponent(mock(SecurityContext.class), "simple"));
});
}
@ -205,8 +202,8 @@ public class HealthEndpointWebExtensionTests {
.getBean(HealthEndpointWebExtension.class);
SecurityContext securityContext = mock(SecurityContext.class);
given(securityContext.getPrincipal()).willReturn(mock(Principal.class));
assertDetailsNotFound(extension.healthForComponent(securityContext,
"simple"));
assertDetailsNotFound(
extension.healthForComponent(securityContext, "simple"));
});
}
@ -221,8 +218,8 @@ public class HealthEndpointWebExtensionTests {
SecurityContext securityContext = mock(SecurityContext.class);
given(securityContext.getPrincipal())
.willReturn(mock(Principal.class));
assertSimpleComponent(extension.healthForComponent(
securityContext, "simple"));
assertSimpleComponent(
extension.healthForComponent(securityContext, "simple"));
});
}
@ -244,8 +241,8 @@ public class HealthEndpointWebExtensionTests {
.run((context) -> {
HealthEndpointWebExtension extension = context
.getBean(HealthEndpointWebExtension.class);
assertDetailsNotFound(extension.healthForComponent(
mock(SecurityContext.class), "simple"));
assertDetailsNotFound(extension
.healthForComponent(mock(SecurityContext.class), "simple"));
});
}
@ -254,15 +251,15 @@ public class HealthEndpointWebExtensionTests {
this.contextRunner.withPropertyValues(
"management.endpoint.health.show-details=when-authorized",
"management.endpoint.health.roles=ACTUATOR").run((context) -> {
HealthEndpointWebExtension extension = context
.getBean(HealthEndpointWebExtension.class);
SecurityContext securityContext = mock(SecurityContext.class);
given(securityContext.getPrincipal())
.willReturn(mock(Principal.class));
given(securityContext.isUserInRole("ACTUATOR")).willReturn(false);
assertDetailsNotFound(extension.healthForComponent(securityContext,
"simple"));
});
HealthEndpointWebExtension extension = context
.getBean(HealthEndpointWebExtension.class);
SecurityContext securityContext = mock(SecurityContext.class);
given(securityContext.getPrincipal())
.willReturn(mock(Principal.class));
given(securityContext.isUserInRole("ACTUATOR")).willReturn(false);
assertDetailsNotFound(
extension.healthForComponent(securityContext, "simple"));
});
}
@Test
@ -270,15 +267,15 @@ public class HealthEndpointWebExtensionTests {
this.contextRunner.withPropertyValues(
"management.endpoint.health.show-details=when-authorized",
"management.endpoint.health.roles=ACTUATOR").run((context) -> {
HealthEndpointWebExtension extension = context
.getBean(HealthEndpointWebExtension.class);
SecurityContext securityContext = mock(SecurityContext.class);
given(securityContext.getPrincipal())
.willReturn(mock(Principal.class));
given(securityContext.isUserInRole("ACTUATOR")).willReturn(true);
assertSimpleComponent(extension.healthForComponent(securityContext,
"simple"));
});
HealthEndpointWebExtension extension = context
.getBean(HealthEndpointWebExtension.class);
SecurityContext securityContext = mock(SecurityContext.class);
given(securityContext.getPrincipal())
.willReturn(mock(Principal.class));
given(securityContext.isUserInRole("ACTUATOR")).willReturn(true);
assertSimpleComponent(
extension.healthForComponent(securityContext, "simple"));
});
}
@Test
@ -288,8 +285,8 @@ public class HealthEndpointWebExtensionTests {
.run((context) -> {
HealthEndpointWebExtension extension = context
.getBean(HealthEndpointWebExtension.class);
assertDetailsNotFound(extension.healthForComponent(null,
"does-not-exist"));
assertDetailsNotFound(
extension.healthForComponent(null, "does-not-exist"));
});
}
@ -360,15 +357,15 @@ public class HealthEndpointWebExtensionTests {
this.contextRunner.withPropertyValues(
"management.endpoint.health.show-details=when-authorized",
"management.endpoint.health.roles=ACTUATOR").run((context) -> {
HealthEndpointWebExtension extension = context
.getBean(HealthEndpointWebExtension.class);
SecurityContext securityContext = mock(SecurityContext.class);
given(securityContext.getPrincipal())
.willReturn(mock(Principal.class));
given(securityContext.isUserInRole("ACTUATOR")).willReturn(false);
assertDetailsNotFound(extension.healthForComponentInstance(securityContext,
"composite", "one"));
});
HealthEndpointWebExtension extension = context
.getBean(HealthEndpointWebExtension.class);
SecurityContext securityContext = mock(SecurityContext.class);
given(securityContext.getPrincipal())
.willReturn(mock(Principal.class));
given(securityContext.isUserInRole("ACTUATOR")).willReturn(false);
assertDetailsNotFound(extension.healthForComponentInstance(
securityContext, "composite", "one"));
});
}
@Test
@ -376,15 +373,15 @@ public class HealthEndpointWebExtensionTests {
this.contextRunner.withPropertyValues(
"management.endpoint.health.show-details=when-authorized",
"management.endpoint.health.roles=ACTUATOR").run((context) -> {
HealthEndpointWebExtension extension = context
.getBean(HealthEndpointWebExtension.class);
SecurityContext securityContext = mock(SecurityContext.class);
given(securityContext.getPrincipal())
.willReturn(mock(Principal.class));
given(securityContext.isUserInRole("ACTUATOR")).willReturn(true);
assertSimpleComponent(extension.healthForComponentInstance(securityContext,
"composite", "one"));
});
HealthEndpointWebExtension extension = context
.getBean(HealthEndpointWebExtension.class);
SecurityContext securityContext = mock(SecurityContext.class);
given(securityContext.getPrincipal())
.willReturn(mock(Principal.class));
given(securityContext.isUserInRole("ACTUATOR")).willReturn(true);
assertSimpleComponent(extension.healthForComponentInstance(
securityContext, "composite", "one"));
});
}
@Test
@ -406,8 +403,7 @@ public class HealthEndpointWebExtensionTests {
private void assertSimpleComponent(WebEndpointResponse<Health> response) {
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
assertThat(response.getBody().getDetails()).containsOnly(
entry("counter", 42));
assertThat(response.getBody().getDetails()).containsOnly(entry("counter", 42));
}
@Test
@ -421,9 +417,8 @@ public class HealthEndpointWebExtensionTests {
given(securityContext.getPrincipal())
.willReturn(mock(Principal.class));
given(securityContext.isUserInRole("ADMIN")).willReturn(true);
assertThat(
extension.health(securityContext).getBody().getDetails())
.isNotEmpty();
assertThat(extension.health(securityContext).getBody().getDetails())
.isNotEmpty();
});
}

@ -220,12 +220,11 @@ public class ReactiveHealthEndpointWebExtensionTests {
@Test
public void registryCanBeAltered() {
this.contextRunner
.withUserConfiguration(HealthIndicatorsConfiguration.class)
this.contextRunner.withUserConfiguration(HealthIndicatorsConfiguration.class)
.withPropertyValues("management.endpoint.health.show-details=always")
.run((context) -> {
ReactiveHealthIndicatorRegistry registry = context.getBean(
ReactiveHealthIndicatorRegistry.class);
ReactiveHealthIndicatorRegistry registry = context
.getBean(ReactiveHealthIndicatorRegistry.class);
ReactiveHealthEndpointWebExtension extension = context
.getBean(ReactiveHealthEndpointWebExtension.class);
assertThat(extension.health(null).block().getBody().getDetails())

@ -58,13 +58,12 @@ public class MetricsAutoConfigurationIntegrationTests {
@Test
public void propertyBasedCommonTagsIsAutoConfigured() {
this.contextRunner.withPropertyValues("management.metrics.tags.region=test",
"management.metrics.tags.origin=local")
.run((context) -> {
"management.metrics.tags.origin=local").run((context) -> {
MeterRegistry registry = context.getBean(MeterRegistry.class);
registry.counter("my.counter", "env", "qa");
assertThat(registry.find("my.counter").tags("env", "qa")
.tags("region", "test").tags("origin", "local").counter())
.isNotNull();
.isNotNull();
});
}

@ -68,8 +68,8 @@ public class CachesEndpoint {
new CacheDescriptor(entry.getTarget()));
});
Map<String, CacheManagerDescriptor> cacheManagerDescriptors = new LinkedHashMap<>();
descriptors.forEach((name, entries) ->
cacheManagerDescriptors.put(name, new CacheManagerDescriptor(entries)));
descriptors.forEach((name, entries) -> cacheManagerDescriptors.put(name,
new CacheManagerDescriptor(entries)));
return new CachesReport(cacheManagerDescriptors);
}

@ -45,11 +45,10 @@ public class CompositeHealthIndicator implements HealthIndicator {
}
/**
* Create a new {@link CompositeHealthIndicator} from the specified
* indicators.
* Create a new {@link CompositeHealthIndicator} from the specified indicators.
* @param healthAggregator the health aggregator
* @param indicators a map of {@link HealthIndicator HealthIndicators} with
* the key being used as an indicator name.
* @param indicators a map of {@link HealthIndicator HealthIndicators} with the key
* being used as an indicator name.
* @deprecated since 2.1.0 in favour of
* {@link #CompositeHealthIndicator(HealthAggregator, HealthIndicatorRegistry)}
*/
@ -60,8 +59,8 @@ public class CompositeHealthIndicator implements HealthIndicator {
}
/**
* Create a new {@link CompositeHealthIndicator} from the indicators in the
* given {@code registry}.
* Create a new {@link CompositeHealthIndicator} from the indicators in the given
* {@code registry}.
* @param healthAggregator the health aggregator
* @param registry the registry of {@link HealthIndicator HealthIndicators}.
*/
@ -72,12 +71,11 @@ public class CompositeHealthIndicator implements HealthIndicator {
}
/**
* Adds the given {@code healthIndicator}, associating it with the given
* {@code name}.
* Adds the given {@code healthIndicator}, associating it with the given {@code name}.
* @param name the name of the indicator
* @param indicator the indicator
* @throws IllegalStateException if an indicator with the given {@code name}
* is already registered.
* @throws IllegalStateException if an indicator with the given {@code name} is
* already registered.
* @deprecated since 2.1.0 in favour of
* {@link HealthIndicatorRegistry#register(String, HealthIndicator)}
*/

@ -57,8 +57,8 @@ public class CompositeHealthIndicatorFactory {
Assert.notNull(healthIndicators, "HealthIndicators must not be null");
HealthIndicatorRegistryFactory factory = new HealthIndicatorRegistryFactory(
this.healthIndicatorNameFactory);
return new CompositeHealthIndicator(
healthAggregator, factory.createHealthIndicatorRegistry(healthIndicators));
return new CompositeHealthIndicator(healthAggregator,
factory.createHealthIndicatorRegistry(healthIndicators));
}
}

@ -91,8 +91,8 @@ public class CompositeReactiveHealthIndicator implements ReactiveHealthIndicator
* @param name the name of the health indicator
* @param indicator the health indicator to add
* @return this instance
* @throws IllegalStateException if an indicator with the given {@code name}
* is already registered.
* @throws IllegalStateException if an indicator with the given {@code name} is
* already registered.
* @deprecated since 2.1.0 in favour of
* {@link ReactiveHealthIndicatorRegistry#register(String, ReactiveHealthIndicator)}
*/

@ -43,10 +43,9 @@ public class DefaultHealthIndicatorRegistry implements HealthIndicatorRegistry {
}
/**
* Create a new {@link DefaultHealthIndicatorRegistry} from the specified
* indicators.
* @param healthIndicators a map of {@link HealthIndicator}s with the key
* being used as an indicator name.
* Create a new {@link DefaultHealthIndicatorRegistry} from the specified indicators.
* @param healthIndicators a map of {@link HealthIndicator}s with the key being used
* as an indicator name.
*/
public DefaultHealthIndicatorRegistry(Map<String, HealthIndicator> healthIndicators) {
Assert.notNull(healthIndicators, "HealthIndicators must not be null");

@ -46,8 +46,8 @@ public class DefaultReactiveHealthIndicatorRegistry
/**
* Create a new {@link DefaultReactiveHealthIndicatorRegistry} from the specified
* indicators.
* @param healthIndicators a map of {@link HealthIndicator}s with the key
* being used as an indicator name.
* @param healthIndicators a map of {@link HealthIndicator}s with the key being used
* as an indicator name.
*/
public DefaultReactiveHealthIndicatorRegistry(
Map<String, ReactiveHealthIndicator> healthIndicators) {

@ -65,8 +65,8 @@ public class HealthEndpointWebExtension {
public WebEndpointResponse<Health> healthForComponentInstance(
SecurityContext securityContext, @Selector String component,
@Selector String instance) {
Supplier<Health> health = () -> this.delegate.healthForComponentInstance(
component, instance);
Supplier<Health> health = () -> this.delegate
.healthForComponentInstance(component, instance);
return this.responseMapper.mapDetails(health, securityContext);
}

@ -31,36 +31,35 @@ import java.util.Map;
public interface HealthIndicatorRegistry {
/**
* Registers the given {@link HealthIndicator}, associating it with the
* given {@code name}.
* Registers the given {@link HealthIndicator}, associating it with the given
* {@code name}.
* @param name the name of the indicator
* @param healthIndicator the indicator
* @throws IllegalStateException if an indicator with the given {@code name}
* is already registered.
* @throws IllegalStateException if an indicator with the given {@code name} is
* already registered.
*/
void register(String name, HealthIndicator healthIndicator);
/**
* Unregisters the {@link HealthIndicator} previously registered with the
* given {@code name}.
* Unregisters the {@link HealthIndicator} previously registered with the given
* {@code name}.
* @param name the name of the indicator
* @return the unregistered indicator, or {@code null} if no indicator was
* found in the registry for the given {@code name}.
* @return the unregistered indicator, or {@code null} if no indicator was found in
* the registry for the given {@code name}.
*/
HealthIndicator unregister(String name);
/**
* Returns the {@link HealthIndicator} registered with the given {@code name}.
* @param name the name of the indicator
* @return the health indicator, or {@code null} if no indicator was
* registered with the given {@code name}.
* @return the health indicator, or {@code null} if no indicator was registered with
* the given {@code name}.
*/
HealthIndicator get(String name);
/**
* Returns a snapshot of the registered health indicators and their names.
* The contents of the map do not reflect subsequent changes to the
* registry.
* Returns a snapshot of the registered health indicators and their names. The
* contents of the map do not reflect subsequent changes to the registry.
* @return the snapshot of registered health indicators
*/
Map<String, HealthIndicator> getAll();

@ -41,10 +41,8 @@ public class HealthIndicatorRegistryFactory {
}
/**
* Create a {@link HealthIndicatorRegistry} based on the specified health
* indicators.
* @param healthIndicators the {@link HealthIndicator} instances mapped by
* name
* Create a {@link HealthIndicatorRegistry} based on the specified health indicators.
* @param healthIndicators the {@link HealthIndicator} instances mapped by name
* @return a {@link HealthIndicator} that delegates to the specified
* {@code healthIndicators}.
*/

@ -31,12 +31,12 @@ import java.util.Map;
public interface ReactiveHealthIndicatorRegistry {
/**
* Registers the given {@link ReactiveHealthIndicator}, associating it with the
* given {@code name}.
* Registers the given {@link ReactiveHealthIndicator}, associating it with the given
* {@code name}.
* @param name the name of the indicator
* @param healthIndicator the indicator
* @throws IllegalStateException if an indicator with the given {@code name}
* is already registered.
* @throws IllegalStateException if an indicator with the given {@code name} is
* already registered.
*/
void register(String name, ReactiveHealthIndicator healthIndicator);
@ -44,23 +44,22 @@ public interface ReactiveHealthIndicatorRegistry {
* Unregisters the {@link ReactiveHealthIndicator} previously registered with the
* given {@code name}.
* @param name the name of the indicator
* @return the unregistered indicator, or {@code null} if no indicator was
* found in the registry for the given {@code name}.
* @return the unregistered indicator, or {@code null} if no indicator was found in
* the registry for the given {@code name}.
*/
ReactiveHealthIndicator unregister(String name);
/**
* Returns the {@link ReactiveHealthIndicator} registered with the given {@code name}.
* @param name the name of the indicator
* @return the health indicator, or {@code null} if no indicator was
* registered with the given {@code name}.
* @return the health indicator, or {@code null} if no indicator was registered with
* the given {@code name}.
*/
ReactiveHealthIndicator get(String name);
/**
* Returns a snapshot of the registered health indicators and their names.
* The contents of the map do not reflect subsequent changes to the
* registry.
* Returns a snapshot of the registered health indicators and their names. The
* contents of the map do not reflect subsequent changes to the registry.
* @return the snapshot of registered health indicators
*/
Map<String, ReactiveHealthIndicator> getAll();

@ -45,7 +45,7 @@ public class CompositeReactiveHealthIndicatorTests {
public void singleIndicator() {
CompositeReactiveHealthIndicator indicator = new CompositeReactiveHealthIndicator(
this.healthAggregator, new DefaultReactiveHealthIndicatorRegistry(
Collections.singletonMap("test", () -> Mono.just(HEALTHY))));
Collections.singletonMap("test", () -> Mono.just(HEALTHY))));
StepVerifier.create(indicator.health()).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.UP);
assertThat(h.getDetails()).containsOnlyKeys("test");
@ -64,9 +64,9 @@ public class CompositeReactiveHealthIndicatorTests {
new DefaultReactiveHealthIndicatorRegistry(indicators));
StepVerifier.withVirtualTime(indicator::health).expectSubscription()
.thenAwait(Duration.ofMillis(10000)).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.UP);
assertThat(h.getDetails()).hasSize(50);
}).verifyComplete();
assertThat(h.getStatus()).isEqualTo(Status.UP);
assertThat(h.getDetails()).hasSize(50);
}).verifyComplete();
}
@ -78,7 +78,7 @@ public class CompositeReactiveHealthIndicatorTests {
CompositeReactiveHealthIndicator indicator = new CompositeReactiveHealthIndicator(
this.healthAggregator,
new DefaultReactiveHealthIndicatorRegistry(indicators))
.timeoutStrategy(100, UNKNOWN_HEALTH);
.timeoutStrategy(100, UNKNOWN_HEALTH);
StepVerifier.create(indicator.health()).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.UP);
assertThat(h.getDetails()).containsOnlyKeys("slow", "fast");
@ -95,14 +95,14 @@ public class CompositeReactiveHealthIndicatorTests {
CompositeReactiveHealthIndicator indicator = new CompositeReactiveHealthIndicator(
this.healthAggregator,
new DefaultReactiveHealthIndicatorRegistry(indicators))
.timeoutStrategy(20000, null);
.timeoutStrategy(20000, null);
StepVerifier.withVirtualTime(indicator::health).expectSubscription()
.thenAwait(Duration.ofMillis(10000)).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.UP);
assertThat(h.getDetails()).containsOnlyKeys("slow", "fast");
assertThat(h.getDetails().get("slow")).isEqualTo(HEALTHY);
assertThat(h.getDetails().get("fast")).isEqualTo(HEALTHY);
}).verifyComplete();
assertThat(h.getStatus()).isEqualTo(Status.UP);
assertThat(h.getDetails()).containsOnlyKeys("slow", "fast");
assertThat(h.getDetails().get("slow")).isEqualTo(HEALTHY);
assertThat(h.getDetails().get("fast")).isEqualTo(HEALTHY);
}).verifyComplete();
}
static class TimeoutHealth implements ReactiveHealthIndicator {

@ -47,10 +47,10 @@ public class DefaultReactiveHealthIndicatorRegistryTests {
@Before
public void setUp() {
given(this.one.health()).willReturn(Mono.just(
new Health.Builder().unknown().withDetail("1", "1").build()));
given(this.two.health()).willReturn(Mono.just(
new Health.Builder().unknown().withDetail("2", "2").build()));
given(this.one.health()).willReturn(
Mono.just(new Health.Builder().unknown().withDetail("1", "1").build()));
given(this.two.health()).willReturn(
Mono.just(new Health.Builder().unknown().withDetail("2", "2").build()));
this.registry = new DefaultReactiveHealthIndicatorRegistry();
}

@ -59,8 +59,8 @@ public class HealthEndpointTests {
@Test
public void statusForComponentIsExposed() {
HealthEndpoint endpoint = new HealthEndpoint(createHealthIndicator(
Collections.singletonMap("test", one)));
HealthEndpoint endpoint = new HealthEndpoint(
createHealthIndicator(Collections.singletonMap("test", one)));
Health health = endpoint.healthForComponent("test");
assertThat(health).isNotNull();
assertThat(health.getStatus()).isEqualTo(Status.UP);
@ -69,8 +69,8 @@ public class HealthEndpointTests {
@Test
public void statusForUnknownComponentReturnNull() {
HealthEndpoint endpoint = new HealthEndpoint(createHealthIndicator(
Collections.emptyMap()));
HealthEndpoint endpoint = new HealthEndpoint(
createHealthIndicator(Collections.emptyMap()));
Health health = endpoint.healthForComponent("does-not-exist");
assertThat(health).isNull();
}
@ -79,7 +79,7 @@ public class HealthEndpointTests {
public void statusForComponentInstanceIsExposed() {
CompositeHealthIndicator compositeIndicator = new CompositeHealthIndicator(
new OrderedHealthAggregator(), new DefaultHealthIndicatorRegistry(
Collections.singletonMap("sub", () -> Health.down().build())));
Collections.singletonMap("sub", () -> Health.down().build())));
HealthEndpoint endpoint = new HealthEndpoint(createHealthIndicator(
Collections.singletonMap("test", compositeIndicator)));
Health health = endpoint.healthForComponentInstance("test", "sub");
@ -92,7 +92,7 @@ public class HealthEndpointTests {
public void statusForUnknownComponentInstanceReturnNull() {
CompositeHealthIndicator compositeIndicator = new CompositeHealthIndicator(
new OrderedHealthAggregator(), new DefaultHealthIndicatorRegistry(
Collections.singletonMap("sub", () -> Health.down().build())));
Collections.singletonMap("sub", () -> Health.down().build())));
HealthEndpoint endpoint = new HealthEndpoint(createHealthIndicator(
Collections.singletonMap("test", compositeIndicator)));
Health health = endpoint.healthForComponentInstance("test", "does-not-exist");

@ -56,9 +56,9 @@ public class HealthEndpointWebIntegrationTests {
registry.register("charlie", () -> Health.down().build());
try {
client.get().uri("/actuator/health").exchange().expectStatus()
.isEqualTo(HttpStatus.SERVICE_UNAVAILABLE).expectBody().jsonPath("status")
.isEqualTo("DOWN").jsonPath("details.alpha.status").isEqualTo("UP")
.jsonPath("details.bravo.status").isEqualTo("UP")
.isEqualTo(HttpStatus.SERVICE_UNAVAILABLE).expectBody()
.jsonPath("status").isEqualTo("DOWN").jsonPath("details.alpha.status")
.isEqualTo("UP").jsonPath("details.bravo.status").isEqualTo("UP")
.jsonPath("details.charlie.status").isEqualTo("DOWN");
}
finally {
@ -71,9 +71,10 @@ public class HealthEndpointWebIntegrationTests {
HealthIndicatorRegistry registry = context.getBean(HealthIndicatorRegistry.class);
HealthIndicator bravo = registry.unregister("bravo");
try {
client.get().uri("/actuator/health").exchange().expectStatus().isOk().expectBody()
.jsonPath("status").isEqualTo("UP").jsonPath("details.alpha.status")
.isEqualTo("UP").jsonPath("details.bravo.status").doesNotExist();
client.get().uri("/actuator/health").exchange().expectStatus().isOk()
.expectBody().jsonPath("status").isEqualTo("UP")
.jsonPath("details.alpha.status").isEqualTo("UP")
.jsonPath("details.bravo.status").doesNotExist();
}
finally {
registry.register("bravo", bravo);

@ -62,7 +62,8 @@ public class HealthWebEndpointResponseMapperTests {
@Test
public void mapDetailsWithUnauthorizedUserDoesNotInvokeSupplier() {
HealthWebEndpointResponseMapper mapper = createMapper(ShowDetails.WHEN_AUTHORIZED);
HealthWebEndpointResponseMapper mapper = createMapper(
ShowDetails.WHEN_AUTHORIZED);
Supplier<Health> supplier = mockSupplier();
SecurityContext securityContext = mockSecurityContext("USER");
WebEndpointResponse<Health> response = mapper.mapDetails(supplier,
@ -75,13 +76,15 @@ public class HealthWebEndpointResponseMapperTests {
@Test
public void mapDetailsWithAuthorizedUserInvokeSupplier() {
HealthWebEndpointResponseMapper mapper = createMapper(ShowDetails.WHEN_AUTHORIZED);
HealthWebEndpointResponseMapper mapper = createMapper(
ShowDetails.WHEN_AUTHORIZED);
Supplier<Health> supplier = mockSupplier();
given(supplier.get()).willReturn(Health.down().build());
SecurityContext securityContext = mockSecurityContext("ACTUATOR");
WebEndpointResponse<Health> response = mapper.mapDetails(supplier,
securityContext);
assertThat(response.getStatus()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE.value());
assertThat(response.getStatus())
.isEqualTo(HttpStatus.SERVICE_UNAVAILABLE.value());
assertThat(response.getBody().getStatus()).isEqualTo(Status.DOWN);
verify(supplier).get();
verify(securityContext).isUserInRole("ACTUATOR");
@ -108,12 +111,12 @@ public class HealthWebEndpointResponseMapperTests {
private SecurityContext mockSecurityContext(String... roles) {
List<String> associatedRoles = Arrays.asList(roles);
SecurityContext securityContext = mock(SecurityContext.class);
given(securityContext.getPrincipal())
.willReturn(mock(Principal.class));
given(securityContext.isUserInRole(anyString())).will((Answer<Boolean>) invocation -> {
String expectedRole = invocation.getArgument(0);
return associatedRoles.contains(expectedRole);
});
given(securityContext.getPrincipal()).willReturn(mock(Principal.class));
given(securityContext.isUserInRole(anyString()))
.will((Answer<Boolean>) invocation -> {
String expectedRole = invocation.getArgument(0);
return associatedRoles.contains(expectedRole);
});
return securityContext;
}

@ -39,16 +39,18 @@ public class ReactiveHealthIndicatorRegistryFactoryTests {
@Test
public void defaultHealthIndicatorNameFactory() {
ReactiveHealthIndicatorRegistry registry = this.factory.createReactiveHealthIndicatorRegistry(
Collections.singletonMap("myHealthIndicator", () -> Mono.just(UP)), null);
ReactiveHealthIndicatorRegistry registry = this.factory
.createReactiveHealthIndicatorRegistry(Collections
.singletonMap("myHealthIndicator", () -> Mono.just(UP)), null);
assertThat(registry.getAll()).containsOnlyKeys("my");
}
@Test
public void healthIndicatorIsAdapted() {
ReactiveHealthIndicatorRegistry registry = this.factory.createReactiveHealthIndicatorRegistry(
Collections.singletonMap("test", () -> Mono.just(UP)),
Collections.singletonMap("regular", () -> DOWN));
ReactiveHealthIndicatorRegistry registry = this.factory
.createReactiveHealthIndicatorRegistry(
Collections.singletonMap("test", () -> Mono.just(UP)),
Collections.singletonMap("regular", () -> DOWN));
assertThat(registry.getAll()).containsOnlyKeys("test", "regular");
StepVerifier.create(registry.get("regular").health()).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.DOWN);

@ -34,4 +34,5 @@ public interface RestClientBuilderCustomizer {
* @param builder the builder to customize
*/
void customize(RestClientBuilder builder);
}

@ -47,8 +47,6 @@ public class RestClientProperties {
*/
private String password;
public List<String> getUris() {
return this.uris;
}
@ -72,4 +70,5 @@ public class RestClientProperties {
public void setPassword(String password) {
this.password = password;
}
}

@ -72,8 +72,8 @@ public class JestAutoConfigurationTests {
@Test
public void jestClientOnLocalhostByDefault() {
this.contextRunner.run((context) ->
assertThat(context).hasSingleBean(JestClient.class));
this.contextRunner
.run((context) -> assertThat(context).hasSingleBean(JestClient.class));
}
@Test
@ -130,11 +130,12 @@ public class JestAutoConfigurationTests {
Map<String, String> source = new HashMap<>();
source.put("a", "alpha");
source.put("b", "bravo");
Index index = new Index.Builder(source).index("foo")
.type("bar").id("1").build();
Index index = new Index.Builder(source).index("foo").type("bar")
.id("1").build();
execute(client, index);
Get getRequest = new Get.Builder("foo", "1").build();
assertThat(execute(client, getRequest).getResponseCode()).isEqualTo(200);
assertThat(execute(client, getRequest).getResponseCode())
.isEqualTo(200);
}));
}

@ -100,6 +100,7 @@ public class RestClientAutoConfigurationTests {
public RestClient customRestClient() {
return mock(RestClient.class);
}
}
@Configuration
@ -109,6 +110,7 @@ public class RestClientAutoConfigurationTests {
public RestClientBuilderCustomizer myCustomizer() {
return (builder) -> builder.setMaxRetryTimeoutMillis(42);
}
}
}

@ -181,15 +181,13 @@ public class LiquibaseAutoConfigurationTests {
@Test
public void overrideTestRollbackOnUpdate() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues(
"spring.liquibase.test-rollback-on-update:true")
.withPropertyValues("spring.liquibase.test-rollback-on-update:true")
.run((context) -> {
SpringLiquibase liquibase = context.getBean(SpringLiquibase.class);
assertThat(liquibase.isTestRollbackOnUpdate()).isTrue();
});
}
@Test
public void changeLogDoesNotExist() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)

@ -43,8 +43,7 @@ public class WebMvcTestPageableIntegrationTests {
@Test
public void shouldSupportPageable() throws Exception {
this.mvc.perform(get("/paged").param("page", "2").param("size", "42"))
.andExpect(status().isOk())
.andExpect(content().string("2:42"));
.andExpect(status().isOk()).andExpect(content().string("2:42"));
}
}

@ -267,7 +267,8 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
+ "]");
}
if (hasWorkingDirectorySet()) {
getLog().warn("Fork mode disabled, ignoring working directory configuration");
getLog().warn(
"Fork mode disabled, ignoring working directory configuration");
}
}
}
@ -475,7 +476,8 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
private void logArguments(String message, String[] args) {
if (getLog().isDebugEnabled()) {
getLog().debug(Arrays.stream(args).collect(Collectors.joining(" ", message, "")));
getLog().debug(
Arrays.stream(args).collect(Collectors.joining(" ", message, "")));
}
}

@ -229,9 +229,9 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
}
/**
* Return the source {@link Artifact} to repackage. If a classifier is specified
* and an artifact with that classifier exists, it is used. Otherwise, the main
* artifact is used.
* Return the source {@link Artifact} to repackage. If a classifier is specified and
* an artifact with that classifier exists, it is used. Otherwise, the main artifact
* is used.
* @return the source artifact to repackage
*/
private Artifact getSourceArtifact() {

Loading…
Cancel
Save