use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.
the class CloudFoundryHealthMvcEndpointTests method cloudFoundryHealthEndpointShouldAlwaysReturnAllHealthDetails.
@Test
public void cloudFoundryHealthEndpointShouldAlwaysReturnAllHealthDetails() throws Exception {
HealthEndpoint endpoint = mock(HealthEndpoint.class);
given(endpoint.isEnabled()).willReturn(true);
CloudFoundryHealthMvcEndpoint mvc = new CloudFoundryHealthMvcEndpoint(endpoint);
given(endpoint.invoke()).willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
given(endpoint.isSensitive()).willReturn(false);
Object result = mvc.invoke(null, null);
assertThat(result instanceof Health).isTrue();
assertThat(((Health) result).getStatus() == Status.UP).isTrue();
assertThat(((Health) result).getDetails().get("foo")).isEqualTo("bar");
}
use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.
the class EndpointAutoConfigurationTests method healthEndpoint.
@Test
public void healthEndpoint() {
load(EmbeddedDataSourceConfiguration.class, EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class);
HealthEndpoint bean = this.context.getBean(HealthEndpoint.class);
assertThat(bean).isNotNull();
Health result = bean.invoke();
assertThat(result).isNotNull();
assertThat(result.getDetails().containsKey("db")).isTrue();
}
use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.
the class HealthMvcEndpointTests method rightAuthorityPresentShouldExposeDetails.
@Test
public void rightAuthorityPresentShouldExposeDetails() throws Exception {
this.environment.getPropertySources().addLast(SECURITY_ROLES);
Authentication principal = mock(Authentication.class);
Set<SimpleGrantedAuthority> authorities = Collections.singleton(new SimpleGrantedAuthority("HERO"));
doReturn(authorities).when(principal).getAuthorities();
given(this.endpoint.invoke()).willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
Object result = this.mvc.invoke(this.defaultUser, principal);
assertThat(result instanceof Health).isTrue();
assertThat(((Health) result).getStatus() == Status.UP).isTrue();
assertThat(((Health) result).getDetails().get("foo")).isEqualTo("bar");
}
use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.
the class HealthMvcEndpointTests method healthIsCached.
@Test
public void healthIsCached() {
given(this.endpoint.getTimeToLive()).willReturn(10000L);
given(this.endpoint.invoke()).willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
Object result = this.mvc.invoke(this.defaultUser, null);
assertThat(result instanceof Health).isTrue();
Health health = (Health) result;
assertThat(health.getStatus() == Status.UP).isTrue();
assertThat(health.getDetails()).hasSize(1);
assertThat(health.getDetails().get("foo")).isEqualTo("bar");
given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build());
// insecure now
result = this.mvc.invoke(this.request, null);
assertThat(result instanceof Health).isTrue();
health = (Health) result;
// so the result is cached
assertThat(health.getStatus() == Status.UP).isTrue();
// but the details are hidden
assertThat(health.getDetails()).isEmpty();
}
use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.
the class HealthMvcEndpointTests method customMapping.
@Test
@SuppressWarnings("unchecked")
public void customMapping() {
given(this.endpoint.invoke()).willReturn(new Health.Builder().status("OK").build());
this.mvc.setStatusMapping(Collections.singletonMap("OK", HttpStatus.INTERNAL_SERVER_ERROR));
Object result = this.mvc.invoke(this.request, null);
assertThat(result instanceof ResponseEntity).isTrue();
ResponseEntity<Health> response = (ResponseEntity<Health>) result;
assertThat(response.getBody().getStatus().equals(new Status("OK"))).isTrue();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
}
Aggregations