use of jp.ossc.nimbus.service.aop.DefaultInvocationContext in project nimbus by nimbus-org.
the class ContextExportInterceptorServiceTest method test1.
public void test1() throws Throwable {
ServiceManagerFactory.registerManager("Test");
ServiceManagerFactory.registerService("Test", "Context", new DefaultContextService());
Interceptor interceptor1 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
Context ctx = (Context) ServiceManagerFactory.getServiceObject("Test", "Context");
ctx.put("A", "100");
ctx.put("B", "200");
return chain.invokeNext(context);
}
};
ContextExportInterceptorService interceptor2 = new ContextExportInterceptorService();
ServiceManagerFactory.registerService("Test", "ContextExportInterceptor", interceptor2);
Interceptor interceptor3 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
Map exportedContext = (Map) context.getAttribute(ContextExportInterceptorService.DEFAULT_ATTRIBUTE_NAME);
assertEquals(2, exportedContext.size());
assertEquals("100", exportedContext.get("A"));
assertEquals("200", exportedContext.get("B"));
return chain.invokeNext(context);
}
};
try {
ServiceManagerFactory.findManager("Test").createAllService();
interceptor2.setContextServiceName(new ServiceName("Test", "Context"));
ServiceManagerFactory.findManager("Test").startAllService();
new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2, interceptor3 }), null).invokeNext(new DefaultInvocationContext());
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.service.aop.DefaultInvocationContext in project nimbus by nimbus-org.
the class ContextExportInterceptorServiceTest method test2.
public void test2() throws Throwable {
ServiceManagerFactory.registerManager("Test");
DefaultContextService contextService = new DefaultContextService();
ServiceManagerFactory.registerService("Test", "Context", contextService);
Interceptor interceptor1 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
Context ctx = (Context) ServiceManagerFactory.getServiceObject("Test", "Context");
ctx.put("A", "100");
ctx.put("B", "200");
ctx.put("C", "300");
return chain.invokeNext(context);
}
};
ContextExportInterceptorService interceptor2 = new ContextExportInterceptorService();
ServiceManagerFactory.registerService("Test", "ContextExportInterceptor", interceptor2);
Interceptor interceptor3 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
Map exportedContext = (Map) context.getAttribute("Context");
assertEquals(2, exportedContext.size());
assertEquals("100", exportedContext.get("A"));
assertEquals("200", exportedContext.get("B"));
return chain.invokeNext(context);
}
};
try {
ServiceManagerFactory.findManager("Test").createAllService();
interceptor2.setContext(contextService);
interceptor2.setAttributeName("Context");
interceptor2.setContextKeys(new String[] { "A", "B" });
ServiceManagerFactory.findManager("Test").startAllService();
new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2, interceptor3 }), null).invokeNext(new DefaultInvocationContext());
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.service.aop.DefaultInvocationContext in project nimbus by nimbus-org.
the class NullReturnInterceptorServiceTest method test1.
public void test1() throws Throwable {
ServiceManagerFactory.registerManager("Test");
NullReturnInterceptorService interceptor = new NullReturnInterceptorService();
ServiceManagerFactory.registerService("Test", "NullReturnInterceptor", interceptor);
try {
ServiceManagerFactory.findManager("Test").createAllService();
ServiceManagerFactory.findManager("Test").startAllService();
final InterceptorChain chain = new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new Invoker() {
public Object invoke(InvocationContext context) throws Throwable {
return "test";
}
});
assertNull(chain.invokeNext(new DefaultInvocationContext(null)));
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.service.aop.DefaultInvocationContext in project nimbus by nimbus-org.
the class ContextImportInterceptorServiceTest method test2.
public void test2() throws Throwable {
ServiceManagerFactory.registerManager("Test");
DefaultContextService contextService = new DefaultContextService();
ServiceManagerFactory.registerService("Test", "Context", contextService);
Interceptor interceptor1 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
Map importContext = new HashMap();
importContext.put("A", "100");
importContext.put("B", "200");
context.setAttribute("Context", importContext);
return chain.invokeNext(context);
}
};
ContextImportInterceptorService interceptor2 = new ContextImportInterceptorService();
ServiceManagerFactory.registerService("Test", "ContextImportInterceptor", interceptor2);
Interceptor interceptor3 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
Context ctx = (Context) ServiceManagerFactory.getServiceObject("Test", "Context");
assertEquals(2, ctx.size());
assertEquals("100", ctx.get("A"));
assertEquals("200", ctx.get("B"));
return chain.invokeNext(context);
}
};
try {
ServiceManagerFactory.findManager("Test").createAllService();
interceptor2.setContext(contextService);
interceptor2.setAttributeName("Context");
interceptor2.setContextKeys(new String[] { "A", "B" });
ServiceManagerFactory.findManager("Test").startAllService();
new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2, interceptor3 }), null).invokeNext(new DefaultInvocationContext());
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.service.aop.DefaultInvocationContext in project nimbus by nimbus-org.
the class ContextImportInterceptorServiceTest method test1.
public void test1() throws Throwable {
ServiceManagerFactory.registerManager("Test");
ServiceManagerFactory.registerService("Test", "Context", new DefaultContextService());
Interceptor interceptor1 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
Map importContext = new HashMap();
importContext.put("A", "100");
importContext.put("B", "200");
context.setAttribute(ContextImportInterceptorService.DEFAULT_ATTRIBUTE_NAME, importContext);
return chain.invokeNext(context);
}
};
ContextImportInterceptorService interceptor2 = new ContextImportInterceptorService();
ServiceManagerFactory.registerService("Test", "ContextImportInterceptor", interceptor2);
Interceptor interceptor3 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
Context ctx = (Context) ServiceManagerFactory.getServiceObject("Test", "Context");
assertEquals(2, ctx.size());
assertEquals("100", ctx.get("A"));
assertEquals("200", ctx.get("B"));
return chain.invokeNext(context);
}
};
try {
ServiceManagerFactory.findManager("Test").createAllService();
interceptor2.setContextServiceName(new ServiceName("Test", "Context"));
ServiceManagerFactory.findManager("Test").startAllService();
new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2, interceptor3 }), null).invokeNext(new DefaultInvocationContext());
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
Aggregations