use of org.apache.catalina.deploy.ServletDef in project tomcat70 by apache.
the class TestContextConfigAnnotation method testOverwriteAnnotation.
@Test
public void testOverwriteAnnotation() throws Exception {
WebXml webxml = new WebXml();
ServletDef servletDef = new ServletDef();
servletDef.setServletName("param");
servletDef.setServletClass("org.apache.catalina.startup.ParamServlet");
servletDef.addInitParameter("foo", "tomcat");
servletDef.setDescription("Description");
servletDef.setDisplayName("DisplayName");
servletDef.setLargeIcon("LargeIcon");
servletDef.setSmallIcon("SmallIcon");
servletDef.setAsyncSupported("true");
servletDef.setLoadOnStartup("1");
webxml.addServlet(servletDef);
webxml.addServletMapping("/param", "param");
ContextConfig config = new ContextConfig();
File pFile = paramClassResource("org/apache/catalina/startup/ParamServlet");
Assert.assertTrue(pFile.exists());
config.processAnnotationsFile(pFile, webxml, false);
Assert.assertEquals(servletDef, webxml.getServlets().get("param"));
Assert.assertEquals("tomcat", servletDef.getParameterMap().get("foo"));
Assert.assertEquals("param", webxml.getServletMappings().get("/param"));
// annotation mapping not added s. Servlet Spec 3.0 (Nov 2009)
// 8.2.3.3.iv page 81
Assert.assertNull(webxml.getServletMappings().get("/annotation/overwrite"));
Assert.assertEquals("Description", servletDef.getDescription());
Assert.assertEquals("DisplayName", servletDef.getDisplayName());
Assert.assertEquals("LargeIcon", servletDef.getLargeIcon());
Assert.assertEquals("SmallIcon", servletDef.getSmallIcon());
Assert.assertEquals(Boolean.TRUE, servletDef.getAsyncSupported());
Assert.assertEquals(Integer.valueOf(1), servletDef.getLoadOnStartup());
Assert.assertNull(servletDef.getEnabled());
Assert.assertNull(servletDef.getJspFile());
}
use of org.apache.catalina.deploy.ServletDef in project tomcat70 by apache.
the class TestContextConfigAnnotation method testAnnotation.
@Test
public void testAnnotation() throws Exception {
WebXml webxml = new WebXml();
ContextConfig config = new ContextConfig();
File pFile = paramClassResource("org/apache/catalina/startup/ParamServlet");
Assert.assertTrue(pFile.exists());
config.processAnnotationsFile(pFile, webxml, false);
ServletDef servletDef = webxml.getServlets().get("param");
Assert.assertNotNull(servletDef);
Assert.assertEquals("Hello", servletDef.getParameterMap().get("foo"));
Assert.assertEquals("World!", servletDef.getParameterMap().get("bar"));
Assert.assertEquals("param", webxml.getServletMappings().get("/annotation/overwrite"));
Assert.assertEquals("param", servletDef.getDescription());
Assert.assertEquals("param", servletDef.getDisplayName());
Assert.assertEquals("paramLarge.png", servletDef.getLargeIcon());
Assert.assertEquals("paramSmall.png", servletDef.getSmallIcon());
Assert.assertEquals(Boolean.FALSE, servletDef.getAsyncSupported());
Assert.assertEquals(Integer.valueOf(0), servletDef.getLoadOnStartup());
Assert.assertNull(servletDef.getEnabled());
Assert.assertNull(servletDef.getJspFile());
}
use of org.apache.catalina.deploy.ServletDef in project tomcat70 by apache.
the class TestContextConfigAnnotation method testSetupWebXMLNoMapping.
@Test
public void testSetupWebXMLNoMapping() throws Exception {
WebXml webxml = new WebXml();
ServletDef servletDef = new ServletDef();
servletDef.setServletName("param1");
servletDef.setServletClass("org.apache.catalina.startup.NoMappingParamServlet");
servletDef.addInitParameter("foo", "tomcat");
webxml.addServlet(servletDef);
webxml.addServletMapping("/param", "param1");
ContextConfig config = new ContextConfig();
File pFile = paramClassResource("org/apache/catalina/startup/NoMappingParamServlet");
Assert.assertTrue(pFile.exists());
config.processAnnotationsFile(pFile, webxml, false);
Assert.assertEquals("tomcat", servletDef.getParameterMap().get("foo"));
Assert.assertEquals("World!", servletDef.getParameterMap().get("bar"));
ServletDef servletDef1 = webxml.getServlets().get("param1");
Assert.assertNotNull(servletDef1);
Assert.assertEquals(servletDef, servletDef1);
}
use of org.apache.catalina.deploy.ServletDef in project tomcat70 by apache.
the class TestContextConfigAnnotation method testDuplicateMapping.
@Test
public void testDuplicateMapping() throws Exception {
WebXml webxml = new WebXml();
ContextConfig config = new ContextConfig();
File pFile = paramClassResource("org/apache/catalina/startup/DuplicateMappingParamServlet");
Assert.assertTrue(pFile.exists());
try {
config.processAnnotationsFile(pFile, webxml, false);
Assert.fail();
} catch (IllegalArgumentException ex) {
// ignore
}
ServletDef servletDef = webxml.getServlets().get("param");
Assert.assertNull(servletDef);
}
use of org.apache.catalina.deploy.ServletDef in project tomcat70 by apache.
the class TestContextConfigAnnotation method testNoMapping.
@Test
public void testNoMapping() throws Exception {
WebXml webxml = new WebXml();
ContextConfig config = new ContextConfig();
File pFile = paramClassResource("org/apache/catalina/startup/NoMappingParamServlet");
Assert.assertTrue(pFile.exists());
config.processAnnotationsFile(pFile, webxml, false);
ServletDef servletDef = webxml.getServlets().get("param1");
Assert.assertNull(servletDef);
webxml.addServletMapping("/param", "param1");
config.processAnnotationsFile(pFile, webxml, false);
servletDef = webxml.getServlets().get("param1");
Assert.assertNull(servletDef);
}
Aggregations