use of org.apache.tomcat.util.descriptor.web.WebXml in project tomcat by apache.
the class TestSchemaValidation method testWebapp_2_3.
@Test
public void testWebapp_2_3() throws Exception {
XmlErrorHandler handler = new XmlErrorHandler();
Digester digester = DigesterFactory.newDigester(true, true, new WebRuleSet(false), true);
digester.setErrorHandler(handler);
digester.push(new WebXml());
WebXml desc = (WebXml) digester.parse(new File("test/webapp-2.3/WEB-INF/web.xml"));
Assert.assertEquals("2.3", desc.getVersion());
Assert.assertEquals(XmlIdentifiers.WEB_23_PUBLIC, desc.getPublicId());
Assert.assertEquals(0, handler.getErrors().size());
Assert.assertEquals(0, handler.getWarnings().size());
}
use of org.apache.tomcat.util.descriptor.web.WebXml in project tomcat by apache.
the class TestSchemaValidation method testWebapp_2_4.
@Test
public void testWebapp_2_4() throws Exception {
XmlErrorHandler handler = new XmlErrorHandler();
Digester digester = DigesterFactory.newDigester(true, true, new WebRuleSet(false), true);
digester.setErrorHandler(handler);
digester.push(new WebXml());
WebXml desc = (WebXml) digester.parse(new File("test/webapp-2.4/WEB-INF/web.xml"));
Assert.assertEquals("2.4", desc.getVersion());
Assert.assertEquals(0, handler.getErrors().size());
Assert.assertEquals(0, handler.getWarnings().size());
}
use of org.apache.tomcat.util.descriptor.web.WebXml in project tomcat by apache.
the class TestContextConfigAnnotation method testOverwriteAnnotation.
@Test
public void testOverwriteAnnotation() throws Exception {
WebXml webxml = new WebXml();
Map<String, JavaClassCacheEntry> javaClassCache = new HashMap<>();
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");
assertTrue(pFile.exists());
config.processAnnotationsFile(pFile, webxml, false, javaClassCache);
assertEquals(servletDef, webxml.getServlets().get("param"));
assertEquals("tomcat", servletDef.getParameterMap().get("foo"));
assertEquals("param", webxml.getServletMappings().get("/param"));
// annotation mapping not added s. Servlet Spec 3.0 (Nov 2009)
// 8.2.3.3.iv page 81
assertNull(webxml.getServletMappings().get("/annotation/overwrite"));
assertEquals("Description", servletDef.getDescription());
assertEquals("DisplayName", servletDef.getDisplayName());
assertEquals("LargeIcon", servletDef.getLargeIcon());
assertEquals("SmallIcon", servletDef.getSmallIcon());
assertEquals(Boolean.TRUE, servletDef.getAsyncSupported());
assertEquals(Integer.valueOf(1), servletDef.getLoadOnStartup());
assertNull(servletDef.getEnabled());
assertNull(servletDef.getJspFile());
}
use of org.apache.tomcat.util.descriptor.web.WebXml in project tomcat by apache.
the class TestContextConfigAnnotation method testFilterMapping.
@Test
public void testFilterMapping() throws Exception {
WebXml webxml = new WebXml();
Map<String, JavaClassCacheEntry> javaClassCache = new HashMap<>();
ContextConfig config = new ContextConfig();
File sFile = paramClassResource("org/apache/catalina/startup/ParamServlet");
config.processAnnotationsFile(sFile, webxml, false, javaClassCache);
File fFile = paramClassResource("org/apache/catalina/startup/ParamFilter");
config.processAnnotationsFile(fFile, webxml, false, javaClassCache);
FilterDef fdef = webxml.getFilters().get("paramFilter");
assertNotNull(fdef);
assertEquals("Servlet says: ", fdef.getParameterMap().get("message"));
}
use of org.apache.tomcat.util.descriptor.web.WebXml in project tomcat by apache.
the class TestContextConfigAnnotation method testSetupWebXMLNoMapping.
@Test
public void testSetupWebXMLNoMapping() throws Exception {
WebXml webxml = new WebXml();
Map<String, JavaClassCacheEntry> javaClassCache = new HashMap<>();
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");
assertTrue(pFile.exists());
config.processAnnotationsFile(pFile, webxml, false, javaClassCache);
assertEquals("tomcat", servletDef.getParameterMap().get("foo"));
assertEquals("World!", servletDef.getParameterMap().get("bar"));
ServletDef servletDef1 = webxml.getServlets().get("param1");
assertNotNull(servletDef1);
assertEquals(servletDef, servletDef1);
}
Aggregations