use of org.aopalliance.intercept.MethodInvocation in project spring-framework by spring-projects.
the class ApplicationContextEventTests method testEventPublicationInterceptor.
@Test
public void testEventPublicationInterceptor() throws Throwable {
MethodInvocation invocation = mock(MethodInvocation.class);
ApplicationContext ctx = mock(ApplicationContext.class);
EventPublicationInterceptor interceptor = new EventPublicationInterceptor();
interceptor.setApplicationEventClass(MyEvent.class);
interceptor.setApplicationEventPublisher(ctx);
interceptor.afterPropertiesSet();
given(invocation.proceed()).willReturn(new Object());
given(invocation.getThis()).willReturn(new Object());
interceptor.invoke(invocation);
verify(ctx).publishEvent(isA(MyEvent.class));
}
use of org.aopalliance.intercept.MethodInvocation in project spring-framework by spring-projects.
the class RmiSupportTests method remoteInvocation.
@Test
public void remoteInvocation() throws NoSuchMethodException {
// let's see if the remote invocation object works
final RemoteBean rb = new RemoteBean();
final Method setNameMethod = rb.getClass().getDeclaredMethod("setName", String.class);
MethodInvocation mi = new MethodInvocation() {
@Override
public Method getMethod() {
return setNameMethod;
}
@Override
public Object[] getArguments() {
return new Object[] { "bla" };
}
@Override
public Object proceed() throws Throwable {
throw new UnsupportedOperationException();
}
@Override
public Object getThis() {
return rb;
}
@Override
public AccessibleObject getStaticPart() {
return setNameMethod;
}
};
RemoteInvocation inv = new RemoteInvocation(mi);
assertEquals("setName", inv.getMethodName());
assertEquals("bla", inv.getArguments()[0]);
assertEquals(String.class, inv.getParameterTypes()[0]);
// this is a bit BS, but we need to test it
inv = new RemoteInvocation();
inv.setArguments(new Object[] { "bla" });
assertEquals("bla", inv.getArguments()[0]);
inv.setMethodName("setName");
assertEquals("setName", inv.getMethodName());
inv.setParameterTypes(new Class<?>[] { String.class });
assertEquals(String.class, inv.getParameterTypes()[0]);
inv = new RemoteInvocation("setName", new Class<?>[] { String.class }, new Object[] { "bla" });
assertEquals("bla", inv.getArguments()[0]);
assertEquals("setName", inv.getMethodName());
assertEquals(String.class, inv.getParameterTypes()[0]);
}
use of org.aopalliance.intercept.MethodInvocation in project dubbo by alibaba.
the class RmiProtocol method doRefer.
@SuppressWarnings("unchecked")
protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException {
final RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
// RMI needs extra parameter since it uses customized remote invocation object
if (url.getParameter(Constants.DUBBO_VERSION_KEY, Version.getVersion()).equals(Version.getVersion())) {
// Check dubbo version on provider, this feature only support
rmiProxyFactoryBean.setRemoteInvocationFactory(new RemoteInvocationFactory() {
public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) {
return new RmiRemoteInvocation(methodInvocation);
}
});
}
rmiProxyFactoryBean.setServiceUrl(url.toIdentityString());
rmiProxyFactoryBean.setServiceInterface(serviceType);
rmiProxyFactoryBean.setCacheStub(true);
rmiProxyFactoryBean.setLookupStubOnStartup(true);
rmiProxyFactoryBean.setRefreshStubOnConnectFailure(true);
rmiProxyFactoryBean.afterPropertiesSet();
return (T) rmiProxyFactoryBean.getObject();
}
use of org.aopalliance.intercept.MethodInvocation in project leopard by tanhaichao.
the class TopnbInterceptorTest method invoke.
// @Test
// public void getContext() {
// Assert.assertNotNull(TopnbInterceptor.getContext("applicationContext.xml"));
// Assert.assertNotNull(TopnbInterceptor.getContext("applicationContext.xml", false));
// Assert.assertNotNull(TopnbInterceptor.getContext("applicationContext.xml", true));
// }
@Test
public void invoke() throws Throwable {
MethodInvocation invocation = new MethodInvocation() {
@Override
public Object[] getArguments() {
return null;
}
@Override
public AccessibleObject getStaticPart() {
return null;
}
@Override
public Object getThis() {
return TopnbInterceptorTest.this;
}
@Override
public Object proceed() throws Throwable {
return "ok";
}
@Override
public Method getMethod() {
try {
return TopnbInterceptorTest.class.getMethod("invoke");
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
};
Object result = new MethodTimeInterceptor().invoke(invocation);
Assert.assertEquals("ok", result);
}
use of org.aopalliance.intercept.MethodInvocation in project guice by google.
the class BindingTest method testToConstructorAndMethodInterceptors.
/*if[AOP]*/
public void testToConstructorAndMethodInterceptors() throws NoSuchMethodException {
final Constructor<D> constructor = D.class.getConstructor(Stage.class);
final AtomicInteger count = new AtomicInteger();
final MethodInterceptor countingInterceptor = new MethodInterceptor() {
@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
count.incrementAndGet();
return methodInvocation.proceed();
}
};
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(Object.class).toConstructor(constructor);
bindInterceptor(Matchers.any(), Matchers.any(), countingInterceptor);
}
});
D d = (D) injector.getInstance(Object.class);
d.hashCode();
d.hashCode();
assertEquals(2, count.get());
}
Aggregations