Search in sources :

Example 1 with DiscoveredOperationMethod

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

the class RequestPredicateFactoryTests method getRequestPredicateWhenHasMoreThanOneMatchAllThrowsException.

@Test
void getRequestPredicateWhenHasMoreThanOneMatchAllThrowsException() {
    DiscoveredOperationMethod operationMethod = getDiscoveredOperationMethod(MoreThanOneMatchAll.class);
    assertThatIllegalStateException().isThrownBy(() -> this.factory.getRequestPredicate(this.rootPath, operationMethod)).withMessage("@Selector annotation with Match.ALL_REMAINING must be unique");
}
Also used : DiscoveredOperationMethod(org.springframework.boot.actuate.endpoint.annotation.DiscoveredOperationMethod) Test(org.junit.jupiter.api.Test)

Example 2 with DiscoveredOperationMethod

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

the class RequestPredicateFactoryTests method getRequestPredicateReturnsPredicateWithPath.

@Test
void getRequestPredicateReturnsPredicateWithPath() {
    DiscoveredOperationMethod operationMethod = getDiscoveredOperationMethod(ValidSelectors.class);
    WebOperationRequestPredicate requestPredicate = this.factory.getRequestPredicate(this.rootPath, operationMethod);
    assertThat(requestPredicate.getPath()).isEqualTo("/root/{one}/{*two}");
}
Also used : WebOperationRequestPredicate(org.springframework.boot.actuate.endpoint.web.WebOperationRequestPredicate) DiscoveredOperationMethod(org.springframework.boot.actuate.endpoint.annotation.DiscoveredOperationMethod) Test(org.junit.jupiter.api.Test)

Example 3 with DiscoveredOperationMethod

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

the class RequestPredicateFactoryTests method getRequestPredicateWhenMatchAllIsNotLastParameterThrowsException.

@Test
void getRequestPredicateWhenMatchAllIsNotLastParameterThrowsException() {
    DiscoveredOperationMethod operationMethod = getDiscoveredOperationMethod(MatchAllIsNotLastParameter.class);
    assertThatIllegalStateException().isThrownBy(() -> this.factory.getRequestPredicate(this.rootPath, operationMethod)).withMessage("@Selector annotation with Match.ALL_REMAINING must be the last parameter");
}
Also used : DiscoveredOperationMethod(org.springframework.boot.actuate.endpoint.annotation.DiscoveredOperationMethod) Test(org.junit.jupiter.api.Test)

Example 4 with DiscoveredOperationMethod

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

the class RequestPredicateFactoryTests method getDiscoveredOperationMethod.

private DiscoveredOperationMethod getDiscoveredOperationMethod(Class<?> source) {
    Method method = source.getDeclaredMethods()[0];
    AnnotationAttributes attributes = new AnnotationAttributes();
    attributes.put("produces", "application/json");
    return new DiscoveredOperationMethod(method, OperationType.READ, attributes);
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) DiscoveredOperationMethod(org.springframework.boot.actuate.endpoint.annotation.DiscoveredOperationMethod) DiscoveredOperationMethod(org.springframework.boot.actuate.endpoint.annotation.DiscoveredOperationMethod) Method(java.lang.reflect.Method)

Example 5 with DiscoveredOperationMethod

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

the class RequestPredicateFactory method getRequestPredicate.

WebOperationRequestPredicate getRequestPredicate(String rootPath, DiscoveredOperationMethod operationMethod) {
    Method method = operationMethod.getMethod();
    Parameter[] selectorParameters = Arrays.stream(method.getParameters()).filter(this::hasSelector).toArray(Parameter[]::new);
    Parameter allRemainingPathSegmentsParameter = getAllRemainingPathSegmentsParameter(selectorParameters);
    String path = getPath(rootPath, selectorParameters, allRemainingPathSegmentsParameter != null);
    WebEndpointHttpMethod httpMethod = determineHttpMethod(operationMethod.getOperationType());
    Collection<String> consumes = getConsumes(httpMethod, method);
    Collection<String> produces = getProduces(operationMethod, method);
    return new WebOperationRequestPredicate(path, httpMethod, consumes, produces);
}
Also used : WebOperationRequestPredicate(org.springframework.boot.actuate.endpoint.web.WebOperationRequestPredicate) Parameter(java.lang.reflect.Parameter) DiscoveredOperationMethod(org.springframework.boot.actuate.endpoint.annotation.DiscoveredOperationMethod) WebEndpointHttpMethod(org.springframework.boot.actuate.endpoint.web.WebEndpointHttpMethod) Method(java.lang.reflect.Method) WebEndpointHttpMethod(org.springframework.boot.actuate.endpoint.web.WebEndpointHttpMethod)

Aggregations

DiscoveredOperationMethod (org.springframework.boot.actuate.endpoint.annotation.DiscoveredOperationMethod)6 Method (java.lang.reflect.Method)3 Test (org.junit.jupiter.api.Test)3 WebOperationRequestPredicate (org.springframework.boot.actuate.endpoint.web.WebOperationRequestPredicate)2 AnnotationAttributes (org.springframework.core.annotation.AnnotationAttributes)2 Parameter (java.lang.reflect.Parameter)1 OperationInvoker (org.springframework.boot.actuate.endpoint.invoke.OperationInvoker)1 WebEndpointHttpMethod (org.springframework.boot.actuate.endpoint.web.WebEndpointHttpMethod)1