Search in sources :

Example 6 with EndpointId

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

the class WebEndpointDiscovererTests method getEndpointsWhenExtensionAddsOperationShouldHaveBothOperations.

@Test
void getEndpointsWhenExtensionAddsOperationShouldHaveBothOperations() {
    load(AdditionalOperationWebEndpointConfiguration.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"), path("test/{id}").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)

Example 7 with EndpointId

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

the class WebEndpointDiscovererTests method getEndpointsWhenHasCustomPathShouldReturnCustomPath.

@Test
void getEndpointsWhenHasCustomPathShouldReturnCustomPath() {
    load((id) -> null, (id) -> "custom/" + id, AdditionalOperationWebEndpointConfiguration.class, (discoverer) -> {
        Map<EndpointId, ExposableWebEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
        assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
        ExposableWebEndpoint endpoint = endpoints.get(EndpointId.of("test"));
        Condition<List<? extends WebOperationRequestPredicate>> expected = requestPredicates(path("custom/test").httpMethod(WebEndpointHttpMethod.GET).consumes().produces("application/json"), path("custom/test/{id}").httpMethod(WebEndpointHttpMethod.GET).consumes().produces("application/json"));
        assertThat(requestPredicates(endpoint)).has(expected);
    });
}
Also used : WebOperationRequestPredicate(org.springframework.boot.actuate.endpoint.web.WebOperationRequestPredicate) ExposableWebEndpoint(org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint) EndpointId(org.springframework.boot.actuate.endpoint.EndpointId) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 8 with EndpointId

use of org.springframework.boot.actuate.endpoint.EndpointId 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 9 with EndpointId

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

the class JmxEndpointDiscovererTests method getEndpointsShouldDiscoverStandardEndpoints.

@Test
void getEndpointsShouldDiscoverStandardEndpoints() {
    load(TestEndpoint.class, (discoverer) -> {
        Map<EndpointId, ExposableJmxEndpoint> endpoints = discover(discoverer);
        assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
        Map<String, JmxOperation> operationByName = mapOperations(endpoints.get(EndpointId.of("test")).getOperations());
        assertThat(operationByName).containsOnlyKeys("getAll", "getSomething", "update", "deleteSomething");
        JmxOperation getAll = operationByName.get("getAll");
        assertThat(getAll.getDescription()).isEqualTo("Invoke getAll for endpoint test");
        assertThat(getAll.getOutputType()).isEqualTo(Object.class);
        assertThat(getAll.getParameters()).isEmpty();
        JmxOperation getSomething = operationByName.get("getSomething");
        assertThat(getSomething.getDescription()).isEqualTo("Invoke getSomething for endpoint test");
        assertThat(getSomething.getOutputType()).isEqualTo(String.class);
        assertThat(getSomething.getParameters()).hasSize(1);
        assertThat(getSomething.getParameters().get(0).getType()).isEqualTo(String.class);
        JmxOperation update = operationByName.get("update");
        assertThat(update.getDescription()).isEqualTo("Invoke update for endpoint test");
        assertThat(update.getOutputType()).isEqualTo(Void.TYPE);
        assertThat(update.getParameters()).hasSize(2);
        assertThat(update.getParameters().get(0).getType()).isEqualTo(String.class);
        assertThat(update.getParameters().get(1).getType()).isEqualTo(String.class);
        JmxOperation deleteSomething = operationByName.get("deleteSomething");
        assertThat(deleteSomething.getDescription()).isEqualTo("Invoke deleteSomething for endpoint test");
        assertThat(deleteSomething.getOutputType()).isEqualTo(Void.TYPE);
        assertThat(deleteSomething.getParameters()).hasSize(1);
        assertThat(deleteSomething.getParameters().get(0).getType()).isEqualTo(String.class);
    });
}
Also used : JmxOperation(org.springframework.boot.actuate.endpoint.jmx.JmxOperation) ExposableJmxEndpoint(org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint) EndpointId(org.springframework.boot.actuate.endpoint.EndpointId) Test(org.junit.jupiter.api.Test)

Example 10 with EndpointId

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

Aggregations

EndpointId (org.springframework.boot.actuate.endpoint.EndpointId)13 Test (org.junit.jupiter.api.Test)11 ExposableWebEndpoint (org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint)7 ExposableJmxEndpoint (org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint)4 JmxOperation (org.springframework.boot.actuate.endpoint.jmx.JmxOperation)4 CachingOperationInvoker (org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvoker)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1 EndpointExposure (org.springframework.boot.actuate.autoconfigure.endpoint.expose.EndpointExposure)1 WebOperation (org.springframework.boot.actuate.endpoint.web.WebOperation)1 WebOperationRequestPredicate (org.springframework.boot.actuate.endpoint.web.WebOperationRequestPredicate)1 ConditionMessage (org.springframework.boot.autoconfigure.condition.ConditionMessage)1 ConditionOutcome (org.springframework.boot.autoconfigure.condition.ConditionOutcome)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1