Search in sources :

Example 6 with SimpleNamespaceResolver

use of org.glassfish.jersey.internal.util.SimpleNamespaceResolver in project jersey by jersey.

the class ResourceExtendedFlagTest method testDetailedWadl.

/**
     * Tests full wadl with all "extended" details.
     *
     * @throws ParserConfigurationException
     * @throws XPathExpressionException
     * @throws IOException
     * @throws SAXException
     */
@Test
public void testDetailedWadl() throws ParserConfigurationException, XPathExpressionException, IOException, SAXException {
    Response response = target("/application.wadl").queryParam(WadlUtils.DETAILED_WADL_QUERY_PARAM, "true").request(MediaTypes.WADL_TYPE).get();
    assertEquals(200, response.getStatus());
    File tmpFile = response.readEntity(File.class);
    DocumentBuilderFactory bf = DocumentBuilderFactory.newInstance();
    bf.setNamespaceAware(true);
    bf.setValidating(false);
    if (!SaxHelper.isXdkDocumentBuilderFactory(bf)) {
        bf.setXIncludeAware(false);
    }
    DocumentBuilder b = bf.newDocumentBuilder();
    Document d = b.parse(tmpFile);
    printSource(new DOMSource(d));
    XPath xp = XPathFactory.newInstance().newXPath();
    xp.setNamespaceContext(new SimpleNamespaceResolver("wadl", "http://wadl.dev.java.net/2009/02"));
    // check base URI
    String val = (String) xp.evaluate("/wadl:application/wadl:resources/@base", d, XPathConstants.STRING);
    assertEquals(val, getBaseUri().toString());
    // check total number of resources is 8
    val = (String) xp.evaluate("count(//wadl:resource)", d, XPathConstants.STRING);
    assertEquals("8", val);
    val = (String) xp.evaluate("count(//wadl:resource[@path='all-extended'])", d, XPathConstants.STRING);
    assertEquals("1", val);
    val = (String) xp.evaluate("count(//wadl:resource[@path='resource'])", d, XPathConstants.STRING);
    assertEquals("1", val);
    val = (String) xp.evaluate("count(//wadl:resource[@path='application.wadl'])", d, XPathConstants.STRING);
    assertEquals("1", val);
    xp.setNamespaceContext(new SimpleNamespaceResolver("jersey", "http://jersey.java.net/"));
    val = (String) xp.evaluate("count(//jersey:extended)", d, XPathConstants.STRING);
    assertEquals("31", val);
}
Also used : Response(javax.ws.rs.core.Response) XPath(javax.xml.xpath.XPath) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SimpleNamespaceResolver(org.glassfish.jersey.internal.util.SimpleNamespaceResolver) Document(org.w3c.dom.Document) File(java.io.File) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Aggregations

XPath (javax.xml.xpath.XPath)6 SimpleNamespaceResolver (org.glassfish.jersey.internal.util.SimpleNamespaceResolver)6 Document (org.w3c.dom.Document)6 DocumentBuilder (javax.xml.parsers.DocumentBuilder)5 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)5 Response (javax.ws.rs.core.Response)4 File (java.io.File)3 JerseyTest (org.glassfish.jersey.test.JerseyTest)3 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DOMSource (javax.xml.transform.dom.DOMSource)2 WebTarget (javax.ws.rs.client.WebTarget)1 Diff (org.custommonkey.xmlunit.Diff)1 SimpleNamespaceContext (org.custommonkey.xmlunit.SimpleNamespaceContext)1