Search in sources :

Example 1 with MockFilterConfig

use of com.mockrunner.mock.web.MockFilterConfig in project geode by apache.

the class SessionReplicationJUnitTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    WebMockObjectFactory factory = getWebMockObjectFactory();
    MockFilterConfig config = factory.getMockFilterConfig();
    config.setInitParameter(DistributionConfig.GEMFIRE_PREFIX + "property.mcast-port", "0");
    config.setInitParameter("cache-type", "peer-to-peer");
    factory.getMockServletContext().setContextPath(CONTEXT_PATH);
    factory.getMockRequest().setRequestURL("/test/foo/bar");
    factory.getMockRequest().setContextPath(CONTEXT_PATH);
    createFilter(SessionCachingFilter.class);
    createServlet(CallbackServlet.class);
    setDoChain(true);
}
Also used : WebMockObjectFactory(com.mockrunner.mock.web.WebMockObjectFactory) MockFilterConfig(com.mockrunner.mock.web.MockFilterConfig) Before(org.junit.Before)

Example 2 with MockFilterConfig

use of com.mockrunner.mock.web.MockFilterConfig in project geode by apache.

the class SessionReplicationLocalCacheJUnitTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    WebMockObjectFactory factory = getWebMockObjectFactory();
    MockFilterConfig config = factory.getMockFilterConfig();
    config.setInitParameter(DistributionConfig.GEMFIRE_PREFIX + "property.mcast-port", "0");
    config.setInitParameter("cache-type", "peer-to-peer");
    config.setInitParameter(DistributionConfig.GEMFIRE_PREFIX + "cache.enable_local_cache", "true");
    factory.getMockServletContext().setContextPath(CONTEXT_PATH);
    factory.getMockRequest().setRequestURL("/test/foo/bar");
    factory.getMockRequest().setContextPath(CONTEXT_PATH);
    createFilter(SessionCachingFilter.class);
    createServlet(CallbackServlet.class);
    setDoChain(true);
}
Also used : WebMockObjectFactory(com.mockrunner.mock.web.WebMockObjectFactory) MockFilterConfig(com.mockrunner.mock.web.MockFilterConfig) Before(org.junit.Before)

Example 3 with MockFilterConfig

use of com.mockrunner.mock.web.MockFilterConfig in project cayenne by apache.

the class CayenneFilterTest method testInitWithLocation.

@Test
public void testInitWithLocation() throws Exception {
    MockFilterConfig config = new MockFilterConfig();
    config.setFilterName("abc");
    config.setInitParameter(WebConfiguration.CONFIGURATION_LOCATION_PARAMETER, "xyz");
    MockServletContext context = new MockServletContext();
    config.setupServletContext(context);
    CayenneFilter filter = new CayenneFilter();
    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("xyz"), 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 4 with MockFilterConfig

use of com.mockrunner.mock.web.MockFilterConfig in project cayenne by apache.

the class CayenneFilterTest method testInitWithStandardModules.

@Test
public void testInitWithStandardModules() throws Exception {
    MockFilterConfig config = new MockFilterConfig();
    config.setFilterName("cayenne-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("cayenne-abc.xml"), locations);
    Collection<Module> modules = runtime.getModules();
    assertEquals(3, modules.size());
    Object[] marray = modules.toArray();
    if (marray[0] instanceof ServerModule) {
        assertTrue(marray[1] instanceof WebModule);
    } else {
        assertTrue(marray[0] instanceof WebModule);
    }
    RequestHandler handler = runtime.getInjector().getInstance(RequestHandler.class);
    assertTrue(handler instanceof SessionContextRequestHandler);
}
Also used : CayenneRuntime(org.apache.cayenne.configuration.CayenneRuntime) MockServletContext(com.mockrunner.mock.web.MockServletContext) MockFilterConfig(com.mockrunner.mock.web.MockFilterConfig) ServerModule(org.apache.cayenne.configuration.server.ServerModule) Module(org.apache.cayenne.di.Module) ServerModule(org.apache.cayenne.configuration.server.ServerModule) Test(org.junit.Test)

Example 5 with MockFilterConfig

use of com.mockrunner.mock.web.MockFilterConfig in project cayenne by apache.

the class CayenneFilterTest method testInitWithExtraModules.

@Test
public void testInitWithExtraModules() throws Exception {
    MockFilterConfig config = new MockFilterConfig();
    config.setFilterName("abc");
    config.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER, MockModule1.class.getName() + "," + MockModule2.class.getName());
    MockServletContext context = new MockServletContext();
    config.setupServletContext(context);
    CayenneFilter filter = new CayenneFilter();
    filter.init(config);
    CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
    assertNotNull(runtime);
    Collection<Module> modules = runtime.getModules();
    assertEquals(5, modules.size());
    Object[] marray = modules.toArray();
    if (marray[0] instanceof ServerModule) {
        assertTrue(marray[1] instanceof WebModule);
    } else {
        assertTrue(marray[0] instanceof WebModule);
    }
    assertTrue(marray[2] instanceof MockModule1);
    assertTrue(marray[3] instanceof MockModule2);
    RequestHandler handler = runtime.getInjector().getInstance(RequestHandler.class);
    assertTrue(handler instanceof MockRequestHandler);
}
Also used : CayenneRuntime(org.apache.cayenne.configuration.CayenneRuntime) MockServletContext(com.mockrunner.mock.web.MockServletContext) MockFilterConfig(com.mockrunner.mock.web.MockFilterConfig) ServerModule(org.apache.cayenne.configuration.server.ServerModule) Module(org.apache.cayenne.di.Module) ServerModule(org.apache.cayenne.configuration.server.ServerModule) 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