use of org.apache.cayenne.rop.ROPServlet 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);
}
use of org.apache.cayenne.rop.ROPServlet 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(7, 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);
}
use of org.apache.cayenne.rop.ROPServlet 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);
}
use of org.apache.cayenne.rop.ROPServlet 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(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 ROPServerModule);
}
use of org.apache.cayenne.rop.ROPServlet in project cayenne by apache.
the class ROPServletTest method testInitHessianService.
@Test
public void testInitHessianService() throws Exception {
MockServletConfig config = new MockServletConfig();
config.setServletName("abc");
MockServletContext context = new MockServletContext();
config.setServletContext(context);
config.setInitParameter("extra-modules", ROPHessianServlet_ConfigModule.class.getName());
ROPServlet servlet = new ROPServlet();
servlet.init(config);
runtime = WebUtil.getCayenneRuntime(context);
Collection<Module> modules = runtime.getModules();
assertEquals(6, modules.size());
Object[] marray = modules.toArray();
assertTrue(marray[3] instanceof ROPHessianServlet_ConfigModule);
// TODO: mock servlet request to check that the right service instance
// is invoked
}
Aggregations