/** * Assert that the following XPath query selects no nodes. * * @param xpath */ public NodeList assertInvalid(String xpath, Node node) throws Exception { return XPathAssert.assertInvalid(xpath, node, namespaces); }
public void assertNoFault(Node node) throws Exception { XPathAssert.assertNoFault(node); }
/** * Assert that the following XPath query selects one or more nodes. * * @param xpath * @throws Exception */ public NodeList assertValid(String xpath, Node node) throws Exception { return XPathAssert.assertValid(xpath, node, namespaces); }
/** * Assert that the following XPath query selects no nodes. * * @param xpath */ public static NodeList assertInvalid(String xpath, Node node, Map<String, String> namespaces) throws Exception { if (node == null) { throw new NullPointerException("Node cannot be null."); } NodeList nodes = (NodeList)createXPath(namespaces).evaluate(xpath, node, XPathConstants.NODESET); if (nodes.getLength() > 0) { String value = writeNodeToString(node); throw new AssertionFailedError("Found multiple nodes for expression:\n" + xpath + "\n" + value); } return nodes; }
/** * Asser that the text of the xpath node retrieved is equal to the value * specified. * * @param xpath * @param value * @param node */ public static void assertXPathEquals(String xpath, String value, Node node, Map<String, String> namespaces) throws Exception { Node result = (Node)createXPath(namespaces).evaluate(xpath, node, XPathConstants.NODE); if (result == null) { throw new AssertionFailedError("No nodes were found for expression: " + xpath); } String value2 = getContent(result).trim(); Assert.assertEquals(value, value2); }
/** * Asser that the text of the xpath node retrieved is equal to the value * specified. * * @param xpath * @param value * @param node */ public void assertXPathEquals(String xpath, String value, Node node) throws Exception { XPathAssert.assertXPathEquals(xpath, value, node, namespaces); }
private static String writeNodeToString(Node node) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { writeXml(node, bos); } catch (TransformerException e) { throw new RuntimeException(e); } return bos.toString(); }
/** * Get the trimed text content of a node or null if there is no text */ public static String getContent(Node n) { if (n == null) { return null; } Node n1 = getChild(n, Node.TEXT_NODE); if (n1 == null) { return null; } return n1.getNodeValue().trim(); }
/** * Assert that the following XPath query selects one or more nodes. * * @param xpath */ public static NodeList assertValid(String xpath, Node node, Map<String, String> namespaces) throws Exception { if (node == null) { throw new NullPointerException("Node cannot be null."); } NodeList nodes = (NodeList)createXPath(namespaces).evaluate(xpath, node, XPathConstants.NODESET); if (nodes.getLength() == 0) { throw new AssertionFailedError("Failed to select any nodes for expression:\n" + xpath + " from document:\n" + writeNodeToString(node)); } return nodes; }
public static void assertFault(Node node) throws Exception { Map<String, String> namespaces = new HashMap<String, String>(); namespaces.put("s", "http://schemas.xmlsoap.org/soap/envelope/"); namespaces.put("s12", "http://www.w3.org/2003/05/soap-envelope"); assertValid("/s:Envelope/s:Body/s:Fault", node, namespaces); assertValid("/s12:Envelope/s12:Body/s12:Fault", node, namespaces); }
public static void assertNoFault(Node node) throws Exception { Map<String, String> namespaces = new HashMap<String, String>(); namespaces.put("s", "http://schemas.xmlsoap.org/soap/envelope/"); namespaces.put("s12", "http://www.w3.org/2003/05/soap-envelope"); assertInvalid("/s:Envelope/s:Body/s:Fault", node, namespaces); assertInvalid("/s12:Envelope/s12:Body/s12:Fault", node, namespaces); }