private LinkedHashSet<String> getStringValues(final NodeInfo nodeInfo, final String xpath) throws XPathException { final XPathExpression expr = getXPathExpression(nodeInfo, xpath); final List<Object> os = expr.evaluate(nodeInfo); final LinkedHashSet<String> values = new LinkedHashSet<String>(); for (Object o : os) { values.add(getStringValue(o)); } return values; }
private List<NodeInfo> getBaseNodes(final NodeInfo nodeInfo, final String xpath) throws Exception { final XPathExpression exprBase = getXPathExpression(nodeInfo, xpath); final List resultBase = exprBase.evaluate(nodeInfo); final List<NodeInfo> importEls = new LinkedList<NodeInfo>(); for (final Object o : resultBase) { if (o instanceof NodeInfo) { importEls.add(((NodeInfo) o)); } } return importEls; }
public static void assertXPathEquals( String xpathString, Document doc, boolean ignoreOrder, Object... expectedValues) { try { XPathEvaluator xpathEvaluator = new XPathEvaluator(); XPathExpression expr = xpathEvaluator.createExpression(xpathString); final JDOMSource docAsDomSource = new JDOMSource(doc); List nodes = expr.evaluate(docAsDomSource); if (nodes.size() != expectedValues.length) { org.junit.Assert.fail( "expected " + expectedValues.length + " values at xpath: " + xpathString); } String[] actualValues = new String[nodes.size()]; for (int i = 0; i < expectedValues.length; i++) { Object node = nodes.get(i); if (node instanceof NodeInfo) { NodeInfo nodeInfo = (NodeInfo) node; actualValues[i] = nodeInfo.getStringValue(); } else { actualValues[i] = String.valueOf(node); } } String[] expectedValuesAsString = new String[expectedValues.length]; for (int i = 0; i < expectedValues.length; i++) { expectedValuesAsString[i] = String.valueOf(expectedValues[i]); } if (ignoreOrder) { Arrays.sort(actualValues); Arrays.sort(expectedValuesAsString); } org.junit.Assert.assertArrayEquals(expectedValuesAsString, actualValues); } catch (Exception e) { throw new RuntimeException(e); } }
private String getHtmlValue(final NodeInfo nodeInfo, final String xpath) throws XPathException { final XPathExpression expr = getXPathExpression(nodeInfo, xpath + "/node()"); final List<Object> nodes = expr.evaluate(nodeInfo); return getHtmlValue(nodes); }