use of org.springframework.boot.actuate.endpoint.invoke.OperationInvoker in project spring-boot by spring-projects.
the class CachingOperationInvokerTests method targetInvokedWithDifferentWebServerNamespace.
@Test
void targetInvokedWithDifferentWebServerNamespace() {
OperationInvoker target = mock(OperationInvoker.class);
Object expectedServer = new Object();
Object expectedManagement = new Object();
InvocationContext contextServer = new InvocationContext(mock(SecurityContext.class), Collections.emptyMap(), new WebServerNamespaceArgumentResolver(WebServerNamespace.SERVER));
InvocationContext contextManagement = new InvocationContext(mock(SecurityContext.class), Collections.emptyMap(), new WebServerNamespaceArgumentResolver(WebServerNamespace.MANAGEMENT));
given(target.invoke(contextServer)).willReturn(expectedServer);
given(target.invoke(contextManagement)).willReturn(expectedManagement);
CachingOperationInvoker invoker = new CachingOperationInvoker(target, CACHE_TTL);
Object responseServer = invoker.invoke(contextServer);
assertThat(responseServer).isSameAs(expectedServer);
then(target).should(times(1)).invoke(contextServer);
Object responseManagement = invoker.invoke(contextManagement);
assertThat(responseManagement).isNotSameAs(responseServer);
then(target).should(times(1)).invoke(contextManagement);
}
use of org.springframework.boot.actuate.endpoint.invoke.OperationInvoker in project spring-boot by spring-projects.
the class CachingOperationInvokerTests method targetInvokedWhenCacheExpires.
@Test
void targetInvokedWhenCacheExpires() throws InterruptedException {
OperationInvoker target = mock(OperationInvoker.class);
Map<String, Object> parameters = new HashMap<>();
InvocationContext context = new InvocationContext(mock(SecurityContext.class), parameters);
given(target.invoke(context)).willReturn(new Object());
CachingOperationInvoker invoker = new CachingOperationInvoker(target, 50L);
invoker.invoke(context);
long expired = System.currentTimeMillis() + 50;
while (System.currentTimeMillis() < expired) {
Thread.sleep(10);
}
invoker.invoke(context);
then(target).should(times(2)).invoke(context);
}
use of org.springframework.boot.actuate.endpoint.invoke.OperationInvoker in project spring-boot by spring-projects.
the class CachingOperationInvokerTests method targetInvokedWhenCalledWithAndWithoutPrincipal.
@Test
void targetInvokedWhenCalledWithAndWithoutPrincipal() {
OperationInvoker target = mock(OperationInvoker.class);
Map<String, Object> parameters = new HashMap<>();
SecurityContext anonymous = mock(SecurityContext.class);
SecurityContext authenticated = mock(SecurityContext.class);
given(authenticated.getPrincipal()).willReturn(mock(Principal.class));
InvocationContext anonymousContext = new InvocationContext(anonymous, parameters);
Object anonymousResult = new Object();
given(target.invoke(anonymousContext)).willReturn(anonymousResult);
InvocationContext authenticatedContext = new InvocationContext(authenticated, parameters);
Object authenticatedResult = new Object();
given(target.invoke(authenticatedContext)).willReturn(authenticatedResult);
CachingOperationInvoker invoker = new CachingOperationInvoker(target, CACHE_TTL);
assertThat(invoker.invoke(anonymousContext)).isEqualTo(anonymousResult);
assertThat(invoker.invoke(authenticatedContext)).isEqualTo(authenticatedResult);
assertThat(invoker.invoke(anonymousContext)).isEqualTo(anonymousResult);
assertThat(invoker.invoke(authenticatedContext)).isEqualTo(authenticatedResult);
then(target).should().invoke(anonymousContext);
then(target).should().invoke(authenticatedContext);
}
use of org.springframework.boot.actuate.endpoint.invoke.OperationInvoker in project spring-boot by spring-projects.
the class DiscoveredOperationsFactory method createOperation.
private O createOperation(EndpointId endpointId, Object target, Method method, OperationType operationType, Class<? extends Annotation> annotationType) {
MergedAnnotation<?> annotation = MergedAnnotations.from(method).get(annotationType);
if (!annotation.isPresent()) {
return null;
}
DiscoveredOperationMethod operationMethod = new DiscoveredOperationMethod(method, operationType, annotation.asAnnotationAttributes());
OperationInvoker invoker = new ReflectiveOperationInvoker(target, operationMethod, this.parameterValueMapper);
invoker = applyAdvisors(endpointId, operationMethod, invoker);
return createOperation(endpointId, operationMethod, invoker);
}
Aggregations