private void compareXML(String expected, String actual) throws Exception { setNormalizeWhitespace(true); setIgnoreWhitespace(true); setIgnoreComments(true); setIgnoreAttributeOrder(false); Diff diff = XMLUnit.compareXML(expected, actual); if (!(diff.similar() && diff.identical())) { System.out.println(actual); DetailedDiff detDiff = new DetailedDiff(diff); @SuppressWarnings("rawtypes") List differences = detDiff.getAllDifferences(); StringBuilder diffLines = new StringBuilder(); for (Object object : differences) { Difference difference = (Difference) object; diffLines.append(difference.toString() + '\n'); } throw new IllegalArgumentException("Actual XML differs from expected: \n" + diffLines.toString()); } } }
/** * Receives to {@link String} representation of two XML files and verify that they are semantically equivalent * * @param expected the reference content * @param actual the actual content * @throws Exception if comparison fails */ public static void compareXML(String expected, String actual) throws Exception { XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreAttributeOrder(false); Diff diff = XMLUnit.compareXML(expected, actual); if (!(diff.similar() && diff.identical())) { System.out.println(actual); DetailedDiff detDiff = new DetailedDiff(diff); @SuppressWarnings("rawtypes") List differences = detDiff.getAllDifferences(); StringBuilder diffLines = new StringBuilder(); for (Object object : differences) { Difference difference = (Difference) object; diffLines.append(difference.toString() + '\n'); } throw new IllegalArgumentException("Actual XML differs from expected: \n" + diffLines.toString()); } }
/** * Configure XML Unit parameters for comparing XML - override this to adjust the defaults */ protected void configureXmlUnit() { XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreComments(true); }
protected void checkXmlStructure(String xmlunitPage, String pageCode) throws SAXException, IOException { InputStream expectedPageCode = testClass.get().getJavaClass().getResourceAsStream(xmlunitPage); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreComments(true); Diff xmlDiff = new Diff(new InputStreamReader(expectedPageCode), new StringReader(pageCode)); xmlDiff.overrideDifferenceListener(getDifferenceListener()); if (!xmlDiff.similar()) { System.out.println("=== ACTUAL PAGE CODE ==="); System.out.println(pageCode); System.out.println("======== ERROR ========="); System.out.println(xmlDiff.toString()); System.out.println("========================"); fail("XML was not similar:" + xmlDiff.toString()); } }
private void configureXmlUnit() { XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); XMLUnit.setCompareUnmatched(false); XMLUnit.setIgnoreAttributeOrder(true); }
private void configureXmlUnit() { XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); XMLUnit.setCompareUnmatched(false); XMLUnit.setIgnoreAttributeOrder(true); }
@Before public void before() throws Exception { tempReg.addNamedTemplate("tempReg", TemplateCompiler.compileTemplate(getClass().getResourceAsStream(dataformat + ".mvt"), (Map<String, Class<? extends Node>>)null)); TemplateRuntime.execute(tempReg.getNamedTemplate("tempReg"), null, tempReg); XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setNormalize(true); if (!StringUtils.isEmpty(copyToDataFormat)) { writer = new PrintWriter(new BufferedWriter(new FileWriter(copyToDataFormat + ".mvt", true))); } }
@Test public void testUnmarshalSuiteFromXml() throws Exception { URL expectedOutputResource = getClass().getResource("mockSuiteOneExpectedOutput.xml"); String expectedXml = FileUtils.readToString(expectedOutputResource.openStream()); String replacedExpectedXml = replaceVariableContent(expectedXml); //first read a TestSuite from expected XML TestSuiteXmlMarshaller w = new TestSuiteXmlMarshaller(); StringReader stringReader = new StringReader(expectedXml); TestSuite t = w.read(stringReader); //now remarshall TestSuite to remarshalledOut StringWriter remarshalledOut = new StringWriter(); w.write(remarshalledOut, t); remarshalledOut.flush(); remarshalledOut.close(); String expectedRemarshalled = remarshalledOut.toString(); String replacedExpectedRemarshalled = replaceVariableContent(expectedRemarshalled); System.out.println(); System.out.println("This is the expected output as XML --->"); System.out.println(replacedExpectedXml); System.out.println("This is the remarshalled output as XML --->"); System.out.println(replacedExpectedRemarshalled); //original XML and remarshalled XML should be identical XMLUnit.setNormalizeWhitespace(true); Diff myDiff = new Diff(replacedExpectedXml, replacedExpectedRemarshalled); assertTrue("test XML identical " + myDiff, myDiff.identical()); }
@Before public void before() throws Exception { tempReg.addNamedTemplate( "tempReg", TemplateCompiler.compileTemplate( getClass().getResourceAsStream( dataformat + ".mvt" ), (Map<String, Class<? extends Node>>) null ) ); TemplateRuntime.execute( tempReg.getNamedTemplate( "tempReg" ), null, tempReg ); XMLUnit.setIgnoreComments( true ); XMLUnit.setIgnoreWhitespace( true ); XMLUnit.setIgnoreAttributeOrder( true ); XMLUnit.setNormalizeWhitespace( true ); XMLUnit.setNormalize( true ); if ( !StringUtils.isEmpty( copyToDataFormat ) ) { writer = new PrintWriter( new BufferedWriter( new FileWriter( copyToDataFormat + ".mvt", true ) ) ); } }
@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); }
@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); } @AfterClass
@Override public boolean matchesSafely(Source source) { String test = convertToString(source); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalize(true); XMLUnit.setNormalizeWhitespace(true); try { return new Diff(control, test).identical(); } catch (SAXException e) { return false; } catch (IOException e) { return false; } }
@Override public void setUp() throws Exception { super.setUp(); XMLUnit.setIgnoreComments( true ); XMLUnit.setIgnoreWhitespace( true ); XMLUnit.setIgnoreAttributeOrder( true ); XMLUnit.setNormalizeWhitespace( true ); XMLUnit.setNormalize( true ); }
@Before public void setUp() throws Exception { XMLUnit.setIgnoreComments( true ); XMLUnit.setIgnoreWhitespace( true ); XMLUnit.setIgnoreAttributeOrder( true ); XMLUnit.setNormalizeWhitespace( true ); XMLUnit.setNormalize( true ); }
@Before public void setUp() throws Exception { XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setNormalize(true); }
@Override public void setUp() throws Exception { super.setUp(); XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setNormalize(true); }
@Override @Before public void setUp() throws Exception { XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setNormalize(true); XStreamXML.SORT_MAPS = true; // allows us to test results easier }
@Before public void setUp() throws Exception { XMLUnit.setIgnoreComments( true ); XMLUnit.setIgnoreWhitespace( true ); XMLUnit.setIgnoreAttributeOrder( true ); XMLUnit.setNormalizeWhitespace( true ); XMLUnit.setNormalize( true ); }
@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"); } @AfterClass
@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); } @AfterClass