Search in sources :

Example 1 with ServerModule

use of org.apache.cayenne.configuration.server.ServerModule 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 2 with ServerModule

use of org.apache.cayenne.configuration.server.ServerModule 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(Arrays.asList("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 3 with ServerModule

use of org.apache.cayenne.configuration.server.ServerModule 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)

Example 4 with ServerModule

use of org.apache.cayenne.configuration.server.ServerModule in project cayenne by apache.

the class Main method appendModules.

protected Collection<Module> appendModules(Collection<Module> modules) {
    // TODO: this is dirty... ServerModule is out of place inside the Modeler...
    // If we need ServerRuntime for certain operations, those should start their own stack...
    modules.add(new ServerModule());
    modules.add(new ProjectModule());
    modules.add(new DbSyncModule());
    modules.add(new CayenneModelerModule());
    return modules;
}
Also used : ProjectModule(org.apache.cayenne.project.ProjectModule) CayenneModelerModule(org.apache.cayenne.modeler.init.CayenneModelerModule) DbSyncModule(org.apache.cayenne.dbsync.DbSyncModule) ServerModule(org.apache.cayenne.configuration.server.ServerModule)

Example 5 with ServerModule

use of org.apache.cayenne.configuration.server.ServerModule in project cayenne by apache.

the class CAY_743Test method testLoad2MapsWithCrossMapInheritance.

@Test
public void testLoad2MapsWithCrossMapInheritance() throws Exception {
    Injector injector = DIBootstrap.createInjector(new ServerModule() {

        @Override
        public void configure(Binder binder) {
            super.configure(binder);
            ServerModule.contributeProjectLocations(binder).add("cay743/cayenne-domain.xml");
        }
    });
    try {
        DataDomain domain = injector.getInstance(DataDomain.class);
        assertEquals(2, domain.getDataMaps().size());
        DataMap m1 = domain.getDataMap("map1");
        DataMap m2 = domain.getDataMap("map2");
        ObjEntity oe11 = m1.getObjEntity("Entity11");
        ObjEntity oe12 = m1.getObjEntity("Entity12");
        ObjEntity oe21 = m2.getObjEntity("Entity21");
        ObjEntity oe22 = m2.getObjEntity("Entity22");
        // this causes StackOverflow per CAY-743
        ObjEntity oe21Super = oe21.getSuperEntity();
        ObjEntity oe12Super = oe12.getSuperEntity();
        assertSame(oe12Super, oe22);
        assertSame(oe21Super, oe11);
    } finally {
        injector.shutdown();
    }
}
Also used : Binder(org.apache.cayenne.di.Binder) ObjEntity(org.apache.cayenne.map.ObjEntity) DataDomain(org.apache.cayenne.access.DataDomain) Injector(org.apache.cayenne.di.Injector) ServerModule(org.apache.cayenne.configuration.server.ServerModule) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Aggregations

ServerModule (org.apache.cayenne.configuration.server.ServerModule)6 Test (org.junit.Test)5 MockServletContext (com.mockrunner.mock.web.MockServletContext)4 Module (org.apache.cayenne.di.Module)4 MockFilterConfig (com.mockrunner.mock.web.MockFilterConfig)2 MockServletConfig (com.mockrunner.mock.web.MockServletConfig)2 CayenneRuntime (org.apache.cayenne.configuration.CayenneRuntime)2 WebModule (org.apache.cayenne.configuration.web.WebModule)2 ROPServlet (org.apache.cayenne.rop.ROPServlet)2 DataDomain (org.apache.cayenne.access.DataDomain)1 RequestHandler (org.apache.cayenne.configuration.web.RequestHandler)1 DbSyncModule (org.apache.cayenne.dbsync.DbSyncModule)1 Binder (org.apache.cayenne.di.Binder)1 Injector (org.apache.cayenne.di.Injector)1 DataMap (org.apache.cayenne.map.DataMap)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 CayenneModelerModule (org.apache.cayenne.modeler.init.CayenneModelerModule)1 ProjectModule (org.apache.cayenne.project.ProjectModule)1