Search in sources :

Example 11 with ExposableWebEndpoint

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

the class WebEndpointDiscovererTests method getEndpointsWhenHasCacheWithTtlShouldCacheReadOperationWithTtlValue.

@Test
void getEndpointsWhenHasCacheWithTtlShouldCacheReadOperationWithTtlValue() {
    load((id) -> 500L, EndpointId::toString, TestEndpointConfiguration.class, (discoverer) -> {
        Map<EndpointId, ExposableWebEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
        assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
        ExposableWebEndpoint endpoint = endpoints.get(EndpointId.of("test"));
        assertThat(endpoint.getOperations()).hasSize(1);
        WebOperation operation = endpoint.getOperations().iterator().next();
        Object invoker = ReflectionTestUtils.getField(operation, "invoker");
        assertThat(invoker).isInstanceOf(CachingOperationInvoker.class);
        assertThat(((CachingOperationInvoker) invoker).getTimeToLive()).isEqualTo(500);
    });
}
Also used : WebOperation(org.springframework.boot.actuate.endpoint.web.WebOperation) ExposableWebEndpoint(org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint) EndpointId(org.springframework.boot.actuate.endpoint.EndpointId) CachingOperationInvoker(org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvoker) Test(org.junit.jupiter.api.Test)

Example 12 with ExposableWebEndpoint

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

the class CloudFoundryActuatorAutoConfiguration method cloudFoundryWebEndpointServletHandlerMapping.

@Bean
public CloudFoundryWebEndpointServletHandlerMapping cloudFoundryWebEndpointServletHandlerMapping(ParameterValueMapper parameterMapper, EndpointMediaTypes endpointMediaTypes, RestTemplateBuilder restTemplateBuilder, ServletEndpointsSupplier servletEndpointsSupplier, ControllerEndpointsSupplier controllerEndpointsSupplier, ApplicationContext applicationContext) {
    CloudFoundryWebEndpointDiscoverer discoverer = new CloudFoundryWebEndpointDiscoverer(applicationContext, parameterMapper, endpointMediaTypes, null, Collections.emptyList(), Collections.emptyList());
    CloudFoundrySecurityInterceptor securityInterceptor = getSecurityInterceptor(restTemplateBuilder, applicationContext.getEnvironment());
    Collection<ExposableWebEndpoint> webEndpoints = discoverer.getEndpoints();
    List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
    allEndpoints.addAll(webEndpoints);
    allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
    allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
    return new CloudFoundryWebEndpointServletHandlerMapping(new EndpointMapping("/cloudfoundryapplication"), webEndpoints, endpointMediaTypes, getCorsConfiguration(), securityInterceptor, new EndpointLinksResolver(allEndpoints));
}
Also used : CloudFoundryWebEndpointDiscoverer(org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryWebEndpointDiscoverer) ExposableWebEndpoint(org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint) ExposableEndpoint(org.springframework.boot.actuate.endpoint.ExposableEndpoint) ArrayList(java.util.ArrayList) EndpointLinksResolver(org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver) EndpointMapping(org.springframework.boot.actuate.endpoint.web.EndpointMapping) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) Bean(org.springframework.context.annotation.Bean)

Example 13 with ExposableWebEndpoint

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

the class WebEndpointDiscovererTests method getEndpointsWhenOperationReturnsResourceShouldProduceApplicationOctetStream.

@Test
void getEndpointsWhenOperationReturnsResourceShouldProduceApplicationOctetStream() {
    load(ResourceEndpointConfiguration.class, (discoverer) -> {
        Map<EndpointId, ExposableWebEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
        assertThat(endpoints).containsOnlyKeys(EndpointId.of("resource"));
        ExposableWebEndpoint endpoint = endpoints.get(EndpointId.of("resource"));
        assertThat(requestPredicates(endpoint)).has(requestPredicates(path("resource").httpMethod(WebEndpointHttpMethod.GET).consumes().produces("application/octet-stream")));
    });
}
Also used : ExposableWebEndpoint(org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint) EndpointId(org.springframework.boot.actuate.endpoint.EndpointId) Test(org.junit.jupiter.api.Test)

Example 14 with ExposableWebEndpoint

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

the class WebEndpointDiscovererTests method getEndpointsWhenPredicateForWriteOperationThatReturnsVoidShouldHaveNoProducedMediaTypes.

@Test
void getEndpointsWhenPredicateForWriteOperationThatReturnsVoidShouldHaveNoProducedMediaTypes() {
    load(VoidWriteOperationEndpointConfiguration.class, (discoverer) -> {
        Map<EndpointId, ExposableWebEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
        assertThat(endpoints).containsOnlyKeys(EndpointId.of("voidwrite"));
        ExposableWebEndpoint endpoint = endpoints.get(EndpointId.of("voidwrite"));
        assertThat(requestPredicates(endpoint)).has(requestPredicates(path("voidwrite").httpMethod(WebEndpointHttpMethod.POST).produces().consumes("application/json")));
    });
}
Also used : ExposableWebEndpoint(org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint) EndpointId(org.springframework.boot.actuate.endpoint.EndpointId) Test(org.junit.jupiter.api.Test)

Example 15 with ExposableWebEndpoint

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

the class WebEndpointDiscovererTests method getEndpointsWhenHasWebExtensionShouldOverrideStandardEndpoint.

@Test
void getEndpointsWhenHasWebExtensionShouldOverrideStandardEndpoint() {
    load(OverriddenOperationWebEndpointExtensionConfiguration.class, (discoverer) -> {
        Map<EndpointId, ExposableWebEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
        assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
        ExposableWebEndpoint endpoint = endpoints.get(EndpointId.of("test"));
        assertThat(requestPredicates(endpoint)).has(requestPredicates(path("test").httpMethod(WebEndpointHttpMethod.GET).consumes().produces("application/json")));
    });
}
Also used : ExposableWebEndpoint(org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint) EndpointId(org.springframework.boot.actuate.endpoint.EndpointId) Test(org.junit.jupiter.api.Test)

Aggregations

ExposableWebEndpoint (org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint)19 Test (org.junit.jupiter.api.Test)13 EndpointId (org.springframework.boot.actuate.endpoint.EndpointId)7 WebOperation (org.springframework.boot.actuate.endpoint.web.WebOperation)6 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)6 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)6 Bean (org.springframework.context.annotation.Bean)6 ArrayList (java.util.ArrayList)5 EndpointMapping (org.springframework.boot.actuate.endpoint.web.EndpointMapping)5 ExposableEndpoint (org.springframework.boot.actuate.endpoint.ExposableEndpoint)4 EndpointLinksResolver (org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver)4 CloudFoundryWebEndpointDiscoverer (org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryWebEndpointDiscoverer)2 ConditionalOnAvailableEndpoint (org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint)2 ConditionalOnManagementPort (org.springframework.boot.actuate.autoconfigure.web.server.ConditionalOnManagementPort)2 List (java.util.List)1 HealthEndpointAutoConfiguration (org.springframework.boot.actuate.autoconfigure.health.HealthEndpointAutoConfiguration)1 InvocationContext (org.springframework.boot.actuate.endpoint.InvocationContext)1 CachingOperationInvoker (org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvoker)1 WebOperationRequestPredicate (org.springframework.boot.actuate.endpoint.web.WebOperationRequestPredicate)1 WebEndpointDiscoverer (org.springframework.boot.actuate.endpoint.web.annotation.WebEndpointDiscoverer)1