use of com.mockrunner.mock.web.MockFilterConfig in project cayenne by apache.
the class CayenneFilterTest method testInitWithFilterName.
@Test
public void testInitWithFilterName() throws Exception {
MockFilterConfig config = new MockFilterConfig();
config.setFilterName("abc");
MockServletContext context = new MockServletContext();
config.setupServletContext(context);
CayenneFilter filter = new CayenneFilter();
assertNull(WebUtil.getCayenneRuntime(context));
filter.init(config);
CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
assertNotNull(runtime);
List<String> locations = runtime.getInjector().getInstance(Key.getListOf(String.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
assertEquals(Collections.singletonList("abc.xml"), locations);
}
use of com.mockrunner.mock.web.MockFilterConfig in project cayenne by apache.
the class CayenneFilterTest method testDoFilter.
@Test
public void testDoFilter() throws Exception {
MockFilterConfig config = new MockFilterConfig();
config.setFilterName("abc");
config.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER, CayenneFilter_DispatchModule.class.getName());
MockServletContext context = new MockServletContext();
config.setupServletContext(context);
CayenneFilter filter = new CayenneFilter();
filter.init(config);
CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
CayenneFilter_DispatchRequestHandler handler = (CayenneFilter_DispatchRequestHandler) runtime.getInjector().getInstance(RequestHandler.class);
assertEquals(0, handler.getStarted());
assertEquals(0, handler.getEnded());
filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
assertEquals(1, handler.getStarted());
assertEquals(1, handler.getEnded());
filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
assertEquals(2, handler.getStarted());
assertEquals(2, handler.getEnded());
}
use of com.mockrunner.mock.web.MockFilterConfig in project cayenne by apache.
the class WebConfigurationTest method testFilterCreateModules_Standard.
@Test
public void testFilterCreateModules_Standard() throws Exception {
MockFilterConfig config = new MockFilterConfig();
WebConfiguration configuration = new WebConfiguration(config);
Module m1 = binder -> {
};
Module m2 = binder -> {
};
Collection<Module> modules = configuration.createModules(m1, m2);
assertEquals(2, modules.size());
Iterator<Module> it = modules.iterator();
assertSame(m1, it.next());
assertSame(m2, it.next());
}
use of com.mockrunner.mock.web.MockFilterConfig in project cayenne by apache.
the class WebConfigurationTest method testFilterCreateModules_Extra.
@Test
public void testFilterCreateModules_Extra() throws Exception {
MockFilterConfig config = new MockFilterConfig();
String exra = String.format("%s, \n%s", MockModule1.class.getName(), MockModule2.class.getName());
config.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER, exra);
WebConfiguration configuration = new WebConfiguration(config);
Module m1 = binder -> {
};
Module m2 = binder -> {
};
Collection<Module> modules = configuration.createModules(m1, m2);
assertEquals(4, modules.size());
Iterator<Module> it = modules.iterator();
assertSame(m1, it.next());
assertSame(m2, it.next());
assertTrue(it.next() instanceof MockModule1);
assertTrue(it.next() instanceof MockModule2);
}
use of com.mockrunner.mock.web.MockFilterConfig in project cayenne by apache.
the class WebConfigurationTest method testFilterConfigurationLocation_Name.
@Test
public void testFilterConfigurationLocation_Name() {
MockFilterConfig config1 = new MockFilterConfig();
config1.setFilterName("cayenne-x");
WebConfiguration configuration1 = new WebConfiguration(config1);
assertEquals("cayenne-x.xml", configuration1.getConfigurationLocation());
MockFilterConfig config2 = new MockFilterConfig();
config2.setFilterName("cayenne-y.xml");
WebConfiguration configuration2 = new WebConfiguration(config2);
assertEquals("cayenne-y.xml", configuration2.getConfigurationLocation());
MockFilterConfig config3 = new MockFilterConfig();
config3.setFilterName("a/b/c/cayenne-z.xml");
WebConfiguration configuration3 = new WebConfiguration(config3);
assertEquals("a/b/c/cayenne-z.xml", configuration3.getConfigurationLocation());
}
Aggregations