Search in sources :

Example 6 with JavaClassCacheEntry

use of org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry 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"));
}
Also used : WebXml(org.apache.tomcat.util.descriptor.web.WebXml) FilterDef(org.apache.tomcat.util.descriptor.web.FilterDef) HashMap(java.util.HashMap) JavaClassCacheEntry(org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry) File(java.io.File) Test(org.junit.Test)

Example 7 with JavaClassCacheEntry

use of org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry 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);
}
Also used : WebXml(org.apache.tomcat.util.descriptor.web.WebXml) HashMap(java.util.HashMap) ServletDef(org.apache.tomcat.util.descriptor.web.ServletDef) JavaClassCacheEntry(org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry) File(java.io.File) Test(org.junit.Test)

Example 8 with JavaClassCacheEntry

use of org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry in project tomcat by apache.

the class TestContextConfigAnnotation method testNoMapping.

@Test
public void testNoMapping() throws Exception {
    WebXml webxml = new WebXml();
    Map<String, JavaClassCacheEntry> javaClassCache = new HashMap<>();
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource("org/apache/catalina/startup/NoMappingParamServlet");
    assertTrue(pFile.exists());
    config.processAnnotationsFile(pFile, webxml, false, javaClassCache);
    ServletDef servletDef = webxml.getServlets().get("param1");
    assertNull(servletDef);
    webxml.addServletMapping("/param", "param1");
    config.processAnnotationsFile(pFile, webxml, false, javaClassCache);
    servletDef = webxml.getServlets().get("param1");
    assertNull(servletDef);
}
Also used : WebXml(org.apache.tomcat.util.descriptor.web.WebXml) HashMap(java.util.HashMap) ServletDef(org.apache.tomcat.util.descriptor.web.ServletDef) JavaClassCacheEntry(org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry) File(java.io.File) Test(org.junit.Test)

Example 9 with JavaClassCacheEntry

use of org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry in project tomcat by apache.

the class TestContextConfigAnnotation method testDuplicateFilterMapping.

@Test
public void testDuplicateFilterMapping() throws Exception {
    WebXml webxml = new WebXml();
    Map<String, JavaClassCacheEntry> javaClassCache = new HashMap<>();
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource("org/apache/catalina/startup/DuplicateMappingParamFilter");
    assertTrue(pFile.exists());
    try {
        config.processAnnotationsFile(pFile, webxml, false, javaClassCache);
        fail();
    } catch (IllegalArgumentException ex) {
    // ignore
    }
    FilterDef filterDef = webxml.getFilters().get("paramD");
    assertNull(filterDef);
}
Also used : WebXml(org.apache.tomcat.util.descriptor.web.WebXml) FilterDef(org.apache.tomcat.util.descriptor.web.FilterDef) HashMap(java.util.HashMap) JavaClassCacheEntry(org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)9 HashMap (java.util.HashMap)9 JavaClassCacheEntry (org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry)9 WebXml (org.apache.tomcat.util.descriptor.web.WebXml)9 Test (org.junit.Test)9 ServletDef (org.apache.tomcat.util.descriptor.web.ServletDef)5 FilterDef (org.apache.tomcat.util.descriptor.web.FilterDef)3 Servlet (javax.servlet.Servlet)1 ServletContainerInitializer (javax.servlet.ServletContainerInitializer)1 StandardContext (org.apache.catalina.core.StandardContext)1 FilterMap (org.apache.tomcat.util.descriptor.web.FilterMap)1