use of org.aopalliance.intercept.MethodInvocation in project jetcache by alibaba.
the class JetCacheInterceptorTest method test1.
@Test
public void test1() throws Throwable {
final Method m = I1.class.getMethod("foo");
final C1 c = new C1();
pc.matches(m, C1.class);
final MethodInvocation mi = mock(MethodInvocation.class);
when(mi.getMethod()).thenReturn(m);
when(mi.getThis()).thenReturn(c);
when(mi.getArguments()).thenReturn(null);
when(mi.proceed()).thenReturn(100);
interceptor.invoke(mi);
interceptor.invoke(mi);
verify(mi, times(1)).proceed();
globalCacheConfig.setEnableMethodCache(false);
interceptor.invoke(mi);
verify(mi, times(2)).proceed();
}
use of org.aopalliance.intercept.MethodInvocation in project jetcache by alibaba.
the class JetCacheInterceptorTest method test2.
@Test
public void test2() throws Throwable {
final Method m = I2.class.getMethod("foo");
final C2 c = new C2();
pc.matches(m, C2.class);
final MethodInvocation mi = mock(MethodInvocation.class);
when(mi.getMethod()).thenReturn(m);
when(mi.getThis()).thenReturn(c);
when(mi.getArguments()).thenReturn(null);
when(mi.proceed()).thenReturn(100);
interceptor.invoke(mi);
interceptor.invoke(mi);
CacheContext.enableCache(() -> {
try {
interceptor.invoke(mi);
interceptor.invoke(mi);
return null;
} catch (Throwable e) {
fail(e);
return null;
}
});
verify(mi, times(3)).proceed();
}
use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.
the class MethodExpressionVoterTests method matchingArgAgainstAuthenticationNameIsSuccessful.
@Test
public void matchingArgAgainstAuthenticationNameIsSuccessful() throws Exception {
MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingAString(), "joe");
assertThat(this.am.vote(this.joe, mi, createAttributes(new PreInvocationExpressionAttribute(null, null, "(#argument == principal) and (principal == 'joe')")))).isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
}
use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.
the class MethodExpressionVoterTests method accessIsGrantedIfNoPreAuthorizeAttributeIsUsed.
@Test
public void accessIsGrantedIfNoPreAuthorizeAttributeIsUsed() throws Exception {
Collection arg = createCollectionArg("joe", "bob", "sam");
MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingACollection(), arg);
assertThat(this.am.vote(this.joe, mi, createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'jim')", "collection", null)))).isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
// All objects should have been removed, because the expression is always false
assertThat(arg).isEmpty();
}
use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.
the class MethodExpressionVoterTests method nullNamedFilterTargetIsRejected.
@Test
public void nullNamedFilterTargetIsRejected() throws Exception {
MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingACollection(), new Object[] { null });
assertThatIllegalArgumentException().isThrownBy(() -> this.am.vote(this.joe, mi, createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'joe')", "collection", null))));
}
Aggregations