Search in sources :

Example 16 with WebXml

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());
}
Also used : WebXml(org.apache.catalina.deploy.WebXml) ServletDef(org.apache.catalina.deploy.ServletDef) File(java.io.File) Test(org.junit.Test)

Example 17 with WebXml

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);
}
Also used : WebXml(org.apache.catalina.deploy.WebXml) ServletDef(org.apache.catalina.deploy.ServletDef) File(java.io.File) Test(org.junit.Test)

Example 18 with WebXml

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);
}
Also used : WebXml(org.apache.catalina.deploy.WebXml) FilterDef(org.apache.catalina.deploy.FilterDef) File(java.io.File) Test(org.junit.Test)

Example 19 with WebXml

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);
}
Also used : WebXml(org.apache.catalina.deploy.WebXml) ServletDef(org.apache.catalina.deploy.ServletDef) File(java.io.File) Test(org.junit.Test)

Example 20 with WebXml

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]);
}
Also used : WebXml(org.apache.catalina.deploy.WebXml) FilterDef(org.apache.catalina.deploy.FilterDef) FilterMap(org.apache.catalina.deploy.FilterMap) File(java.io.File) Test(org.junit.Test)

Aggregations

WebXml (org.apache.catalina.deploy.WebXml)26 Test (org.junit.Test)20 File (java.io.File)17 ServletDef (org.apache.catalina.deploy.ServletDef)5 WebRuleSet (org.apache.catalina.startup.WebRuleSet)5 XmlErrorHandler (org.apache.tomcat.util.descriptor.XmlErrorHandler)5 Digester (org.apache.tomcat.util.digester.Digester)5 URL (java.net.URL)4 FilterDef (org.apache.catalina.deploy.FilterDef)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 NamingException (javax.naming.NamingException)2 ServletContainerInitializer (javax.servlet.ServletContainerInitializer)2 StandardContext (org.apache.catalina.core.StandardContext)2 FilterMap (org.apache.catalina.deploy.FilterMap)2 FileDirContext (org.apache.naming.resources.FileDirContext)2 InputSource (org.xml.sax.InputSource)2 JarURLConnection (java.net.JarURLConnection)1 MalformedURLException (java.net.MalformedURLException)1