Java Code Examples for org.custommonkey.xmlunit.XMLUnit#setIgnoreDiffBetweenTextAndCDATA()

The following examples show how to use org.custommonkey.xmlunit.XMLUnit#setIgnoreDiffBetweenTextAndCDATA() . 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 vote down vote up
@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 vote down vote up
@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 vote down vote up
@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 vote down vote up
@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: UtilsDiff.java    From apogen with Apache License 2.0 5 votes vote down vote up
/**
 * BETA version of APOGEN-DOM-differencing mechanism
 * 
 * @param doc1
 * @param doc2
 * @return list of Differences
 * @throws ParserConfigurationException
 * @throws IOException
 * @throws SAXException
 */
@SuppressWarnings("unchecked")
public static List<Difference> customisedDomDiff(String string, String string2)
		throws ParserConfigurationException, SAXException, IOException {

	org.w3c.dom.Document doc1 = asDocument(string, true);
	org.w3c.dom.Document doc2 = asDocument(string2, true);

	XMLUnit.setControlParser("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
	XMLUnit.setTestParser("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
	XMLUnit.setSAXParserFactory("org.apache.xerces.jaxp.SAXParserFactoryImpl");

	XMLUnit.setNormalizeWhitespace(true);
	XMLUnit.setIgnoreAttributeOrder(true);
	XMLUnit.setIgnoreWhitespace(true);
	XMLUnit.setIgnoreComments(true);
	XMLUnit.setNormalize(true);
	XMLUnit.setIgnoreDiffBetweenTextAndCDATA(false);

	Diff d = new Diff(doc1, doc2);
	DetailedDiff dd = new DetailedDiff(d);

	dd.overrideDifferenceListener(new DomDifferenceListener());
	dd.overrideElementQualifier(null);

	return dd.getAllDifferences();
}
 
Example 6
Source File: DOMRoundtrip.java    From exificient with MIT License 5 votes vote down vote up
protected void isXMLEqual(Document control, Document test)
		throws SAXException, IOException {
	XMLUnit.setIgnoreWhitespace(true);
	XMLUnit.setIgnoreAttributeOrder(true);
	XMLUnit.setIgnoreComments(true);
	XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
	// XMLUnit.setNormalize(true);

	// Diff diff = compareXML (control, test);

	assertXMLEqual(control, test);
}
 
Example 7
Source File: ParallelTest.java    From exificient with MIT License 5 votes vote down vote up
private void testParallelDecode(ParallelExiFactory parallelExiFactory,
		int nbThreads, int nbTask) throws Exception {
	EXIFactory exiFactory = getExiFactory();
	ArrayList<ExiSch> nc1NameExiMap = getExiSch(parallelExiFactory, true,
			exiFactory);
	Collection<Callable<DecodeResult>> tasks = new ArrayList<Callable<DecodeResult>>();
	for (int i = 0; i < nbTask; i++) {
		tasks.add(new TaskDecode(
				nc1NameExiMap.get(i % nc1NameExiMap.size())));
	}

	ExecutorService executor = Executors.newFixedThreadPool(nbThreads);
	List<Future<DecodeResult>> results = executor.invokeAll(tasks);
	int differentExiCount = 0;

	XMLUnit.setIgnoreWhitespace(true);
	XMLUnit.setIgnoreAttributeOrder(true);
	XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
	XMLUnit.setIgnoreComments(true);

	for (Future<DecodeResult> result : results) {
		DecodeResult exiResult = result.get();

		Diff diff = compareXML(exiResult.roundTripDoc, exiResult.doc);
		if (!diff.similar()) {
			differentExiCount++;
		}
	}
	executor.shutdown();
	assertEquals(0, differentExiCount);
}
 
Example 8
Source File: IbisConsoleTest.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Before
public void initXMLUnit() throws IOException {
	XMLUnit.setIgnoreWhitespace(true);
	XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
	session = new PipeLineSessionBase();
	session.put("method", "GET");
}
 
Example 9
Source File: XmlUnitService.java    From cerberus-source with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initializes {@link XMLUnit} properties
 */
private void initXMLUnitProperties() {
    XMLUnit.setIgnoreComments(true);
    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
    XMLUnit.setCompareUnmatched(false);
}
 
Example 10
Source File: ParallelTest.java    From exificient with MIT License 4 votes vote down vote up
private void testParallelEncode(ParallelExiFactory parallelExiFactory,
		int nbThreads, int nbTask, boolean testXml) throws Exception {
	EXIFactory exiFactory = getExiFactory();
	ArrayList<ExiSch> nc1NameExiMap = getExiSch(parallelExiFactory,
			testXml, exiFactory);
	Collection<Callable<EncodeResult>> tasks = new ArrayList<Callable<EncodeResult>>();
	for (int i = 0; i < nbTask; i++) {
		tasks.add(new TaskEncode(
				nc1NameExiMap.get(i % nc1NameExiMap.size())));
	}

	ExecutorService executor = Executors.newFixedThreadPool(nbThreads);
	List<Future<EncodeResult>> results = executor.invokeAll(tasks);
	int differentExiCount = 0;

	if (testXml) {
		XMLUnit.setIgnoreWhitespace(true);
		XMLUnit.setIgnoreAttributeOrder(true);
		XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
		XMLUnit.setIgnoreComments(true);
	}

	for (Future<EncodeResult> result : results) {
		EncodeResult exiResult = result.get();
		boolean equals = Arrays
				.equals(exiResult.exiOriginal, exiResult.exi);
		if (!equals) {
			differentExiCount++;
		}

		if (testXml) {
			Document document = decodeExiToDoc(exiResult.exi, exiFactory);
			Diff diff = compareXML(document, exiResult.roundTripDoc);
			if (equals) {
				Assert.assertTrue(diff.toString(), diff.similar());
			} else {
				Assert.assertFalse(diff.toString(), diff.similar());
			}
		}
	}
	executor.shutdown();
	assertEquals(0, differentExiCount);
}
 
Example 11
Source File: DtrMapTestCase.java    From exificient with MIT License 4 votes vote down vote up
private byte[] testEString(String xmlAsString) throws EXIException,
		IOException, SAXException, TransformerException {
	/* DTR Map */
	QName type = new QName("", "es");
	QName representation = new QName(Constants.W3C_EXI_NS_URI, "estring");
	QName[] dtrMapTypes = { type };
	QName[] dtrMapRepresentations = { representation };

	// factory
	EXIFactory ef = DefaultEXIFactory.newInstance();
	ef.setFidelityOptions(FidelityOptions.createStrict());
	ef.setGrammars(GrammarFactory.newInstance().createGrammars(
			new ByteArrayInputStream(xsdAsStringEString.getBytes())));
	ef.setDatatypeRepresentationMap(dtrMapTypes, dtrMapRepresentations);

	// encode
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	EXIResult exiResult = new EXIResult(ef);
	exiResult.setOutputStream(baos);
	XMLReader xmlReader = XMLReaderFactory.createXMLReader();
	xmlReader.setContentHandler(exiResult.getHandler());
	xmlReader.parse(new InputSource(new ByteArrayInputStream(xmlAsString
			.getBytes()))); // parse XML input

	// decode
	ByteArrayOutputStream baosXML = new ByteArrayOutputStream();
	Result result = new StreamResult(baosXML);
	InputSource is = new InputSource(new ByteArrayInputStream(
			baos.toByteArray()));
	SAXSource exiSource = new EXISource(ef);
	exiSource.setInputSource(is);
	TransformerFactory tf = TransformerFactory.newInstance();
	Transformer transformer = tf.newTransformer();
	transformer.transform(exiSource, result);

	// System.out.println(new String(baosXML.toByteArray()));

	XMLUnit.setIgnoreWhitespace(true);
	XMLUnit.setIgnoreAttributeOrder(true);
	XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);

	XMLAssert.assertXMLEqual(new StringReader(xmlAsString),
			new StringReader(new String(baosXML.toByteArray())));

	return baos.toByteArray();
}
 
Example 12
Source File: TestBug18026.java    From java-client-api with Apache License 2.0 4 votes vote down vote up
@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 13
Source File: TestBug18026.java    From java-client-api with Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example 14
Source File: Main.java    From libreveris with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void compare ()
{
    // Comparing
    try {
        output.println("Comparing " + controlFile + " to " + testFile);

        final Document controlDoc;
        final Document testDoc;

        try (InputStream cis = new FileInputStream(controlFile)) {
            controlDoc = new PositionalXMLReader().readXML(cis);
        }
        try (InputStream tis = new FileInputStream(testFile)) {
            testDoc = new PositionalXMLReader().readXML(tis);
        }

        // Tuning
        XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
        XMLUnit.setNormalizeWhitespace(true);
        XMLUnit.setIgnoreWhitespace(true);

        ///XMLUnit.setIgnoreComments(true); NO!!!!!!!!
        // The setIgnoreComments triggers the use of XSLT transform
        // which 1/ ruins userdata and 2/ fails on xml:space and xml:lang.
        // Moreover, comments are actually ignored by Diff

        ///XMLUnit.setCompareUnmatched(false); NO need

        // Customization
        Filter filter = (filterFile != null)
                ? new BasicFilter(new FileInputStream(filterFile))
                : null;

        Diff diff = new Diff(controlDoc, testDoc, null);
        diff.overrideElementQualifier(
                new ElementNameAndAttributeQualifier("number"));
        diff.overrideDifferenceListener(
                new MusicDifferenceListener(filter, output));

        output.println("Similar:     " + diff.similar());
        output.println("Identical:   " + diff.identical());

        DetailedDiff detDiff = new DetailedDiff(diff);

        List differences = detDiff.getAllDifferences();
        output.println();
        output.println("Physical differences: " + differences.size());

        int diffId = 0;

        for (Object object : differences) {
            Difference difference = (Difference) object;

            if (!difference.isRecoverable()
                && ((filter == null) || !filter.canIgnore(difference))) {
                diffId++;
                output.dump(diffId, difference);
            }
        }
        output.println("Logical  differences: " + diffId);
        logger.info("Logical  differences: {}", diffId);

    } catch (ConfigurationException | SAXException | IOException e) {
        e.printStackTrace();
    }
}
 
Example 15
Source File: XmlBuilderTest.java    From iaf with Apache License 2.0 4 votes vote down vote up
@Before
public void initXMLUnit() throws LDAPException, IOException {
	XMLUnit.setIgnoreWhitespace(true);
	XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
}
 
Example 16
Source File: EjbJarXmlTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
/**
 * TODO Doesn't seem there are any asserts here
 *
 * @throws Exception
 */
public void testEjbJar() throws Exception {
    final String fileName = "ejb-jar-example1.xml";

    final Event test = Event.start("Test");

    final URL resource = this.getClass().getClassLoader().getResource(fileName);

    final String expected = IO.slurp(resource);

    final Event ejbJarJAXBCreate = Event.start("EjbJarJAXBCreate");
    ejbJarJAXBCreate.stop();

    final Event unmarshalEvent = Event.start("unmarshal");
    final Object value;

    final EjbJar$JAXB jaxbType = new EjbJar$JAXB();
    value = Sxc.unmarshalJavaee(resource, jaxbType);

    unmarshalEvent.stop();

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();

    final Event marshall = Event.start("marshall");
    Sxc.marshall(jaxbType, value, baos);
    marshall.stop();

    final String result = new String(baos.toByteArray(), "UTF-8");

    XMLUnit.setIgnoreComments(Boolean.TRUE);
    XMLUnit.setIgnoreWhitespace(Boolean.TRUE);
    XMLUnit.setIgnoreAttributeOrder(Boolean.TRUE);
    XMLUnit.setIgnoreDiffBetweenTextAndCDATA(Boolean.TRUE);

    final Diff diff = new Diff(expected.trim(), result.trim());
    final Diff myDiff = new DetailedDiff(diff);

    final AtomicInteger differenceNumber = new AtomicInteger(0); // just to get an int wrapper for the test
    myDiff.overrideDifferenceListener(new IgnoreTextAndAttributeValuesDifferenceListener() {
        @Override
        public int differenceFound(final Difference difference) {
            if (!difference.isRecoverable()) {
                differenceNumber.incrementAndGet();
                System.err.println(">>> " + difference.toString());
            }
            return 0;
        }
    });

    assertTrue("Files are not identical", myDiff.identical());
    test.stop();
}