Search in sources :

Example 1 with DiscoveredAnnotation

use of org.eclipse.jetty.webapp.DiscoveredAnnotation in project jetty.project by eclipse.

the class TestServletAnnotations method testServletAnnotation.

@Test
public void testServletAnnotation() throws Exception {
    List<String> classes = new ArrayList<String>();
    classes.add("org.eclipse.jetty.annotations.ServletC");
    AnnotationParser parser = new AnnotationParser();
    WebAppContext wac = new WebAppContext();
    List<DiscoveredAnnotation> results = new ArrayList<DiscoveredAnnotation>();
    TestWebServletAnnotationHandler handler = new TestWebServletAnnotationHandler(wac, results);
    parser.parse(Collections.singleton(handler), classes);
    assertEquals(1, results.size());
    assertTrue(results.get(0) instanceof WebServletAnnotation);
    results.get(0).apply();
    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);
    assertEquals(1, mappings.length);
    String[] paths = mappings[0].getPathSpecs();
    assertNotNull(paths);
    assertEquals(2, paths.length);
}
Also used : ServletMapping(org.eclipse.jetty.servlet.ServletMapping) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ArrayList(java.util.ArrayList) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) DiscoveredAnnotation(org.eclipse.jetty.webapp.DiscoveredAnnotation) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1 ServletMapping (org.eclipse.jetty.servlet.ServletMapping)1 DiscoveredAnnotation (org.eclipse.jetty.webapp.DiscoveredAnnotation)1 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)1 Test (org.junit.Test)1