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);
}
Aggregations