Search in sources :

Example 1 with MockServletConfig

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

the class ROPServletTest method testInitWithServletName.

@Test
public void testInitWithServletName() throws Exception {
    MockServletConfig config = new MockServletConfig();
    config.setServletName("cayenne-org.apache.cayenne.configuration.rop.server.test-config");
    MockServletContext context = new MockServletContext();
    config.setServletContext(context);
    ROPServlet servlet = new ROPServlet();
    assertNull(WebUtil.getCayenneRuntime(context));
    servlet.init(config);
    runtime = WebUtil.getCayenneRuntime(context);
    assertNotNull(runtime);
    List<String> locations = runtime.getInjector().getInstance(Key.getListOf(String.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
    assertEquals(Arrays.asList("cayenne-org.apache.cayenne.configuration.rop.server.test-config.xml"), locations);
}
Also used : MockServletConfig(com.mockrunner.mock.web.MockServletConfig) ROPServlet(org.apache.cayenne.rop.ROPServlet) MockServletContext(com.mockrunner.mock.web.MockServletContext) Test(org.junit.Test)

Example 2 with MockServletConfig

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

the class ROPServletTest method testInitWithExtraModules.

@Test
public void testInitWithExtraModules() throws Exception {
    String name = "cayenne-org.apache.cayenne.configuration.rop.server.test-config";
    MockServletConfig config = new MockServletConfig();
    config.setServletName(name);
    config.setInitParameter("extra-modules", MockModule1.class.getName() + "," + MockModule2.class.getName());
    MockServletContext context = new MockServletContext();
    config.setServletContext(context);
    ROPServlet servlet = new ROPServlet();
    servlet.init(config);
    runtime = WebUtil.getCayenneRuntime(context);
    assertNotNull(runtime);
    Collection<Module> modules = runtime.getModules();
    assertEquals(6, 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 ROPServerModule);
    assertTrue(marray[3] instanceof MockModule1);
    assertTrue(marray[4] instanceof MockModule2);
    RequestHandler handler = runtime.getInjector().getInstance(RequestHandler.class);
    assertTrue(handler instanceof MockRequestHandler);
}
Also used : MockServletConfig(com.mockrunner.mock.web.MockServletConfig) WebModule(org.apache.cayenne.configuration.web.WebModule) ROPServlet(org.apache.cayenne.rop.ROPServlet) MockServletContext(com.mockrunner.mock.web.MockServletContext) ServerModule(org.apache.cayenne.configuration.server.ServerModule) RequestHandler(org.apache.cayenne.configuration.web.RequestHandler) Module(org.apache.cayenne.di.Module) WebModule(org.apache.cayenne.configuration.web.WebModule) ServerModule(org.apache.cayenne.configuration.server.ServerModule) Test(org.junit.Test)

Example 3 with MockServletConfig

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

the class WebConfigurationTest method testServletCreateModules_Extra.

@Test
public void testServletCreateModules_Extra() throws Exception {
    MockServletConfig config = new MockServletConfig();
    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) MockServletConfig(com.mockrunner.mock.web.MockServletConfig) Module(org.apache.cayenne.di.Module) Test(org.junit.Test)

Example 4 with MockServletConfig

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

the class ROPServletTest method testInitWithLocation.

@Test
public void testInitWithLocation() throws Exception {
    String location = "cayenne-org.apache.cayenne.configuration.rop.server.test-config.xml";
    MockServletConfig config = new MockServletConfig();
    config.setServletName("abc");
    config.setInitParameter("configuration-location", location);
    MockServletContext context = new MockServletContext();
    config.setServletContext(context);
    ROPServlet servlet = new ROPServlet();
    servlet.init(config);
    runtime = WebUtil.getCayenneRuntime(context);
    assertNotNull(runtime);
    List<String> locations = runtime.getInjector().getInstance(Key.getListOf(String.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
    assertEquals(Arrays.asList(location), locations);
}
Also used : MockServletConfig(com.mockrunner.mock.web.MockServletConfig) ROPServlet(org.apache.cayenne.rop.ROPServlet) MockServletContext(com.mockrunner.mock.web.MockServletContext) Test(org.junit.Test)

Example 5 with MockServletConfig

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

the class ROPServletTest method testInitWithStandardModules.

@Test
public void testInitWithStandardModules() throws Exception {
    String name = "cayenne-org.apache.cayenne.configuration.rop.server.test-config";
    MockServletConfig config = new MockServletConfig();
    config.setServletName(name);
    MockServletContext context = new MockServletContext();
    config.setServletContext(context);
    ROPServlet servlet = new ROPServlet();
    servlet.init(config);
    runtime = WebUtil.getCayenneRuntime(context);
    assertNotNull(runtime);
    List<String> locations = runtime.getInjector().getInstance(Key.getListOf(String.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
    assertEquals(Arrays.asList(name + ".xml"), locations);
    Collection<Module> modules = runtime.getModules();
    assertEquals(4, 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 ROPServerModule);
}
Also used : MockServletConfig(com.mockrunner.mock.web.MockServletConfig) WebModule(org.apache.cayenne.configuration.web.WebModule) ROPServlet(org.apache.cayenne.rop.ROPServlet) Module(org.apache.cayenne.di.Module) WebModule(org.apache.cayenne.configuration.web.WebModule) ServerModule(org.apache.cayenne.configuration.server.ServerModule) MockServletContext(com.mockrunner.mock.web.MockServletContext) ServerModule(org.apache.cayenne.configuration.server.ServerModule) Test(org.junit.Test)

Aggregations

MockServletConfig (com.mockrunner.mock.web.MockServletConfig)8 Test (org.junit.Test)8 MockServletContext (com.mockrunner.mock.web.MockServletContext)5 ROPServlet (org.apache.cayenne.rop.ROPServlet)5 Module (org.apache.cayenne.di.Module)4 ServerModule (org.apache.cayenne.configuration.server.ServerModule)3 WebModule (org.apache.cayenne.configuration.web.WebModule)3 MockFilterConfig (com.mockrunner.mock.web.MockFilterConfig)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 RequestHandler (org.apache.cayenne.configuration.web.RequestHandler)1 Assert (org.junit.Assert)1