use of jp.ossc.nimbus.service.aop.MockFactory 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.MockFactory 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");
}
}
Aggregations