Search in sources :

Example 6 with OperationInvoker

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

the class CachingOperationInvokerAdvisorTests method applyWhenOperationIsNotReadShouldNotAddAdvise.

@Test
void applyWhenOperationIsNotReadShouldNotAddAdvise() {
    OperationParameters parameters = getParameters("get");
    OperationInvoker advised = this.advisor.apply(EndpointId.of("foo"), OperationType.WRITE, parameters, this.invoker);
    assertThat(advised).isSameAs(this.invoker);
}
Also used : OperationParameters(org.springframework.boot.actuate.endpoint.invoke.OperationParameters) OperationInvoker(org.springframework.boot.actuate.endpoint.invoke.OperationInvoker) Test(org.junit.jupiter.api.Test)

Example 7 with OperationInvoker

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

the class CachingOperationInvokerAdvisorTests method assertAdviseIsApplied.

private void assertAdviseIsApplied(OperationParameters parameters) {
    OperationInvoker advised = this.advisor.apply(EndpointId.of("foo"), OperationType.READ, parameters, this.invoker);
    assertThat(advised).isInstanceOf(CachingOperationInvoker.class);
    assertThat(advised).hasFieldOrPropertyWithValue("invoker", this.invoker);
    assertThat(advised).hasFieldOrPropertyWithValue("timeToLive", 100L);
}
Also used : OperationInvoker(org.springframework.boot.actuate.endpoint.invoke.OperationInvoker)

Example 8 with OperationInvoker

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

the class CachingOperationInvokerAdvisorTests method applyWhenHasAtLeaseOneMandatoryParameterShouldNotAddAdvise.

@Test
void applyWhenHasAtLeaseOneMandatoryParameterShouldNotAddAdvise() {
    OperationParameters parameters = getParameters("getWithParameters", String.class, String.class);
    OperationInvoker advised = this.advisor.apply(EndpointId.of("foo"), OperationType.READ, parameters, this.invoker);
    assertThat(advised).isSameAs(this.invoker);
}
Also used : OperationParameters(org.springframework.boot.actuate.endpoint.invoke.OperationParameters) OperationInvoker(org.springframework.boot.actuate.endpoint.invoke.OperationInvoker) Test(org.junit.jupiter.api.Test)

Example 9 with OperationInvoker

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

the class CachingOperationInvokerAdvisorTests method applyWithMandatoryCachedAndNonCachedShouldAddAdvise.

@Test
void applyWithMandatoryCachedAndNonCachedShouldAddAdvise() {
    OperationParameters parameters = getParameters("getWithServerNamespaceAndOtherMandatory", WebServerNamespace.class, String.class);
    OperationInvoker advised = this.advisor.apply(EndpointId.of("foo"), OperationType.READ, parameters, this.invoker);
    assertThat(advised).isSameAs(this.invoker);
}
Also used : OperationParameters(org.springframework.boot.actuate.endpoint.invoke.OperationParameters) OperationInvoker(org.springframework.boot.actuate.endpoint.invoke.OperationInvoker) Test(org.junit.jupiter.api.Test)

Example 10 with OperationInvoker

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

the class CachingOperationInvokerTests method targetAlwaysInvokedWithParameters.

@Test
void targetAlwaysInvokedWithParameters() {
    OperationInvoker target = mock(OperationInvoker.class);
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("test", "value");
    parameters.put("something", null);
    InvocationContext context = new InvocationContext(mock(SecurityContext.class), parameters);
    given(target.invoke(context)).willReturn(new Object());
    CachingOperationInvoker invoker = new CachingOperationInvoker(target, CACHE_TTL);
    invoker.invoke(context);
    invoker.invoke(context);
    invoker.invoke(context);
    then(target).should(times(3)).invoke(context);
}
Also used : OperationInvoker(org.springframework.boot.actuate.endpoint.invoke.OperationInvoker) HashMap(java.util.HashMap) SecurityContext(org.springframework.boot.actuate.endpoint.SecurityContext) InvocationContext(org.springframework.boot.actuate.endpoint.InvocationContext) Test(org.junit.jupiter.api.Test)

Aggregations

OperationInvoker (org.springframework.boot.actuate.endpoint.invoke.OperationInvoker)14 Test (org.junit.jupiter.api.Test)11 InvocationContext (org.springframework.boot.actuate.endpoint.InvocationContext)7 SecurityContext (org.springframework.boot.actuate.endpoint.SecurityContext)7 OperationParameters (org.springframework.boot.actuate.endpoint.invoke.OperationParameters)5 HashMap (java.util.HashMap)4 Principal (java.security.Principal)2 ReflectiveOperationInvoker (org.springframework.boot.actuate.endpoint.invoke.reflect.ReflectiveOperationInvoker)1