@Test
public void testBaseWadlGenerator() throws Exception {

    ResourceDescriptor ard = new AbstractResourceDescriptor(Resource1.class);
    WadlProcessor wadlProcessor = new WadlProcessor();
    Application app = wadlProcessor.process(ard, new URI("http://localhost:8080/ws/rs"));
    JAXBContext jctx = JAXBContext.newInstance(Application.class);
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    jctx.createMarshaller().marshal(app, bout);
    System.out.println(new String(bout.toByteArray()));
    DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
    f.setNamespaceAware(true);
    Document doc = f.newDocumentBuilder().parse(new ByteArrayInputStream(bout.toByteArray()));
    XPath xp = XPathFactory.newInstance().newXPath();
    xp.setNamespaceContext(new DummyNamespaceContext());
    String str = (String)xp.evaluate("count(//wadl:resource)", doc, STRING);
    assertEquals("4", str);
    str = (String)xp.evaluate("count(//wadl:resource[@path='a/{b}'])", doc, STRING);
    assertEquals("1", str);
    str = (String)xp.evaluate("count(//wadl:resource[@path='{c}/{d}'])", doc, STRING);
    assertEquals("1", str);
    str = (String)xp.evaluate("count(//wadl:resource[@path='{c}/{d}/{e}'])", doc, STRING);
    assertEquals("1", str);
    str = (String)xp.evaluate("count(//wadl:resource[@path='sub/{x}'])", doc, STRING);
    assertEquals("1", str);
    // discover resource methods
    str = (String)xp.evaluate("count(//wadl:resource[@path='a/{b}']/wadl:method)", doc, STRING);
    assertEquals("5", str);
    NodeList nl = (NodeList)xp.evaluate("//wadl:resource[@path='a/{b}']/wadl:method[@id='m1']/@name", doc, NODESET);
    assertEquals(1, nl.getLength());
    boolean get = false;
    for (int i = 0; i < nl.getLength(); i++) {
        String t = nl.item(i).getTextContent();
        if (t.equals("GET")) {
            get = true;
        }
    }
    assertTrue(get);
    for (int i = 0; i < nl.getLength(); i++) {
        System.out.println(">>>>> resource method : " + nl.item(i).getTextContent());
    }
    str = (String)xp.evaluate("//wadl:resource[@path='a/{b}']/wadl:method[@id='m2']/@name", doc, STRING);
    assertEquals("POST", str);
    str = (String)xp.evaluate("//wadl:resource[@path='a/{b}']/wadl:method[@id='m2']/wadl:request/wadl:param[@style='header']/@name", doc, STRING);
    assertEquals("content-type", str);
    str = (String)xp.evaluate("//wadl:resource[@path='a/{b}']/wadl:method[@id='m3']/@name", doc, STRING);
    assertEquals("DELETE", str);
    str = (String)xp.evaluate("//wadl:resource[@path='a/{b}']/wadl:method[@id='m4']/@name", doc, STRING);
    assertEquals("PUT", str);
    // discover sub-resource methods
    nl = (NodeList)xp.evaluate("//wadl:resource[@path='a/{b}']/wadl:resource[@path='{c}/{d}']/wadl:method/@name", doc, NODESET);
    assertEquals(1, nl.getLength());
    boolean subget = false;
    for (int i = 0; i < nl.getLength(); i++) {
        String t = nl.item(i).getTextContent();
        if (t.equals("GET")) {
            subget = true;
        }
    }
    assertTrue(subget);
    for (int i = 0; i < nl.getLength(); i++) {
        System.out.println(">>>>> sub-resource method : " + nl.item(i).getTextContent());
    }
    str = (String)xp.evaluate("count(//wadl:resource[@path='a/{b}']/wadl:resource[@path='{c}/{d}/{e}']/wadl:method)", doc, STRING);
    assertEquals("1", str);
    str = (String)xp.evaluate("//wadl:resource[@path='a/{b}']/wadl:resource[@path='{c}/{d}']/wadl:param[@name='c']/@style", doc, STRING);
    assertEquals("template", str);
    str = (String)xp.evaluate("//wadl:resource[@path='a/{b}']/wadl:resource[@path='{c}/{d}']/wadl:param[@name='b']/@style", doc, STRING);
    assertEquals("template", str);
    str = (String)xp.evaluate("//wadl:resource[@path='a/{b}']/wadl:resource[@path='{c}/{d}/{e}']/wadl:param[@name='c']/@style", doc, STRING);
    assertEquals("template", str);
    str = (String)xp.evaluate("//wadl:resource[@path='a/{b}']/wadl:resource[@path='{c}/{d}/{e}']/wadl:param[@name='e']/@style", doc, STRING);
    assertEquals("template", str);
    str = (String)xp.evaluate("//wadl:resource[@path='a/{b}']/wadl:resource[@path='{c}/{d}/{e}']/wadl:method[@id='m6']/@name", doc, STRING);
    assertEquals("POST", str);
    // discover sub-resource locators
    nl = (NodeList)xp.evaluate("//wadl:resource[@path='a/{b}']/wadl:resource[@path='sub/{x}']/wadl:method/@name", doc, NODESET);
    assertEquals(2, nl.getLength());
    boolean childget = false;
    boolean childopt = false;
    for (int i = 0; i < nl.getLength(); i++) {
        String t = nl.item(i).getTextContent();
        if (t.equals("GET")) {
            childget = true;
        }
        if (t.equals("OPTIONS")) {
            childopt = true;
        }
    }
    assertTrue(childget && childopt);
    for (int i = 0; i < nl.getLength(); i++) {
        System.out.println(">>>>> child resource method : " + nl.item(i).getTextContent());
    }
    str = (String)xp.evaluate("count(//wadl:resource[@path='a/{b}']/wadl:resource[@path='sub/{x}']/wadl:method)", doc, STRING);
    assertEquals("2", str);
    str = (String)xp.evaluate("//wadl:resource[@path='a/{b}']/wadl:resource[@path='sub/{x}']/wadl:param[@name='x']/@style", doc, STRING);
    assertEquals("template", str);
    str = (String)xp.evaluate("//wadl:resource[@path='a/{b}']/wadl:resource[@path='sub/{x}']/wadl:method[@id='m0']/wadl:response/wadl:representation/@mediaType", doc, STRING);
    assertEquals("text/plain", str);
}