Search in sources :

Example 1 with WebOperation

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

the class CloudFoundryActuatorAutoConfigurationTests method endpointPathCustomizationIsNotApplied.

@Test
void endpointPathCustomizationIsNotApplied() {
    this.contextRunner.withPropertyValues("VCAP_APPLICATION:---", "vcap.application.application_id:my-app-id", "vcap.application.cf_api:https://my-cloud-controller.com", "management.endpoints.web.path-mapping.test=custom").withBean(TestEndpoint.class, TestEndpoint::new).run((context) -> {
        CloudFoundryWebEndpointServletHandlerMapping handlerMapping = getHandlerMapping(context);
        Collection<ExposableWebEndpoint> endpoints = handlerMapping.getEndpoints();
        ExposableWebEndpoint endpoint = endpoints.stream().filter((candidate) -> EndpointId.of("test").equals(candidate.getEndpointId())).findFirst().get();
        Collection<WebOperation> operations = endpoint.getOperations();
        assertThat(operations).hasSize(1);
        assertThat(operations.iterator().next().getRequestPredicate().getPath()).isEqualTo("test");
    });
}
Also used : WebOperation(org.springframework.boot.actuate.endpoint.web.WebOperation) ExposableWebEndpoint(org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint) Test(org.junit.jupiter.api.Test)

Example 2 with WebOperation

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

the class CloudFoundryWebEndpointDiscovererTests method getEndpointsShouldAddCloudFoundryHealthExtension.

@Test
void getEndpointsShouldAddCloudFoundryHealthExtension() {
    load(TestConfiguration.class, (discoverer) -> {
        Collection<ExposableWebEndpoint> endpoints = discoverer.getEndpoints();
        assertThat(endpoints.size()).isEqualTo(2);
        for (ExposableWebEndpoint endpoint : endpoints) {
            if (endpoint.getEndpointId().equals(EndpointId.of("health"))) {
                WebOperation operation = findMainReadOperation(endpoint);
                assertThat(operation.invoke(new InvocationContext(mock(SecurityContext.class), Collections.emptyMap()))).isEqualTo("cf");
            }
        }
    });
}
Also used : WebOperation(org.springframework.boot.actuate.endpoint.web.WebOperation) ExposableWebEndpoint(org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint) InvocationContext(org.springframework.boot.actuate.endpoint.InvocationContext) Test(org.junit.jupiter.api.Test)

Example 3 with WebOperation

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

the class ReactiveCloudFoundryActuatorAutoConfigurationTests method healthEndpointInvokerShouldBeCloudFoundryWebExtension.

@Test
void healthEndpointInvokerShouldBeCloudFoundryWebExtension() {
    this.contextRunner.withConfiguration(AutoConfigurations.of(HealthEndpointAutoConfiguration.class)).withPropertyValues("VCAP_APPLICATION:---", "vcap.application.application_id:my-app-id", "vcap.application.cf_api:https://my-cloud-controller.com").run((context) -> {
        Collection<ExposableWebEndpoint> endpoints = getHandlerMapping(context).getEndpoints();
        ExposableWebEndpoint endpoint = endpoints.iterator().next();
        assertThat(endpoint.getOperations()).hasSize(2);
        WebOperation webOperation = findOperationWithRequestPath(endpoint, "health");
        assertThat(webOperation).extracting("invoker").extracting("target").isInstanceOf(CloudFoundryReactiveHealthEndpointWebExtension.class);
    });
}
Also used : WebOperation(org.springframework.boot.actuate.endpoint.web.WebOperation) ExposableWebEndpoint(org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint) HealthEndpointAutoConfiguration(org.springframework.boot.actuate.autoconfigure.health.HealthEndpointAutoConfiguration) Test(org.junit.jupiter.api.Test)

Example 4 with WebOperation

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

the class AdditionalHealthEndpointPathsWebMvcHandlerMapping method initHandlerMethods.

@Override
protected void initHandlerMethods() {
    for (WebOperation operation : this.endpoint.getOperations()) {
        WebOperationRequestPredicate predicate = operation.getRequestPredicate();
        String matchAllRemainingPathSegmentsVariable = predicate.getMatchAllRemainingPathSegmentsVariable();
        if (matchAllRemainingPathSegmentsVariable != null) {
            for (HealthEndpointGroup group : this.groups) {
                AdditionalHealthEndpointPath additionalPath = group.getAdditionalPath();
                if (additionalPath != null) {
                    registerMapping(this.endpoint, predicate, operation, additionalPath.getValue());
                }
            }
        }
    }
}
Also used : WebOperation(org.springframework.boot.actuate.endpoint.web.WebOperation) WebOperationRequestPredicate(org.springframework.boot.actuate.endpoint.web.WebOperationRequestPredicate) AdditionalHealthEndpointPath(org.springframework.boot.actuate.health.AdditionalHealthEndpointPath) HealthEndpointGroup(org.springframework.boot.actuate.health.HealthEndpointGroup)

Example 5 with WebOperation

use of org.springframework.boot.actuate.endpoint.web.WebOperation 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)

Aggregations

WebOperation (org.springframework.boot.actuate.endpoint.web.WebOperation)8 Test (org.junit.jupiter.api.Test)6 ExposableWebEndpoint (org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint)6 WebOperationRequestPredicate (org.springframework.boot.actuate.endpoint.web.WebOperationRequestPredicate)2 AdditionalHealthEndpointPath (org.springframework.boot.actuate.health.AdditionalHealthEndpointPath)2 HealthEndpointGroup (org.springframework.boot.actuate.health.HealthEndpointGroup)2 HealthEndpointAutoConfiguration (org.springframework.boot.actuate.autoconfigure.health.HealthEndpointAutoConfiguration)1 EndpointId (org.springframework.boot.actuate.endpoint.EndpointId)1 InvocationContext (org.springframework.boot.actuate.endpoint.InvocationContext)1 CachingOperationInvoker (org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvoker)1 RequestMappingInfo (org.springframework.web.reactive.result.method.RequestMappingInfo)1