use XMLUnit
This commit is contained in:
6
pom.xml
6
pom.xml
@@ -88,6 +88,12 @@
|
|||||||
<version>5.0.4</version>
|
<version>5.0.4</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.xmlunit</groupId>
|
||||||
|
<artifactId>xmlunit-core</artifactId>
|
||||||
|
<version>2.6.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<!-- For Toecount -->
|
<!-- For Toecount -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sanityinc</groupId>
|
<groupId>com.sanityinc</groupId>
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import org.junit.BeforeClass;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
|
import org.xmlunit.builder.DiffBuilder;
|
||||||
|
import org.xmlunit.diff.Diff;
|
||||||
|
|
||||||
import javax.xml.transform.TransformerException;
|
import javax.xml.transform.TransformerException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -28,10 +30,11 @@ import java.io.IOException;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Every ZUGFeRD 1.0 XML file from <code>src/test/resources/migration/input</code>
|
* Every ZUGFeRD 1.0 XML file from <code>src/test/resources/migration/input</code>
|
||||||
@@ -69,9 +72,8 @@ public class VersionMigrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void addFilesFromFolder(final File folder, Collection<Object[]> testSuiteData) {
|
private static void addFilesFromFolder(final File folder, Collection<Object[]> testSuiteData) {
|
||||||
String filePath = null;
|
|
||||||
for (final File fileEntry : folder.listFiles()) {
|
for (final File fileEntry : folder.listFiles()) {
|
||||||
filePath = fileEntry.getAbsolutePath();
|
String filePath = fileEntry.getAbsolutePath();
|
||||||
if (fileEntry.isDirectory()) {
|
if (fileEntry.isDirectory()) {
|
||||||
LOG.log(Level.INFO, "*** testDirectory:{0}", filePath);
|
LOG.log(Level.INFO, "*** testDirectory:{0}", filePath);
|
||||||
addFilesFromFolder(fileEntry, testSuiteData);
|
addFilesFromFolder(fileEntry, testSuiteData);
|
||||||
@@ -100,20 +102,8 @@ public class VersionMigrationTest {
|
|||||||
// we need to save the string and reload it otherwise two bytes are missing (likely EOF related)
|
// we need to save the string and reload it otherwise two bytes are missing (likely EOF related)
|
||||||
String outXML = ResourceUtilities.readFile(StandardCharsets.UTF_8, OUTPUT_DIR + newName);
|
String outXML = ResourceUtilities.readFile(StandardCharsets.UTF_8, OUTPUT_DIR + newName);
|
||||||
String refXML = ResourceUtilities.readFile(StandardCharsets.UTF_8, REFERENCE_DIR + newName);
|
String refXML = ResourceUtilities.readFile(StandardCharsets.UTF_8, REFERENCE_DIR + newName);
|
||||||
int t = outXML.length();
|
Diff myDiff = DiffBuilder.compare(refXML).withTest(outXML).checkForSimilar().ignoreComments().ignoreWhitespace().build();
|
||||||
int r = refXML.length();
|
assertFalse(myDiff.toString(), myDiff.hasDifferences());
|
||||||
if (t != r || !(outXML.equals(refXML))) {
|
|
||||||
LOG.info("There are differences between:"
|
|
||||||
+ "\nZUGFeRD 2.0 Test Output @ " + OUTPUT_DIR + newName
|
|
||||||
+ "\nZUGFeRD 2.0 Test Reference @ " + REFERENCE_DIR + newName);
|
|
||||||
LOG.info("\n\nFile sizes:\n "
|
|
||||||
+ "\nZUGFeRD 2.0 Test Output character count: " + t
|
|
||||||
+ "\nZUGFeRD 2.0 Test Refer. character count: " + r);
|
|
||||||
findLineDiffs(outXML, refXML);
|
|
||||||
Assert.fail("Version update failed, as test result and reference are different!");
|
|
||||||
} else {
|
|
||||||
LOG.log(Level.INFO, "\n*** Tested successfull migration from ZUGFeRD 1.0 to 2.0: '" + newName + "'' ***\n", OUTPUT_DIR);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
LOG.log(Level.INFO, "\n*** Migrated from ZUGFeRD 1.0 to 2.0 invoice: '" + newName + "'' ***\n", OUTPUT_DIR);
|
LOG.log(Level.INFO, "\n*** Migrated from ZUGFeRD 1.0 to 2.0 invoice: '" + newName + "'' ***\n", OUTPUT_DIR);
|
||||||
}
|
}
|
||||||
@@ -123,22 +113,4 @@ public class VersionMigrationTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void findLineDiffs(String outXML, String refXML) {
|
|
||||||
Scanner outScanner = new Scanner(outXML);
|
|
||||||
Scanner refScanner = new Scanner(refXML);
|
|
||||||
String outLine = null;
|
|
||||||
String refLine = null;
|
|
||||||
while (outScanner.hasNextLine() && refScanner.hasNextLine()) {
|
|
||||||
outLine = outScanner.nextLine();
|
|
||||||
refLine = refScanner.nextLine();
|
|
||||||
if (!outLine.equals(refLine)) {
|
|
||||||
LOG.info("First line difference between reference and output file:" +
|
|
||||||
"\nRefLine: " + refLine +
|
|
||||||
"\nOutLine: " + outLine + "\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
refScanner.close();
|
|
||||||
outScanner.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,9 @@
|
|||||||
<rsm:CrossIndustryInvoice xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100"
|
<rsm:CrossIndustryInvoice xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100"
|
||||||
xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100"
|
xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100"
|
||||||
xmlns:qdt="urn:un:unece:uncefact:data:Standard:QualifiedDataType:100"
|
xmlns:qdt="urn:un:unece:uncefact:data:Standard:QualifiedDataType:100"
|
||||||
xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100"><!--
|
xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100">
|
||||||
Migrated by Mustangproject XSLT
|
<!--Migrated by Mustangproject XSLT-->
|
||||||
--><rsm:ExchangedDocumentContext>
|
<rsm:ExchangedDocumentContext>
|
||||||
<ram:TestIndicator>
|
<ram:TestIndicator>
|
||||||
<udt:Indicator>false</udt:Indicator>
|
<udt:Indicator>false</udt:Indicator>
|
||||||
</ram:TestIndicator>
|
</ram:TestIndicator>
|
||||||
|
|||||||
Reference in New Issue
Block a user