Search in sources :

Example 1 with HealthEndpoint

use of org.springframework.boot.actuate.endpoint.HealthEndpoint in project spring-boot by spring-projects.

the class CloudFoundryEndpointHandlerMappingTests method registersCloudFoundryHealthEndpoint.

@Test
public void registersCloudFoundryHealthEndpoint() throws Exception {
    StaticApplicationContext context = new StaticApplicationContext();
    HealthEndpoint delegate = new HealthEndpoint(new OrderedHealthAggregator(), Collections.<String, HealthIndicator>emptyMap());
    CloudFoundryEndpointHandlerMapping handlerMapping = new CloudFoundryEndpointHandlerMapping(Collections.singleton(new TestHealthMvcEndpoint(delegate)), null, null);
    handlerMapping.setPrefix("/test");
    handlerMapping.setApplicationContext(context);
    handlerMapping.afterPropertiesSet();
    HandlerExecutionChain handler = handlerMapping.getHandler(new MockHttpServletRequest("GET", "/test/health"));
    HandlerMethod handlerMethod = (HandlerMethod) handler.getHandler();
    Object handlerMethodBean = handlerMethod.getBean();
    assertThat(handlerMethodBean).isInstanceOf(CloudFoundryHealthMvcEndpoint.class);
}
Also used : HealthEndpoint(org.springframework.boot.actuate.endpoint.HealthEndpoint) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) OrderedHealthAggregator(org.springframework.boot.actuate.health.OrderedHealthAggregator) HandlerMethod(org.springframework.web.method.HandlerMethod) Test(org.junit.Test)

Example 2 with HealthEndpoint

use of org.springframework.boot.actuate.endpoint.HealthEndpoint in project spring-boot by spring-projects.

the class EndpointAutoConfigurationTests method healthEndpointWithDefaultHealthIndicator.

@Test
public void healthEndpointWithDefaultHealthIndicator() {
    load(EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class);
    HealthEndpoint bean = this.context.getBean(HealthEndpoint.class);
    assertThat(bean).isNotNull();
    Health result = bean.invoke();
    assertThat(result).isNotNull();
}
Also used : HealthEndpoint(org.springframework.boot.actuate.endpoint.HealthEndpoint) Health(org.springframework.boot.actuate.health.Health) Test(org.junit.Test)

Example 3 with HealthEndpoint

use of org.springframework.boot.actuate.endpoint.HealthEndpoint 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");
}
Also used : HealthEndpoint(org.springframework.boot.actuate.endpoint.HealthEndpoint) Health(org.springframework.boot.actuate.health.Health) Test(org.junit.Test)

Example 4 with HealthEndpoint

use of org.springframework.boot.actuate.endpoint.HealthEndpoint 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();
}
Also used : HealthEndpoint(org.springframework.boot.actuate.endpoint.HealthEndpoint) Health(org.springframework.boot.actuate.health.Health) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 HealthEndpoint (org.springframework.boot.actuate.endpoint.HealthEndpoint)4 Health (org.springframework.boot.actuate.health.Health)3 OrderedHealthAggregator (org.springframework.boot.actuate.health.OrderedHealthAggregator)1 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 HandlerMethod (org.springframework.web.method.HandlerMethod)1 HandlerExecutionChain (org.springframework.web.servlet.HandlerExecutionChain)1