FilterDispatcherTestpublic class FilterDispatcherTest extends org.apache.struts2.StrutsTestCase FilterDispatcher TestCase. |
Methods Summary |
---|
public void | testCharacterEncodingSetBeforeRequestWrappingAndActionService()
MockServletContext servletContext = new MockServletContext();
MockFilterConfig filterConfig = new MockFilterConfig(servletContext);
MockHttpServletRequest req = new MockHttpServletRequest(servletContext);
MockHttpServletResponse res = new MockHttpServletResponse();
MockFilterChain chain = new MockFilterChain();
final InnerDispatcher _dispatcher = new InnerDispatcher(servletContext);
Dispatcher.setInstance(null);
DefaultConfiguration conf = new DefaultConfiguration() {
@Override
public Container getContainer() {
return new ContainerBuilder().create(false);
}
};
ConfigurationManager confManager = new ConfigurationManager();
confManager.setConfiguration(conf);
_dispatcher.setConfigurationManager(confManager);
ObjectFactory.setObjectFactory(new InnerObjectFactory());
_dispatcher.setDefaultEncoding("UTF-16_DUMMY");
FilterDispatcher filter = new FilterDispatcher() {
protected Dispatcher createDispatcher(FilterConfig filterConfig) {
return _dispatcher;
}
};
filter.setActionMapper(new InnerActionMapper());
filter.init(filterConfig);
filter.doFilter(req, res, chain);
assertTrue(_dispatcher.wrappedRequest);
assertTrue(_dispatcher.serviceRequest);
| public void | testIfActionMapperIsNullDontServiceAction()
MockServletContext servletContext = new MockServletContext();
MockFilterConfig filterConfig = new MockFilterConfig(servletContext);
MockHttpServletRequest req = new MockHttpServletRequest(servletContext);
MockHttpServletResponse res = new MockHttpServletResponse();
MockFilterChain chain = new MockFilterChain();
final NoOpDispatcher _dispatcher = new NoOpDispatcher(servletContext);
ConfigurationManager confManager = new ConfigurationManager();
confManager.setConfiguration(new DefaultConfiguration());
_dispatcher.setConfigurationManager(confManager);
Dispatcher.setInstance(_dispatcher);
ObjectFactory.setObjectFactory(new InnerObjectFactory());
FilterDispatcher filter = new FilterDispatcher() {
protected Dispatcher createDispatcher() {
return _dispatcher;
}
};
filter.setActionMapper(null);
filter.init(filterConfig);
filter.doFilter(req, res, chain);
assertFalse(_dispatcher.serviceRequest);
| public void | testObjectFactoryDestroy()
final InnerDestroyableObjectFactory destroyedObjectFactory = new InnerDestroyableObjectFactory();
FilterDispatcher filterDispatcher = new FilterDispatcher() {
@Override
protected Dispatcher createDispatcher(FilterConfig cfg) {
return new Dispatcher(cfg.getServletContext(), new HashMap()) {
Container cont = new ContainerBuilder()
.factory(ObjectFactory.class, new Factory() {
public Object create(Context context) throws Exception { return destroyedObjectFactory; }
})
.create(false);
@Override
public Container getContainer() {
return cont;
}
};
}
};
filterDispatcher.init(new MockFilterConfig((ServletContext) null));
assertFalse(destroyedObjectFactory.destroyed);
filterDispatcher.destroy();
assertTrue(destroyedObjectFactory.destroyed);
| public void | testParsePackages()
FilterDispatcher filterDispatcher = new FilterDispatcher();
String[] result1 = filterDispatcher.parse("foo.bar.package1 foo.bar.package2 foo.bar.package3");
String[] result2 = filterDispatcher.parse("foo.bar.package1\tfoo.bar.package2\tfoo.bar.package3");
String[] result3 = filterDispatcher.parse("foo.bar.package1,foo.bar.package2,foo.bar.package3");
String[] result4 = filterDispatcher.parse("foo.bar.package1 foo.bar.package2 \t foo.bar.package3 , foo.bar.package4");
assertEquals(result1[0], "foo/bar/package1/");
assertEquals(result1[1], "foo/bar/package2/");
assertEquals(result1[2], "foo/bar/package3/");
assertEquals(result2[0], "foo/bar/package1/");
assertEquals(result2[1], "foo/bar/package2/");
assertEquals(result2[2], "foo/bar/package3/");
assertEquals(result3[0], "foo/bar/package1/");
assertEquals(result3[1], "foo/bar/package2/");
assertEquals(result3[2], "foo/bar/package3/");
assertEquals(result4[0], "foo/bar/package1/");
assertEquals(result4[1], "foo/bar/package2/");
assertEquals(result4[2], "foo/bar/package3/");
assertEquals(result4[3], "foo/bar/package4/");
|
|