Search in sources :

Example 6 with InvocationContext

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

the class CachingOperationInvokerTests method cacheInTtlWithMonoResponse.

@Test
void cacheInTtlWithMonoResponse() {
    MonoOperationInvoker.invocations = new AtomicInteger();
    MonoOperationInvoker target = new MonoOperationInvoker();
    InvocationContext context = new InvocationContext(mock(SecurityContext.class), Collections.emptyMap());
    CachingOperationInvoker invoker = new CachingOperationInvoker(target, CACHE_TTL);
    Object response = ((Mono<?>) invoker.invoke(context)).block();
    Object cachedResponse = ((Mono<?>) invoker.invoke(context)).block();
    assertThat(MonoOperationInvoker.invocations).hasValue(1);
    assertThat(response).isSameAs(cachedResponse);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Mono(reactor.core.publisher.Mono) SecurityContext(org.springframework.boot.actuate.endpoint.SecurityContext) InvocationContext(org.springframework.boot.actuate.endpoint.InvocationContext) Test(org.junit.jupiter.api.Test)

Example 7 with InvocationContext

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

the class ReflectiveOperationInvokerTests method invokeShouldInvokeMethod.

@Test
void invokeShouldInvokeMethod() {
    ReflectiveOperationInvoker invoker = new ReflectiveOperationInvoker(this.target, this.operationMethod, this.parameterValueMapper);
    Object result = invoker.invoke(new InvocationContext(mock(SecurityContext.class), Collections.singletonMap("name", "boot")));
    assertThat(result).isEqualTo("toob");
}
Also used : InvocationContext(org.springframework.boot.actuate.endpoint.InvocationContext) Test(org.junit.jupiter.api.Test)

Example 8 with InvocationContext

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

the class ReflectiveOperationInvokerTests method invokeShouldResolveParameters.

@Test
void invokeShouldResolveParameters() {
    ReflectiveOperationInvoker invoker = new ReflectiveOperationInvoker(this.target, this.operationMethod, this.parameterValueMapper);
    Object result = invoker.invoke(new InvocationContext(mock(SecurityContext.class), Collections.singletonMap("name", 1234)));
    assertThat(result).isEqualTo("4321");
}
Also used : InvocationContext(org.springframework.boot.actuate.endpoint.InvocationContext) Test(org.junit.jupiter.api.Test)

Example 9 with InvocationContext

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

the class DiscoveredOperationsFactoryTests method createOperationShouldApplyAdvisors.

@Test
void createOperationShouldApplyAdvisors() {
    TestOperationInvokerAdvisor advisor = new TestOperationInvokerAdvisor();
    this.invokerAdvisors.add(advisor);
    TestOperation operation = getFirst(this.factory.createOperations(EndpointId.of("test"), new ExampleRead()));
    operation.invoke(new InvocationContext(mock(SecurityContext.class), Collections.emptyMap()));
    assertThat(advisor.getEndpointId()).isEqualTo(EndpointId.of("test"));
    assertThat(advisor.getOperationType()).isEqualTo(OperationType.READ);
    assertThat(advisor.getParameters()).isEmpty();
}
Also used : InvocationContext(org.springframework.boot.actuate.endpoint.InvocationContext) Test(org.junit.jupiter.api.Test)

Example 10 with InvocationContext

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

the class DiscoveredOperationsFactoryTests method createOperationsShouldProviderInvoker.

@Test
void createOperationsShouldProviderInvoker() {
    TestOperation operation = getFirst(this.factory.createOperations(EndpointId.of("test"), new ExampleWithParams()));
    Map<String, Object> params = Collections.singletonMap("name", 123);
    Object result = operation.invoke(new InvocationContext(mock(SecurityContext.class), params));
    assertThat(result).isEqualTo("123");
}
Also used : InvocationContext(org.springframework.boot.actuate.endpoint.InvocationContext) Test(org.junit.jupiter.api.Test)

Aggregations

InvocationContext (org.springframework.boot.actuate.endpoint.InvocationContext)17 Test (org.junit.jupiter.api.Test)14 SecurityContext (org.springframework.boot.actuate.endpoint.SecurityContext)11 OperationInvoker (org.springframework.boot.actuate.endpoint.invoke.OperationInvoker)7 HashMap (java.util.HashMap)4 Principal (java.security.Principal)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Mono (reactor.core.publisher.Mono)2 AttributeNotFoundException (javax.management.AttributeNotFoundException)1 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)1 MBeanException (javax.management.MBeanException)1 ReflectionException (javax.management.ReflectionException)1 ApiVersion (org.springframework.boot.actuate.endpoint.ApiVersion)1 InvalidEndpointRequestException (org.springframework.boot.actuate.endpoint.InvalidEndpointRequestException)1 ExposableWebEndpoint (org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint)1 WebOperation (org.springframework.boot.actuate.endpoint.web.WebOperation)1 Flux (reactor.core.publisher.Flux)1