Search in sources :

Example 81 with MethodInvocation

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 = context.mock(MethodInvocation.class);
    context.checking(new Expectations() {

        {
            try {
                allowing(mi).getMethod();
                will(Expectations.returnValue(m));
                allowing(mi).getThis();
                will(Expectations.returnValue(c));
                allowing(mi).getArguments();
                will(Expectations.returnValue(null));
                oneOf(mi).proceed();
                will(Expectations.returnValue(new Integer(100)));
            } catch (Throwable e) {
                Assert.fail();
            }
        }
    });
    interceptor.invoke(mi);
    interceptor.invoke(mi);
}
Also used : Expectations(org.jmock.Expectations) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Method(java.lang.reflect.Method)

Example 82 with MethodInvocation

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 = context.mock(MethodInvocation.class);
    context.checking(new Expectations() {

        {
            try {
                allowing(mi).getMethod();
                will(Expectations.returnValue(m));
                allowing(mi).getThis();
                will(Expectations.returnValue(c));
                allowing(mi).getArguments();
                will(Expectations.returnValue(null));
                oneOf(mi).proceed();
                will(Expectations.returnValue(new Integer(100)));
                oneOf(mi).proceed();
                will(Expectations.returnValue(new Integer(100)));
                oneOf(mi).proceed();
                will(Expectations.returnValue(new Integer(100)));
            } catch (Throwable e) {
                Assert.fail();
            }
        }
    });
    interceptor.invoke(mi);
    interceptor.invoke(mi);
    CacheContext.enableCache(() -> {
        try {
            interceptor.invoke(mi);
            interceptor.invoke(mi);
            return null;
        } catch (Throwable e) {
            Assert.fail();
            return null;
        }
    });
}
Also used : Expectations(org.jmock.Expectations) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Method(java.lang.reflect.Method)

Aggregations

MethodInvocation (org.aopalliance.intercept.MethodInvocation)82 Test (org.junit.Test)58 SimpleMethodInvocation (org.springframework.security.util.SimpleMethodInvocation)22 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)15 ITestBean (org.springframework.tests.sample.beans.ITestBean)13 Method (java.lang.reflect.Method)11 Log (org.apache.commons.logging.Log)9 EvaluationContext (org.springframework.expression.EvaluationContext)9 Expression (org.springframework.expression.Expression)9 PreInvocationExpressionAttribute (org.springframework.security.access.expression.method.PreInvocationExpressionAttribute)9 Authentication (org.springframework.security.core.Authentication)9 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)9 TestBean (org.springframework.tests.sample.beans.TestBean)9 IOException (java.io.IOException)8 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)7 FileNotFoundException (java.io.FileNotFoundException)6 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)5 ConnectException (java.rmi.ConnectException)4 RemoteException (java.rmi.RemoteException)4 OtherTargetObject (org.springframework.security.OtherTargetObject)4