diff options
Diffstat (limited to 'jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestServletAnnotations.java')
-rw-r--r-- | jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestServletAnnotations.java | 82 |
1 files changed, 43 insertions, 39 deletions
diff --git a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestServletAnnotations.java b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestServletAnnotations.java index 850a22c6fe..b508876408 100644 --- a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestServletAnnotations.java +++ b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestServletAnnotations.java @@ -18,9 +18,6 @@ package org.eclipse.jetty.annotations; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -34,6 +31,13 @@ import org.eclipse.jetty.webapp.DiscoveredAnnotation; import org.eclipse.jetty.webapp.WebAppContext; import org.junit.Test; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * TestServletAnnotations */ @@ -56,7 +60,7 @@ public class TestServletAnnotations _list.add(a); } } - + @Test public void testServletAnnotation() throws Exception { @@ -66,9 +70,9 @@ public class TestServletAnnotations WebAppContext wac = new WebAppContext(); List<DiscoveredAnnotation> results = new ArrayList<DiscoveredAnnotation>(); - + TestWebServletAnnotationHandler handler = new TestWebServletAnnotationHandler(wac, results); - + parser.parse(Collections.singleton(handler), classes, new ClassNameResolver () { public boolean isExcluded(String name) @@ -82,7 +86,7 @@ public class TestServletAnnotations } }); - + assertEquals(1, results.size()); assertTrue(results.get(0) instanceof WebServletAnnotation); @@ -91,14 +95,14 @@ public class TestServletAnnotations ServletHolder[] holders = wac.getServletHandler().getServlets(); assertNotNull(holders); assertEquals(1, holders.length); - + // Verify servlet annotations ServletHolder cholder = holders[0]; assertThat("Servlet Name", cholder.getName(), is("CServlet")); assertThat("InitParameter[x]", cholder.getInitParameter("x"), is("y")); assertThat("Init Order", cholder.getInitOrder(), is(2)); assertThat("Async Supported", cholder.isAsyncSupported(), is(false)); - + // Verify mappings ServletMapping[] mappings = wac.getServletHandler().getServletMappings(); assertNotNull(mappings); @@ -107,33 +111,33 @@ public class TestServletAnnotations assertNotNull(paths); assertEquals(2, paths.length); } - - + + @Test public void testWebServletAnnotationOverrideDefault () throws Exception { //if the existing servlet mapping TO A DIFFERENT SERVLET IS from a default descriptor we //DO allow the annotation to replace the mapping. - + WebAppContext wac = new WebAppContext(); ServletHolder defaultServlet = new ServletHolder(); defaultServlet.setClassName("org.eclipse.jetty.servlet.DefaultServlet"); - defaultServlet.setName("default"); + defaultServlet.setName("default"); wac.getServletHandler().addServlet(defaultServlet); - + ServletMapping m = new ServletMapping(); m.setPathSpec("/"); m.setServletName("default"); m.setDefault(true); //this mapping will be from a default descriptor wac.getServletHandler().addServletMapping(m); - + WebServletAnnotation annotation = new WebServletAnnotation(wac, "org.eclipse.jetty.annotations.ServletD", null); annotation.apply(); - + //test that as the original servlet mapping had only 1 pathspec, then the whole //servlet mapping should be deleted as that pathspec will be remapped to the DServlet ServletMapping[] resultMappings = wac.getServletHandler().getServletMappings(); - assertNotNull(resultMappings); + assertNotNull(resultMappings); assertEquals(1, resultMappings.length); assertEquals(2, resultMappings[0].getPathSpecs().length); resultMappings[0].getServletName().equals("DServlet"); @@ -142,38 +146,38 @@ public class TestServletAnnotations assertTrue (s.equals("/") || s.equals("/bah/*")); } } - - - + + + @Test public void testWebServletAnnotationReplaceDefault () throws Exception { //if the existing servlet mapping TO A DIFFERENT SERVLET IS from a default descriptor we - //DO allow the annotation to replace the mapping. + //DO allow the annotation to replace the mapping. WebAppContext wac = new WebAppContext(); ServletHolder defaultServlet = new ServletHolder(); defaultServlet.setClassName("org.eclipse.jetty.servlet.DefaultServlet"); - defaultServlet.setName("default"); + defaultServlet.setName("default"); wac.getServletHandler().addServlet(defaultServlet); - + ServletMapping m = new ServletMapping(); m.setPathSpec("/"); m.setServletName("default"); m.setDefault(true); //this mapping will be from a default descriptor wac.getServletHandler().addServletMapping(m); - + ServletMapping m2 = new ServletMapping(); m2.setPathSpec("/other"); m2.setServletName("default"); m2.setDefault(true); //this mapping will be from a default descriptor wac.getServletHandler().addServletMapping(m2); - + WebServletAnnotation annotation = new WebServletAnnotation(wac, "org.eclipse.jetty.annotations.ServletD", null); annotation.apply(); - + //test that only the mapping for "/" was removed from the mappings to the default servlet ServletMapping[] resultMappings = wac.getServletHandler().getServletMappings(); - assertNotNull(resultMappings); + assertNotNull(resultMappings); assertEquals(2, resultMappings.length); for (ServletMapping r:resultMappings) { @@ -194,10 +198,10 @@ public class TestServletAnnotations else fail("Unexpected servlet mapping"); } - + } - - + + @Test public void testWebServletAnnotationNotOverride () throws Exception { @@ -232,7 +236,7 @@ public class TestServletAnnotations fail("Unexpected servlet name"); } } - + @Test public void testWebServletAnnotationIgnore () throws Exception { @@ -243,33 +247,33 @@ public class TestServletAnnotations servlet.setClassName("org.eclipse.jetty.servlet.OtherDServlet"); servlet.setName("DServlet"); wac.getServletHandler().addServlet(servlet); - + ServletMapping m = new ServletMapping(); m.setPathSpec("/default"); m.setDefault(true); m.setServletName("DServlet"); wac.getServletHandler().addServletMapping(m); - + ServletMapping m2 = new ServletMapping(); m2.setPathSpec("/other"); m2.setServletName("DServlet"); wac.getServletHandler().addServletMapping(m2); - + WebServletAnnotation annotation = new WebServletAnnotation(wac, "org.eclipse.jetty.annotations.ServletD", null); annotation.apply(); ServletMapping[] resultMappings = wac.getServletHandler().getServletMappings(); assertEquals(2, resultMappings.length); - + for (ServletMapping r:resultMappings) { assertEquals(1, r.getPathSpecs().length); if (!r.getPathSpecs()[0].equals("/default") && !r.getPathSpecs()[0].equals("/other")) fail("Unexpected path in mapping"); } - + } - + @Test public void testWebServletAnnotationNoMappings () throws Exception { @@ -293,8 +297,8 @@ public class TestServletAnnotations fail("Unexpected path mapping"); } } - - + + @Test public void testDeclareRoles () |