use of org.apache.catalina.deploy.WebXml 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.WebXml 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.WebXml in project tomcat70 by apache.
the class TestContextConfigAnnotation method testDuplicateFilterMapping.
@Test
public void testDuplicateFilterMapping() throws Exception {
WebXml webxml = new WebXml();
ContextConfig config = new ContextConfig();
File pFile = paramClassResource("org/apache/catalina/startup/DuplicateMappingParamFilter");
Assert.assertTrue(pFile.exists());
try {
config.processAnnotationsFile(pFile, webxml, false);
Assert.fail();
} catch (IllegalArgumentException ex) {
// ignore
}
FilterDef filterDef = webxml.getFilters().get("paramD");
Assert.assertNull(filterDef);
}
use of org.apache.catalina.deploy.WebXml 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.WebXml in project tomcat70 by apache.
the class TestContextConfigAnnotation method testOverwriteFilterMapping.
@Test
public void testOverwriteFilterMapping() throws Exception {
WebXml webxml = new WebXml();
FilterDef filterDef = new FilterDef();
filterDef.setFilterName("paramFilter");
filterDef.setFilterClass("org.apache.catalina.startup.ParamFilter");
filterDef.addInitParameter("message", "tomcat");
filterDef.setDescription("Description");
filterDef.setDisplayName("DisplayName");
filterDef.setLargeIcon("LargeIcon");
filterDef.setSmallIcon("SmallIcon");
filterDef.setAsyncSupported("true");
webxml.addFilter(filterDef);
FilterMap filterMap = new FilterMap();
filterMap.addURLPattern("/param1");
filterMap.setFilterName("paramFilter");
webxml.addFilterMapping(filterMap);
ContextConfig config = new ContextConfig();
File sFile = paramClassResource("org/apache/catalina/startup/ParamServlet");
config.processAnnotationsFile(sFile, webxml, false);
File fFile = paramClassResource("org/apache/catalina/startup/ParamFilter");
config.processAnnotationsFile(fFile, webxml, false);
FilterDef fdef = webxml.getFilters().get("paramFilter");
Assert.assertNotNull(fdef);
Assert.assertEquals(filterDef, fdef);
Assert.assertEquals("tomcat", fdef.getParameterMap().get("message"));
Set<FilterMap> filterMappings = webxml.getFilterMappings();
Assert.assertTrue(filterMappings.contains(filterMap));
// annotation mapping not added s. Servlet Spec 3.0 (Nov 2009)
// 8.2.3.3.vi page 81
String[] urlPatterns = filterMap.getURLPatterns();
Assert.assertNotNull(urlPatterns);
Assert.assertEquals(1, urlPatterns.length);
Assert.assertEquals("/param1", urlPatterns[0]);
// check simple Parameter
Assert.assertEquals("Description", fdef.getDescription());
Assert.assertEquals("DisplayName", fdef.getDisplayName());
Assert.assertEquals("LargeIcon", fdef.getLargeIcon());
Assert.assertEquals("SmallIcon", fdef.getSmallIcon());
// FIXME: Strange why servletDef is Boolean and FilterDef is String?
Assert.assertEquals("true", fdef.getAsyncSupported());
String[] dis = filterMap.getDispatcherNames();
Assert.assertEquals(2, dis.length);
Assert.assertEquals(DispatcherType.ERROR.toString(), dis[0]);
Assert.assertEquals(DispatcherType.ASYNC.toString(), dis[1]);
}
Aggregations