@Test public void shouldGetEmptyValueFromXPathWithNamespace() throws ParserConfigurationException, IOException, SAXException { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder(); Document parsedXml = documentBuilder.parse(new InputSource(new StringReader(namedXml))); String value = ContractVerifierUtil.valueFromXPath(parsedXml, "/customer/email/text()"); assertThat(value).isEqualTo(""); }
public static String valueFromXPath(Document parsedXml, String path) { XPath xPath = XPathFactory.newInstance().newXPath(); Element documentElement = parsedXml.getDocumentElement(); xPath.setNamespaceContext(new DOMNamespaceContext(documentElement)); try { return xPath.evaluate(path, documentElement); } catch (XPathExpressionException exception) { LOG.error("Incorrect xpath provided: " + path, exception); throw new IllegalArgumentException(); } }
ContractVerifierUtil { public static String valueFromXPath(Document parsedXml, String path) { XPath xPath = XPathFactory.newInstance().newXPath(); Element documentElement = parsedXml.getDocumentElement(); xPath.setNamespaceContext(new DOMNamespaceContext(documentElement)); try { return xPath.evaluate(path, documentElement); } catch (XPathExpressionException exception) { LOG.error("Incorrect xpath provided: " + path, exception); throw new IllegalArgumentException(); } } }
ContractVerifierUtil { public static String valueFromXPath(Document parsedXml, String path) { XPath xPath = XPathFactory.newInstance().newXPath(); Element documentElement = parsedXml.getDocumentElement(); xPath.setNamespaceContext(new DOMNamespaceContext(documentElement)); try { return xPath.evaluate(path, documentElement); } catch (XPathExpressionException exception) { LOG.error("Incorrect xpath provided: " + path, exception); throw new IllegalArgumentException(); } } private  ContractVerifierUtil(); }
ContractVerifierUtil { public static String valueFromXPath(Document parsedXml, String path) { XPath xPath = XPathFactory.newInstance().newXPath(); Element documentElement = parsedXml.getDocumentElement(); xPath.setNamespaceContext(new DOMNamespaceContext(documentElement)); try { return xPath.evaluate(path, documentElement); } catch (XPathExpressionException exception) { LOG.error("Incorrect xpath provided: " + path, exception); throw new IllegalArgumentException(); } } private  ContractVerifierUtil(); static byte[] fileToBytes(Object testClass, String relativePath); static String valueFromXPath(Document parsedXml, String path); static Node nodeFromXPath(Document parsedXml, String path); static YamlContract contract(Object testClass, String relativePath); static ContractVerifierMap map(); }
ContractVerifierUtil { public static String valueFromXPath(Document parsedXml, String path) { XPath xPath = XPathFactory.newInstance().newXPath(); Element documentElement = parsedXml.getDocumentElement(); xPath.setNamespaceContext(new DOMNamespaceContext(documentElement)); try { return xPath.evaluate(path, documentElement); } catch (XPathExpressionException exception) { LOG.error("Incorrect xpath provided: " + path, exception); throw new IllegalArgumentException(); } } private  ContractVerifierUtil(); static byte[] fileToBytes(Object testClass, String relativePath); static String valueFromXPath(Document parsedXml, String path); static Node nodeFromXPath(Document parsedXml, String path); static YamlContract contract(Object testClass, String relativePath); static ContractVerifierMap map(); static final String TEST_METHOD_PREFIX; }