use of org.custommonkey.xmlunit.DetailedDiff in project archiva by apache.
the class MetadataToolsTest method assertMetadata.
private void assertMetadata(String expectedMetadata, ManagedRepositoryContent repository, VersionedReference reference) throws LayoutException, IOException, SAXException, ParserConfigurationException {
Path metadataFile = Paths.get(repository.getRepoRoot(), tools.toPath(reference));
String actualMetadata = org.apache.archiva.common.utils.FileUtils.readFileToString(metadataFile, Charset.defaultCharset());
DetailedDiff detailedDiff = new DetailedDiff(new Diff(expectedMetadata, actualMetadata));
if (!detailedDiff.similar()) {
// If it isn't similar, dump the difference.
assertEquals(expectedMetadata, actualMetadata);
}
}
use of org.custommonkey.xmlunit.DetailedDiff in project cerberus-source by cerberustesting.
the class XmlUtilTest method testToString.
@Test
public void testToString() throws XmlUtilException, SAXException, IOException {
Document doc = XmlUtil.newDocument();
Element expected = doc.createElement("root");
doc.appendChild(expected);
Element child = doc.createElement("child");
expected.appendChild(child);
String actual = XmlUtil.toString(expected);
DetailedDiff diff = new DetailedDiff(XMLUnit.compareXML("<root><child/></root>", actual));
Assert.assertTrue(diff.toString(), diff.similar());
}
use of org.custommonkey.xmlunit.DetailedDiff in project cerberus-source by cerberustesting.
the class XmlUtilTest method testFromString.
@Test
public void testFromString() throws XmlUtilException {
Document expected = XmlUtil.newDocument();
Element element = expected.createElement("root");
expected.appendChild(element);
Element child = expected.createElement("child");
element.appendChild(child);
Document actual = XmlUtil.fromString("<root><child/></root>");
DetailedDiff diff = new DetailedDiff(XMLUnit.compareXML(expected, actual));
Assert.assertTrue(diff.toString(), diff.similar());
}
use of org.custommonkey.xmlunit.DetailedDiff in project cerberus-source by cerberustesting.
the class DifferencesTest method testMkStringWhenExistingDifference.
@Test
public void testMkStringWhenExistingDifference() throws XmlUtilException, SAXException, IOException {
differences.addDifference(new Difference("diff1"));
differences.addDifference(new Difference("diff2"));
String actual = differences.mkString();
Document doc = XmlUtil.newDocument();
Element root = doc.createElement(Differences.DIFFERENCES_NODE);
doc.appendChild(root);
Element diff1 = doc.createElement(Differences.DIFFERENCE_NODE);
diff1.appendChild(doc.createTextNode("diff1"));
root.appendChild(diff1);
Element diff2 = doc.createElement(Differences.DIFFERENCE_NODE);
diff2.appendChild(doc.createTextNode("diff2"));
root.appendChild(diff2);
String expected = XmlUtil.toString(doc);
DetailedDiff result = new DetailedDiff(XMLUnit.compareXML(expected, actual));
Assert.assertTrue("Differences can be correctly transforms as String", result.similar());
}
use of org.custommonkey.xmlunit.DetailedDiff in project sirix by sirixdb.
the class FMSETest method test.
/**
* Test a folder of XML files.
*
* @param FOLDER path string
* @throws Exception if any exception occurs
*/
private void test(final String FOLDER) throws Exception {
Database database = TestHelper.getDatabase(PATHS.PATH1.getFile());
ResourceManager resource = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
final Path folder = Paths.get(FOLDER);
final List<Path> list = Files.list(folder).filter(path -> path.getFileName().endsWith(".xml")).collect(toList());
// Sort files list according to file names.
list.sort((first, second) -> {
final String firstName = first.getFileName().toString().substring(0, first.getFileName().toString().indexOf('.'));
final String secondName = second.getFileName().toString().substring(0, second.getFileName().toString().indexOf('.'));
if (Integer.parseInt(firstName) < Integer.parseInt(secondName)) {
return -1;
} else if (Integer.parseInt(firstName) > Integer.parseInt(secondName)) {
return +1;
} else {
return 0;
}
});
boolean first = true;
// Shredder files.
for (final Path file : list) {
if (file.getFileName().endsWith(".xml")) {
if (first) {
first = false;
try (final XdmNodeWriteTrx wtx = resource.beginNodeWriteTrx()) {
final XMLShredder shredder = new XMLShredder.Builder(wtx, XMLShredder.createFileReader(file), Insert.ASFIRSTCHILD).commitAfterwards().build();
shredder.call();
}
} else {
FMSEImport.main(new String[] { PATHS.PATH1.getFile().toAbsolutePath().toString(), file.toAbsolutePath().toString() });
}
resource.close();
resource = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
final OutputStream out = new ByteArrayOutputStream();
final XMLSerializer serializer = new XMLSerializerBuilder(resource, out).build();
serializer.call();
final StringBuilder sBuilder = TestHelper.readFile(file, false);
final Diff diff = new Diff(sBuilder.toString(), out.toString());
final DetailedDiff detDiff = new DetailedDiff(diff);
@SuppressWarnings("unchecked") final List<Difference> differences = detDiff.getAllDifferences();
for (final Difference difference : differences) {
System.err.println("***********************");
System.err.println(difference);
System.err.println("***********************");
}
assertTrue("pieces of XML are similar " + diff, diff.similar());
assertTrue("but are they identical? " + diff, diff.identical());
}
}
database.close();
}
Aggregations