Search in sources :

Example 1 with MvcEndpoint

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

the class LinksEnhancerTests method useNameAsRelIfAvailable.

@Test
public void useNameAsRelIfAvailable() throws Exception {
    TestMvcEndpoint endpoint = new TestMvcEndpoint(new TestEndpoint("a"));
    endpoint.setPath("something-else");
    LinksEnhancer enhancer = getLinksEnhancer(Collections.singletonList((MvcEndpoint) endpoint));
    ResourceSupport support = new ResourceSupport();
    enhancer.addEndpointLinks(support, "");
    assertThat(support.getLink("a").getHref()).contains("/something-else");
}
Also used : AbstractMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.AbstractMvcEndpoint) MvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint) ResourceSupport(org.springframework.hateoas.ResourceSupport) Test(org.junit.Test)

Example 2 with MvcEndpoint

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

the class LinksEnhancerTests method usePathAsRelIfNameNotAvailable.

@Test
public void usePathAsRelIfNameNotAvailable() throws Exception {
    MvcEndpoint endpoint = new NoNameTestMvcEndpoint("/a", false);
    LinksEnhancer enhancer = getLinksEnhancer(Collections.singletonList(endpoint));
    ResourceSupport support = new ResourceSupport();
    enhancer.addEndpointLinks(support, "");
    assertThat(support.getLink("a").getHref()).contains("/a");
}
Also used : AbstractMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.AbstractMvcEndpoint) MvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint) ResourceSupport(org.springframework.hateoas.ResourceSupport) Test(org.junit.Test)

Example 3 with MvcEndpoint

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

the class LinksEnhancerTests method multipleHrefsForSameRelWhenPathIsDifferent.

@Test
public void multipleHrefsForSameRelWhenPathIsDifferent() throws Exception {
    TestMvcEndpoint endpoint = new TestMvcEndpoint(new TestEndpoint("a"));
    endpoint.setPath("endpoint");
    TestMvcEndpoint otherEndpoint = new TestMvcEndpoint(new TestEndpoint("a"));
    otherEndpoint.setPath("other-endpoint");
    LinksEnhancer enhancer = getLinksEnhancer(Arrays.asList((MvcEndpoint) endpoint, otherEndpoint));
    ResourceSupport support = new ResourceSupport();
    enhancer.addEndpointLinks(support, "");
    assertThat(support.getLinks()).haveExactly(1, getCondition("a", "endpoint"));
    assertThat(support.getLinks()).haveExactly(1, getCondition("a", "other-endpoint"));
}
Also used : AbstractMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.AbstractMvcEndpoint) MvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint) ResourceSupport(org.springframework.hateoas.ResourceSupport) Test(org.junit.Test)

Example 4 with MvcEndpoint

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

the class LinksEnhancerTests method hrefNotAddedToRelTwice.

@Test
public void hrefNotAddedToRelTwice() throws Exception {
    MvcEndpoint endpoint = new TestMvcEndpoint(new TestEndpoint("a"));
    MvcEndpoint otherEndpoint = new TestMvcEndpoint(new TestEndpoint("a"));
    LinksEnhancer enhancer = getLinksEnhancer(Arrays.asList(endpoint, otherEndpoint));
    ResourceSupport support = new ResourceSupport();
    enhancer.addEndpointLinks(support, "");
    assertThat(support.getLinks()).haveExactly(1, getCondition("a", "a"));
}
Also used : AbstractMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.AbstractMvcEndpoint) MvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint) ResourceSupport(org.springframework.hateoas.ResourceSupport) Test(org.junit.Test)

Example 5 with MvcEndpoint

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

the class LinksEnhancerTests method getLinksEnhancer.

private LinksEnhancer getLinksEnhancer(List<MvcEndpoint> endpoints) throws Exception {
    StaticWebApplicationContext context = new StaticWebApplicationContext();
    for (MvcEndpoint endpoint : endpoints) {
        context.getDefaultListableBeanFactory().registerSingleton(endpoint.toString(), endpoint);
    }
    MvcEndpoints mvcEndpoints = new MvcEndpoints();
    mvcEndpoints.setApplicationContext(context);
    mvcEndpoints.afterPropertiesSet();
    return new LinksEnhancer("", mvcEndpoints);
}
Also used : AbstractMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.AbstractMvcEndpoint) MvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) MvcEndpoints(org.springframework.boot.actuate.endpoint.mvc.MvcEndpoints)

Aggregations

MvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint)9 Test (org.junit.Test)5 AbstractMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.AbstractMvcEndpoint)5 ResourceSupport (org.springframework.hateoas.ResourceSupport)4 Template (groovy.text.Template)1 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 AuditEventsMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.AuditEventsMvcEndpoint)1 EndpointHandlerMapping (org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping)1 EndpointHandlerMappingCustomizer (org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMappingCustomizer)1 EnvironmentMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint)1 HealthMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint)1 HeapdumpMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.HeapdumpMvcEndpoint)1 LogFileMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.LogFileMvcEndpoint)1 LoggersMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint)1 MetricsMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint)1 MvcEndpointSecurityInterceptor (org.springframework.boot.actuate.endpoint.mvc.MvcEndpointSecurityInterceptor)1 MvcEndpoints (org.springframework.boot.actuate.endpoint.mvc.MvcEndpoints)1