use of jp.ossc.nimbus.core.ServiceName in project nimbus by nimbus-org.
the class SelectableServletFilterInterceptorChainListServiceTest method test1.
public void test1() throws Throwable {
ServletRequest request = new DummyHttpServletRequest();
ServletResponse response = new DummyHttpServletResponse();
FilterChain chain = new DummyFilterChain();
ServletFilterInvocationContext context = new ServletFilterInvocationContext(request, response, chain);
final Interceptor interceptor1 = new TestInterceptor();
final Interceptor interceptor2 = new TestInterceptor();
ServiceManagerFactory.registerManager("Test");
ServiceManagerFactory.registerService("Test", "DefaultChainList", new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2 }));
SelectableServletFilterInterceptorChainListService chainList = new SelectableServletFilterInterceptorChainListService();
try {
ServiceManagerFactory.findManager("Test").createAllService();
ServiceManagerFactory.findManager("Test").startAllService();
chainList.setDefaultInterceptorChainListServiceName(new ServiceName("Test", "DefaultChainList"));
chainList.create();
chainList.start();
assertEquals(interceptor1, chainList.getInterceptor(context, 0));
assertEquals(interceptor2, chainList.getInterceptor(context, 1));
} finally {
chainList.stop();
chainList.destroy();
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.core.ServiceName in project nimbus by nimbus-org.
the class SelectableServletFilterInterceptorChainListServiceTest method test2.
public void test2() throws Throwable {
DummyHttpServletRequest request = new DummyHttpServletRequest();
DummyHttpServletResponse response = new DummyHttpServletResponse();
FilterChain chain = new DummyFilterChain();
ServletFilterInvocationContext context = new ServletFilterInvocationContext(request, response, chain);
final Interceptor interceptor1 = new TestInterceptor();
final Interceptor interceptor2 = new TestInterceptor();
final Interceptor interceptor3 = new TestInterceptor();
final Interceptor interceptor4 = new TestInterceptor();
ServiceManagerFactory.registerManager("Test");
ServiceManagerFactory.registerService("Test", "DefaultChainList", new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2 }));
ServiceManagerFactory.registerService("Test", "ChainList1", new DefaultInterceptorChainList(new Interceptor[] { interceptor3, interceptor4 }));
SelectableServletFilterInterceptorChainListService chainList = new SelectableServletFilterInterceptorChainListService();
try {
ServiceManagerFactory.findManager("Test").createAllService();
ServiceManagerFactory.findManager("Test").startAllService();
Properties enabledURLMapping = new Properties();
enabledURLMapping.setProperty("http://nimbus.ossc.jp/hoge/fuga/.*\\.html", "Test#ChainList1");
chainList.setEnabledURLMapping(enabledURLMapping);
chainList.setDefaultInterceptorChainListServiceName(new ServiceName("Test", "DefaultChainList"));
chainList.create();
chainList.start();
request.setScheme("http");
request.setServerName("nimbus.ossc.jp");
request.setRequestURI("/hoge/fuga/a.html");
assertEquals(interceptor3, chainList.getInterceptor(context, 0));
assertEquals(interceptor4, chainList.getInterceptor(context, 1));
request.setRequestURI("/hoge/fuga2/a.html");
assertEquals(interceptor1, chainList.getInterceptor(context, 0));
assertEquals(interceptor2, chainList.getInterceptor(context, 1));
} finally {
chainList.stop();
chainList.destroy();
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.core.ServiceName in project nimbus by nimbus-org.
the class SelectableServletFilterInterceptorChainListServiceTest method test5.
public void test5() throws Throwable {
DummyHttpServletRequest request = new DummyHttpServletRequest();
DummyHttpServletResponse response = new DummyHttpServletResponse();
FilterChain chain = new DummyFilterChain();
ServletFilterInvocationContext context = new ServletFilterInvocationContext(request, response, chain);
final Interceptor interceptor1 = new TestInterceptor();
final Interceptor interceptor2 = new TestInterceptor();
final Interceptor interceptor3 = new TestInterceptor();
final Interceptor interceptor4 = new TestInterceptor();
ServiceManagerFactory.registerManager("Test");
ServiceManagerFactory.registerService("Test", "DefaultChainList", new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2 }));
ServiceManagerFactory.registerService("Test", "ChainList1", new DefaultInterceptorChainList(new Interceptor[] { interceptor3, interceptor4 }));
SelectableServletFilterInterceptorChainListService chainList = new SelectableServletFilterInterceptorChainListService();
try {
ServiceManagerFactory.findManager("Test").createAllService();
ServiceManagerFactory.findManager("Test").startAllService();
Properties disabledURIMapping = new Properties();
disabledURIMapping.setProperty("/hoge/fuga/.*\\.html", "Test#ChainList1");
chainList.setDisabledURIMapping(disabledURIMapping);
chainList.setDefaultInterceptorChainListServiceName(new ServiceName("Test", "DefaultChainList"));
chainList.create();
chainList.start();
request.setRequestURI("/hoge/fuga/a.html");
assertEquals(interceptor1, chainList.getInterceptor(context, 0));
assertEquals(interceptor2, chainList.getInterceptor(context, 1));
request.setRequestURI("/hoge/fuga2/a.html");
assertEquals(interceptor3, chainList.getInterceptor(context, 0));
assertEquals(interceptor4, chainList.getInterceptor(context, 1));
} finally {
chainList.stop();
chainList.destroy();
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.core.ServiceName in project nimbus by nimbus-org.
the class SelectableServletFilterInterceptorChainListServiceTest method test6.
public void test6() throws Throwable {
DummyHttpServletRequest request = new DummyHttpServletRequest();
DummyHttpServletResponse response = new DummyHttpServletResponse();
FilterChain chain = new DummyFilterChain();
ServletFilterInvocationContext context = new ServletFilterInvocationContext(request, response, chain);
final Interceptor interceptor1 = new TestInterceptor();
final Interceptor interceptor2 = new TestInterceptor();
final Interceptor interceptor3 = new TestInterceptor();
final Interceptor interceptor4 = new TestInterceptor();
ServiceManagerFactory.registerManager("Test");
ServiceManagerFactory.registerService("Test", "DefaultChainList", new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2 }));
ServiceManagerFactory.registerService("Test", "ChainList1", new DefaultInterceptorChainList(new Interceptor[] { interceptor3, interceptor4 }));
SelectableServletFilterInterceptorChainListService chainList = new SelectableServletFilterInterceptorChainListService();
try {
ServiceManagerFactory.findManager("Test").createAllService();
ServiceManagerFactory.findManager("Test").startAllService();
Properties enabledPathMapping = new Properties();
enabledPathMapping.setProperty("/fuga/.*\\.html", "Test#ChainList1");
chainList.create();
chainList.setEnabledPathMapping(enabledPathMapping);
chainList.setDefaultInterceptorChainListServiceName(new ServiceName("Test", "DefaultChainList"));
chainList.start();
request.setPathInfo("/fuga/a.html");
assertEquals(interceptor3, chainList.getInterceptor(context, 0));
assertEquals(interceptor4, chainList.getInterceptor(context, 1));
request.setPathInfo(null);
request.setServletPath("/fuga/a.html");
assertEquals(interceptor3, chainList.getInterceptor(context, 0));
assertEquals(interceptor4, chainList.getInterceptor(context, 1));
request.setServletPath(null);
request.setPathInfo("/fuga2/a.html");
assertEquals(interceptor1, chainList.getInterceptor(context, 0));
assertEquals(interceptor2, chainList.getInterceptor(context, 1));
} finally {
chainList.stop();
chainList.destroy();
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.core.ServiceName 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