Java Code Examples for org.custommonkey.xmlunit.XMLUnit#newXpathEngine()
The following examples show how to use
org.custommonkey.xmlunit.XMLUnit#newXpathEngine() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StructuredQueryBuilderTest.java From java-client-api with Apache License 2.0 | 6 votes |
@BeforeClass public static void beforeClass() { XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalize(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); Map<String,String> namespaces = new HashMap<>(); namespaces.put("rapi", "http://marklogic.com/rest-api"); namespaces.put("prop", "http://marklogic.com/xdmp/property"); namespaces.put("xs", "http://www.w3.org/2001/XMLSchema"); namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance"); namespaces.put("search", "http://marklogic.com/appservices/search"); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(namespaces); xpather = XMLUnit.newXpathEngine(); xpather.setNamespaceContext(namespaceContext); }
Example 2
Source File: BufferableHandleTest.java From java-client-api with Apache License 2.0 | 6 votes |
@BeforeClass public static void beforeClass() { Common.connect(); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalize(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); Map<String,String> namespaces = new HashMap<>(); namespaces.put("rapi", "http://marklogic.com/rest-api"); namespaces.put("prop", "http://marklogic.com/xdmp/property"); namespaces.put("xs", "http://www.w3.org/2001/XMLSchema"); namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance"); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(namespaces); xpather = XMLUnit.newXpathEngine(); xpather.setNamespaceContext(namespaceContext); }
Example 3
Source File: TransformExtensionsTest.java From java-client-api with Apache License 2.0 | 6 votes |
@BeforeClass public static void beforeClass() throws IOException { Common.connect(); Common.connectAdmin(); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalize(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); Map<String,String> namespaces = new HashMap<>(); namespaces.put("xsl", "http://www.w3.org/1999/XSL/Transform"); namespaces.put("rapi", "http://marklogic.com/rest-api"); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(namespaces); xpather = XMLUnit.newXpathEngine(); xpather.setNamespaceContext(namespaceContext); xqueryTransform = Common.testFileToString(XQUERY_FILE, "UTF-8"); xslTransform = Common.testFileToString(XSLT_FILE, "UTF-8"); }
Example 4
Source File: ResourceExtensionsTest.java From java-client-api with Apache License 2.0 | 6 votes |
@BeforeClass public static void beforeClass() throws IOException { Common.connectAdmin(); resourceServices = Common.testFileToString(XQUERY_FILE); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalize(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); Map<String,String> namespaces = new HashMap<>(); namespaces.put("rapi", "http://marklogic.com/rest-api"); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(namespaces); xpather = XMLUnit.newXpathEngine(); xpather.setNamespaceContext(namespaceContext); }
Example 5
Source File: JsonDataGeneratorTest.java From json-data-generator with Apache License 2.0 | 6 votes |
@Test public void testXmlTemplate() throws IOException, JsonDataGeneratorException, SAXException, ParserConfigurationException, XpathException { parser.generateTestDataJson(this.getClass().getClassLoader().getResource("xmlfunctionWithRepeat.xml"), outputStream); ByteArrayInputStream inputstream = new ByteArrayInputStream(outputStream.toByteArray()); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setCoalescing(true); dbf.setIgnoringElementContentWhitespace(true); dbf.setIgnoringComments(true); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(inputstream); XpathEngine simpleXpathEngine = XMLUnit.newXpathEngine(); String value = simpleXpathEngine.evaluate("//root/tags", doc); assertEquals(value.split(",").length, 7); assertTrue(simpleXpathEngine.evaluate("//root/element[1]/name", doc).length() > 1); assertTrue(simpleXpathEngine.evaluate("//root/element[2]/name", doc).length() > 1); assertTrue(simpleXpathEngine.evaluate("//root/friends/friend[1]/name", doc).length() > 1); assertTrue(simpleXpathEngine.evaluate("//root/friends/friend[2]/name", doc).length() > 1); assertTrue(simpleXpathEngine.evaluate("//root/friends/friend[3]/name", doc).length() > 1); }
Example 6
Source File: CastorMarshallerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Assert the values of xpath expression evaluation is exactly the same as expected value. * <p>The xpath may contain the xml namespace prefixes, since namespaces from flight example * are being registered. * @param msg the error message that will be used in case of test failure * @param expected the expected value * @param xpath the xpath to evaluate * @param xmlDoc the xml to use * @throws Exception if any error occurs during xpath evaluation */ private void assertXpathEvaluatesTo(String msg, String expected, String xpath, String xmlDoc) throws Exception { Map<String, String> namespaces = new HashMap<String, String>(); namespaces.put("tns", "http://samples.springframework.org/flight"); namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance"); NamespaceContext ctx = new SimpleNamespaceContext(namespaces); XpathEngine engine = XMLUnit.newXpathEngine(); engine.setNamespaceContext(ctx); Document doc = XMLUnit.buildControlDocument(xmlDoc); NodeList node = engine.getMatchingNodes(xpath, doc); assertEquals(msg, expected, node.item(0).getNodeValue()); }
Example 7
Source File: XPathRegexAssert.java From xmlunit with Apache License 2.0 | 5 votes |
public static void assertXPathMatches(String message, String regex, String xpath, Document doc) throws XpathException { XpathEngine engine = XMLUnit.newXpathEngine(); String value = engine.evaluate(xpath, doc); Assert.assertTrue(message, value.matches(regex)); }
Example 8
Source File: Asserts.java From OpenESPI-Common-java with Apache License 2.0 | 5 votes |
public static void assertXpathValue(String expectedValue, String xpathExpression, Document inDocument) throws XpathException { XpathEngine simpleXpathEngine = XMLUnit.newXpathEngine(); Assert.assertEquals(expectedValue, simpleXpathEngine.evaluate(xpathExpression, inDocument).trim()); }
Example 9
Source File: Asserts.java From OpenESPI-Common-java with Apache License 2.0 | 5 votes |
public static void assertXpathValueStartsWith(String expectedPrefix, String xpathExpression, String inXMLString) throws IOException, SAXException, XpathException { Document xmlDocument = XMLUnit.buildControlDocument(inXMLString); XpathEngine simpleXpathEngine = XMLUnit.newXpathEngine(); String updated = simpleXpathEngine.evaluate(xpathExpression, xmlDocument).trim(); Assert.assertThat(updated, CoreMatchers.startsWith(expectedPrefix)); }
Example 10
Source File: TestBug18026.java From java-client-api with Apache License 2.0 | 4 votes |
@Test public void testBug18026() throws KeyManagementException, NoSuchAlgorithmException, IOException, SAXException, ParserConfigurationException { String filename = "xml-original.xml"; String uri = "/write-buffer/"; byte[] before = null; byte[] after = null; String strBefore = null; String strAfter = null; System.out.println("Running testBug18026"); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalize(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); Map<String, String> namespaces = new HashMap<>(); namespaces.put("rapi", "http://marklogic.com/rest-api"); namespaces.put("prop", "http://marklogic.com/xdmp/property"); namespaces.put("xs", "http://www.w3.org/2001/XMLSchema"); namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance"); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(namespaces); xpather = XMLUnit.newXpathEngine(); xpather.setNamespaceContext(namespaceContext); // connect the client DatabaseClient client = getDatabaseClient("rest-writer", "x", getConnType()); Document readDoc = expectedXMLDocument(filename); DOMHandle dHandle = new DOMHandle(); dHandle.set(readDoc); before = dHandle.toBuffer(); strBefore = new String(before); System.out.println("Before: " + strBefore); // write doc XMLDocumentManager docMgr = client.newXMLDocumentManager(); String docId = uri + filename; docMgr.write(docId, dHandle); // read doc docMgr.read(docId, dHandle); dHandle.get(); after = dHandle.toBuffer(); strAfter = new String(after); System.out.println("After: " + strAfter); assertXMLEqual("Buffer is not the same", strBefore, strAfter); // release client client.release(); }
Example 11
Source File: TestBug18026.java From java-client-api with Apache License 2.0 | 4 votes |
@Test public void testBug18026WithJson() throws KeyManagementException, NoSuchAlgorithmException, IOException, SAXException, ParserConfigurationException { String filename = "json-original.json"; String uri = "/write-buffer/"; byte[] before = null; byte[] after = null; String strBefore = null; String strAfter = null; System.out.println("Running testBug18026WithJson"); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalize(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); Map<String, String> namespaces = new HashMap<>(); namespaces.put("rapi", "http://marklogic.com/rest-api"); namespaces.put("prop", "http://marklogic.com/xdmp/property"); namespaces.put("xs", "http://www.w3.org/2001/XMLSchema"); namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance"); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(namespaces); xpather = XMLUnit.newXpathEngine(); xpather.setNamespaceContext(namespaceContext); ObjectMapper mapper = new ObjectMapper(); // connect the client DatabaseClient client = getDatabaseClient("rest-writer", "x", getConnType()); InputStream inputStream = new FileInputStream("src/test/java/com/marklogic/client/functionaltest/data/" + filename); InputStreamHandle isHandle = new InputStreamHandle(); isHandle.set(inputStream); before = isHandle.toBuffer(); strBefore = new String(before); System.out.println("Before: " + strBefore); JsonNode contentBefore = mapper.readValue(strBefore, JsonNode.class); // write doc JSONDocumentManager docMgr = client.newJSONDocumentManager(); String docId = uri + filename; docMgr.write(docId, isHandle); // read doc docMgr.read(docId, isHandle); isHandle.get(); after = isHandle.toBuffer(); strAfter = new String(after); System.out.println("After: " + strAfter); JsonNode contentAfter = mapper.readValue(strAfter, JsonNode.class); assertTrue("Buffered JSON document difference", contentBefore.equals(contentAfter)); // release client client.release(); }