Search in sources :

Example 11 with MockFilterConfig

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);
}
Also used : CayenneRuntime(org.apache.cayenne.configuration.CayenneRuntime) MockServletContext(com.mockrunner.mock.web.MockServletContext) MockFilterConfig(com.mockrunner.mock.web.MockFilterConfig) Test(org.junit.Test)

Example 12 with MockFilterConfig

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());
}
Also used : MockHttpServletRequest(com.mockrunner.mock.web.MockHttpServletRequest) CayenneRuntime(org.apache.cayenne.configuration.CayenneRuntime) MockFilterChain(com.mockrunner.mock.web.MockFilterChain) MockServletContext(com.mockrunner.mock.web.MockServletContext) MockHttpServletResponse(com.mockrunner.mock.web.MockHttpServletResponse) MockFilterConfig(com.mockrunner.mock.web.MockFilterConfig) Test(org.junit.Test)

Example 13 with MockFilterConfig

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());
}
Also used : MockServletConfig(com.mockrunner.mock.web.MockServletConfig) Iterator(java.util.Iterator) MockFilterConfig(com.mockrunner.mock.web.MockFilterConfig) Collection(java.util.Collection) Map(java.util.Map) Module(org.apache.cayenne.di.Module) Test(org.junit.Test) Assert(org.junit.Assert) Module(org.apache.cayenne.di.Module) MockFilterConfig(com.mockrunner.mock.web.MockFilterConfig) Test(org.junit.Test)

Example 14 with MockFilterConfig

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);
}
Also used : MockServletConfig(com.mockrunner.mock.web.MockServletConfig) Iterator(java.util.Iterator) MockFilterConfig(com.mockrunner.mock.web.MockFilterConfig) Collection(java.util.Collection) Map(java.util.Map) Module(org.apache.cayenne.di.Module) Test(org.junit.Test) Assert(org.junit.Assert) Module(org.apache.cayenne.di.Module) MockFilterConfig(com.mockrunner.mock.web.MockFilterConfig) Test(org.junit.Test)

Example 15 with MockFilterConfig

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());
}
Also used : MockFilterConfig(com.mockrunner.mock.web.MockFilterConfig) Test(org.junit.Test)

Aggregations

MockFilterConfig (com.mockrunner.mock.web.MockFilterConfig)15 Test (org.junit.Test)13 MockServletContext (com.mockrunner.mock.web.MockServletContext)7 CayenneRuntime (org.apache.cayenne.configuration.CayenneRuntime)7 Module (org.apache.cayenne.di.Module)4 MockServletConfig (com.mockrunner.mock.web.MockServletConfig)2 WebMockObjectFactory (com.mockrunner.mock.web.WebMockObjectFactory)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 ServerModule (org.apache.cayenne.configuration.server.ServerModule)2 Assert (org.junit.Assert)2 Before (org.junit.Before)2 MockFilterChain (com.mockrunner.mock.web.MockFilterChain)1 MockHttpServletRequest (com.mockrunner.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (com.mockrunner.mock.web.MockHttpServletResponse)1