Search in sources :

Example 1 with CayenneRuntime

use of org.apache.cayenne.configuration.CayenneRuntime in project cayenne by apache.

the class ROPServlet method destroy.

@Override
public void destroy() {
    super.destroy();
    CayenneRuntime runtime = WebUtil.getCayenneRuntime(servletContext);
    if (runtime != null) {
        runtime.shutdown();
    }
}
Also used : CayenneRuntime(org.apache.cayenne.configuration.CayenneRuntime)

Example 2 with CayenneRuntime

use of org.apache.cayenne.configuration.CayenneRuntime 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 3 with CayenneRuntime

use of org.apache.cayenne.configuration.CayenneRuntime 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 4 with CayenneRuntime

use of org.apache.cayenne.configuration.CayenneRuntime 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 5 with CayenneRuntime

use of org.apache.cayenne.configuration.CayenneRuntime in project cayenne by apache.

the class WebUtilTest method testGetCayenneRuntime.

@Test
public void testGetCayenneRuntime() {
    MockServletContext context = new MockServletContext();
    assertNull(WebUtil.getCayenneRuntime(context));
    CayenneRuntime runtime = mock(CayenneRuntime.class);
    WebUtil.setCayenneRuntime(context, runtime);
    assertSame(runtime, WebUtil.getCayenneRuntime(context));
    CayenneRuntime runtime1 = mock(CayenneRuntime.class);
    WebUtil.setCayenneRuntime(context, runtime1);
    assertSame(runtime1, WebUtil.getCayenneRuntime(context));
    WebUtil.setCayenneRuntime(context, null);
    assertNull(WebUtil.getCayenneRuntime(context));
}
Also used : CayenneRuntime(org.apache.cayenne.configuration.CayenneRuntime) MockServletContext(com.mockrunner.mock.web.MockServletContext) Test(org.junit.Test)

Aggregations

CayenneRuntime (org.apache.cayenne.configuration.CayenneRuntime)10 MockServletContext (com.mockrunner.mock.web.MockServletContext)8 Test (org.junit.Test)8 MockFilterConfig (com.mockrunner.mock.web.MockFilterConfig)7 ServerModule (org.apache.cayenne.configuration.server.ServerModule)2 Module (org.apache.cayenne.di.Module)2 MockFilterChain (com.mockrunner.mock.web.MockFilterChain)1 MockHttpServletRequest (com.mockrunner.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (com.mockrunner.mock.web.MockHttpServletResponse)1