use of jp.ossc.nimbus.service.aop.invoker.MethodReflectionCallInvokerService in project nimbus by nimbus-org.
the class ReturnInterceptorService method startService.
public void startService() throws Exception {
if (returnConditions != null) {
returnConditions.clear();
}
if (returnValues != null && returnValues.size() != 0) {
if (returnConditions == null) {
returnConditions = new ArrayList();
}
final Iterator entries = returnValues.entrySet().iterator();
while (entries.hasNext()) {
final Map.Entry entry = (Map.Entry) entries.next();
final String condition = (String) entry.getKey();
final Object value = entry.getValue();
returnConditions.add(new Condition(condition, value));
}
}
if (returnServiceNames != null && returnServiceNames.size() != 0) {
if (returnConditions == null) {
returnConditions = new ArrayList();
}
final Iterator entries = returnServiceNames.entrySet().iterator();
while (entries.hasNext()) {
final Map.Entry entry = (Map.Entry) entries.next();
final String condition = (String) entry.getKey();
final ServiceName name = (ServiceName) entry.getValue();
returnConditions.add(new Condition(condition, name));
}
}
if (returnInterfaceClass != null && interceptorChainListServiceName != null) {
final MethodReflectionCallInvokerService invoker = new MethodReflectionCallInvokerService();
invoker.create();
invoker.start();
invocationHandler = new ProxyInvocationHandler(interceptorChainListServiceName, invoker);
proxy = Proxy.newProxyInstance(NimbusClassLoader.getInstance(), new Class[] { returnInterfaceClass }, invocationHandler);
}
}
use of jp.ossc.nimbus.service.aop.invoker.MethodReflectionCallInvokerService in project nimbus by nimbus-org.
the class MockInterceptorServiceTest method test1.
public void test1() throws Throwable {
ServiceManagerFactory.registerManager("Test");
MockInterceptorService interceptor = new MockInterceptorService();
ServiceManagerFactory.registerService("Test", "MockInterceptor", interceptor);
final Method targetMethod = String.class.getMethod("toString", (Class[]) null);
MockFactory mockFactory = new MockFactory() {
public Object createMock(InvocationContext context) {
assertNotNull(context);
assertTrue(context instanceof MethodInvocationContext);
MethodInvocationContext ctx = (MethodInvocationContext) context;
assertEquals("Real", ctx.getTargetObject());
assertEquals(targetMethod, ctx.getTargetMethod());
return "Mock";
}
};
ServiceManagerFactory.registerService("Test", "MockFactory", mockFactory);
try {
ServiceManagerFactory.findManager("Test").createAllService();
interceptor.setMockFactoryServiceName(new ServiceName("Test", "MockFactory"));
ServiceManagerFactory.findManager("Test").startAllService();
final InterceptorChain chain = new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new MethodReflectionCallInvokerService());
assertEquals("Mock", chain.invokeNext(new DefaultMethodInvocationContext("Real", targetMethod, null)));
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.service.aop.invoker.MethodReflectionCallInvokerService in project nimbus by nimbus-org.
the class MockInterceptorServiceTest method test2.
public void test2() throws Throwable {
ServiceManagerFactory.registerManager("Test");
MockInterceptorService interceptor = new MockInterceptorService();
ServiceManagerFactory.registerService("Test", "MockInterceptor", interceptor);
final Method targetMethod = String.class.getMethod("toString", (Class[]) null);
MockFactory mockFactory = new MockFactory() {
public Object createMock(InvocationContext context) {
assertNotNull(context);
assertTrue(context instanceof MethodInvocationContext);
MethodInvocationContext ctx = (MethodInvocationContext) context;
assertEquals("Real", ctx.getTargetObject());
assertEquals(targetMethod, ctx.getTargetMethod());
return "Mock";
}
};
try {
ServiceManagerFactory.findManager("Test").createAllService();
interceptor.setMockFactory(mockFactory);
ServiceManagerFactory.findManager("Test").startAllService();
final InterceptorChain chain = new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new MethodReflectionCallInvokerService());
assertEquals("Mock", chain.invokeNext(new DefaultMethodInvocationContext("Real", targetMethod, null)));
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.service.aop.invoker.MethodReflectionCallInvokerService in project nimbus by nimbus-org.
the class MockInterceptorServiceTest method test4.
public void test4() throws Throwable {
ServiceManagerFactory.registerManager("Test");
MockInterceptorService interceptor = new MockInterceptorService();
ServiceManagerFactory.registerService("Test", "MockInterceptor", interceptor);
final Method targetMethod = String.class.getMethod("toString", (Class[]) null);
try {
ServiceManagerFactory.findManager("Test").createAllService();
interceptor.setMock("Mock");
ServiceManagerFactory.findManager("Test").startAllService();
final InterceptorChain chain = new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new MethodReflectionCallInvokerService());
assertEquals("Mock", chain.invokeNext(new DefaultMethodInvocationContext("Real", targetMethod, null)));
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.service.aop.invoker.MethodReflectionCallInvokerService in project nimbus by nimbus-org.
the class MockInterceptorServiceTest method test3.
public void test3() throws Throwable {
ServiceManagerFactory.registerManager("Test");
MockInterceptorService interceptor = new MockInterceptorService();
ServiceManagerFactory.registerService("Test", "MockInterceptor", interceptor);
final Method targetMethod = String.class.getMethod("toString", (Class[]) null);
ServiceManagerFactory.registerService("Test", "Mock", "Mock");
try {
ServiceManagerFactory.findManager("Test").createAllService();
interceptor.setMockServiceName(new ServiceName("Test", "Mock"));
ServiceManagerFactory.findManager("Test").startAllService();
final InterceptorChain chain = new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new MethodReflectionCallInvokerService());
assertEquals("Mock", chain.invokeNext(new DefaultMethodInvocationContext("Real", targetMethod, null)));
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
Aggregations