Search in sources :

Example 1 with ServletDef

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

Example 2 with ServletDef

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

Example 3 with ServletDef

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

Example 4 with ServletDef

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

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

Aggregations

ServletDef (org.apache.catalina.deploy.ServletDef)7 File (java.io.File)5 WebXml (org.apache.catalina.deploy.WebXml)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Wrapper (org.apache.catalina.Wrapper)1 FilterMap (org.apache.catalina.deploy.FilterMap)1 AnnotationEntry (org.apache.tomcat.util.bcel.classfile.AnnotationEntry)1 ElementValuePair (org.apache.tomcat.util.bcel.classfile.ElementValuePair)1