Loading tools/XmlDiff/.classpath +3 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="src" path="tests"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> <classpathentry kind="lib" path="lib/xmlunit-1.5.jar" sourcepath="lib/xmlunit-1.5-src.zip"/> <classpathentry kind="output" path="bin"/> </classpath> tools/XmlDiff/src/org/etsi/mts/ttcn/part9/xmldiff/XmlDiff.java +24 −3 Original line number Diff line number Diff line Loading @@ -39,7 +39,11 @@ public class XmlDiff { * */ public XmlDiff(String referenceXmlFile, String[] xsdFileNames, String[] xsdSearchPath) { this.referenceXmlFile = new File(referenceXmlFile); this(new File(referenceXmlFile), xsdFileNames, xsdSearchPath); } public XmlDiff(File file, Object xsdFileNames, Object xsdSearchPath) { this.referenceXmlFile = file; if (!this.referenceXmlFile.exists()) { throw new IllegalArgumentException("No such file: " + this.referenceXmlFile.getAbsolutePath()); } Loading @@ -63,9 +67,26 @@ public class XmlDiff { throw new XmlDiffError(e); } Reader rd = new InputStreamReader(stream, StandardCharsets.UTF_8); StringReader inputReader = new StringReader(input); return diff(rd, inputReader, diffDetails); } public boolean diff(Reader input, StringBuilder diffDetails) throws XmlDiffError { InputStream stream; try { stream = new FileInputStream(referenceXmlFile); } catch (FileNotFoundException e) { throw new XmlDiffError(e); } Reader rd = new InputStreamReader(stream, StandardCharsets.UTF_8); return diff(rd, input, diffDetails); } private boolean diff(Reader expected, Reader actual, StringBuilder diffDetails) throws XmlDiffError { Diff differ = null; try { differ = new Diff(rd, new StringReader(input)); differ = new Diff(expected, actual); } catch (SAXException e) { throw new XmlDiffError("Failed to parse XML", e); } catch (IOException e) { Loading tools/XmlDiff/tests/org/etsi/mts/ttcn/part9/xmldiff/TestDiff2.java 0 → 100644 +89 −0 Original line number Diff line number Diff line package org.etsi.mts.ttcn.part9.xmldiff; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.Reader; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; public class TestDiff2 { public static String FILE_base = "Pos_070401_AttributeElementDefinition_001_01_base.xml"; public static String FILE_whitespace = "Pos_070401_AttributeElementDefinition_001_02_whitespace.xml"; public static String FILE_comment = "Pos_070401_AttributeElementDefinition_001_03_comment.xml"; public static String FILE_nmsp_prefix = "Pos_070401_AttributeElementDefinition_001_04_nmsp_prefix.xml"; public static String FILE_attr_order = "Pos_070401_AttributeElementDefinition_001_05_attr_order.xml"; public static String FILE_no_nmsp_prefix = "Pos_070401_AttributeElementDefinition_001_06_no_nmsp_prefix.xml"; public static String FILE_escape = "Pos_070401_AttributeElementDefinition_001_07_escape.xml"; public static String FILE_xsd = "Pos_070401_AttributeElementDefinition_001.xsd"; private File root; private XmlDiff differ; private StringBuilder errors; private Reader actual; @Before public void setUp() throws IOException { root = new File("xml/002"); differ = new XmlDiff(new File(root, FILE_base), null, null); errors = new StringBuilder(); } @Test public void test_whitespace() throws IOException, XmlDiffError { actual = new FileReader(new File(root, FILE_whitespace)); boolean v = differ.diff(actual, errors); assertEquals("", errors.toString()); assertTrue(v); } @Test public void test_comment() throws IOException, XmlDiffError { actual = new FileReader(new File(root, FILE_comment)); boolean v = differ.diff(actual, errors); assertEquals("", errors.toString()); assertTrue(v); } @Test public void test_nmsp_prefix() throws IOException, XmlDiffError { actual = new FileReader(new File(root, FILE_nmsp_prefix)); boolean v = differ.diff(actual, errors); assertEquals("", errors.toString()); assertTrue(v); } @Test public void test_attr_order() throws IOException, XmlDiffError { actual = new FileReader(new File(root, FILE_attr_order)); boolean v = differ.diff(actual, errors); assertEquals("", errors.toString()); assertTrue(v); } @Test public void test_no_nmsp_prefix() throws IOException, XmlDiffError { actual = new FileReader(new File(root, FILE_no_nmsp_prefix)); boolean v = differ.diff(actual, errors); assertEquals("", errors.toString()); assertTrue(v); } @Test public void test_escape() throws IOException, XmlDiffError { actual = new FileReader(new File(root, FILE_escape)); boolean v = differ.diff(actual, errors); assertEquals("", errors.toString()); assertTrue(v); } } tools/XmlDiff/tests/org/etsi/mts/ttcn/part9/xmldiff/TestDiff3.java 0 → 100644 +49 −0 Original line number Diff line number Diff line package org.etsi.mts.ttcn.part9.xmldiff; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.Reader; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; public class TestDiff3 { public static String FILE_base = "Pos_07060101_extending_simple_content_001.xml"; public static String FILE_ttwb = "generated_ttwb.xml"; public static String FILE_tc = "generated_tc.xml"; private File root; private XmlDiff differ; private StringBuilder errors; private Reader actual; @Before public void setUp() throws IOException { root = new File("xml/003"); differ = new XmlDiff(new File(root, FILE_base), null, null); errors = new StringBuilder(); } @Test public void test_ttwb() throws IOException, XmlDiffError { actual = new FileReader(new File(root, FILE_ttwb)); boolean v = differ.diff(actual, errors); assertEquals("", errors.toString()); assertTrue(v); } @Test public void test_tc() throws IOException, XmlDiffError { actual = new FileReader(new File(root, FILE_tc)); boolean v = differ.diff(actual, errors); assertFalse(v); assertTrue(errors.toString().contains("attribute")); } } tools/XmlDiff/tests/org/etsi/mts/ttcn/part9/xmldiff/TestSimpleDiff.java 0 → 100644 +30 −0 Original line number Diff line number Diff line package org.etsi.mts.ttcn.part9.xmldiff; import static org.junit.Assert.*; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import org.junit.Test; public class TestSimpleDiff { public static final String PREFIX = "xml/001"; public static final String REFERENCE_XML = PREFIX + "/books.xml"; @Test public void pos_001_nowhitespaces() throws IOException, XmlDiffError { XmlDiff differ = new XmlDiff(REFERENCE_XML, null, null); String textXml = "books_nowhitespaces.xml"; String text = new String(Files.readAllBytes(Paths.get(PREFIX, textXml)), StandardCharsets.UTF_8); StringBuilder error = new StringBuilder(); boolean v = differ.diff(text, error); assertEquals("", error.toString()); assertTrue("The XML files must be considered similar", v); } } Loading
tools/XmlDiff/.classpath +3 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="src" path="tests"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> <classpathentry kind="lib" path="lib/xmlunit-1.5.jar" sourcepath="lib/xmlunit-1.5-src.zip"/> <classpathentry kind="output" path="bin"/> </classpath>
tools/XmlDiff/src/org/etsi/mts/ttcn/part9/xmldiff/XmlDiff.java +24 −3 Original line number Diff line number Diff line Loading @@ -39,7 +39,11 @@ public class XmlDiff { * */ public XmlDiff(String referenceXmlFile, String[] xsdFileNames, String[] xsdSearchPath) { this.referenceXmlFile = new File(referenceXmlFile); this(new File(referenceXmlFile), xsdFileNames, xsdSearchPath); } public XmlDiff(File file, Object xsdFileNames, Object xsdSearchPath) { this.referenceXmlFile = file; if (!this.referenceXmlFile.exists()) { throw new IllegalArgumentException("No such file: " + this.referenceXmlFile.getAbsolutePath()); } Loading @@ -63,9 +67,26 @@ public class XmlDiff { throw new XmlDiffError(e); } Reader rd = new InputStreamReader(stream, StandardCharsets.UTF_8); StringReader inputReader = new StringReader(input); return diff(rd, inputReader, diffDetails); } public boolean diff(Reader input, StringBuilder diffDetails) throws XmlDiffError { InputStream stream; try { stream = new FileInputStream(referenceXmlFile); } catch (FileNotFoundException e) { throw new XmlDiffError(e); } Reader rd = new InputStreamReader(stream, StandardCharsets.UTF_8); return diff(rd, input, diffDetails); } private boolean diff(Reader expected, Reader actual, StringBuilder diffDetails) throws XmlDiffError { Diff differ = null; try { differ = new Diff(rd, new StringReader(input)); differ = new Diff(expected, actual); } catch (SAXException e) { throw new XmlDiffError("Failed to parse XML", e); } catch (IOException e) { Loading
tools/XmlDiff/tests/org/etsi/mts/ttcn/part9/xmldiff/TestDiff2.java 0 → 100644 +89 −0 Original line number Diff line number Diff line package org.etsi.mts.ttcn.part9.xmldiff; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.Reader; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; public class TestDiff2 { public static String FILE_base = "Pos_070401_AttributeElementDefinition_001_01_base.xml"; public static String FILE_whitespace = "Pos_070401_AttributeElementDefinition_001_02_whitespace.xml"; public static String FILE_comment = "Pos_070401_AttributeElementDefinition_001_03_comment.xml"; public static String FILE_nmsp_prefix = "Pos_070401_AttributeElementDefinition_001_04_nmsp_prefix.xml"; public static String FILE_attr_order = "Pos_070401_AttributeElementDefinition_001_05_attr_order.xml"; public static String FILE_no_nmsp_prefix = "Pos_070401_AttributeElementDefinition_001_06_no_nmsp_prefix.xml"; public static String FILE_escape = "Pos_070401_AttributeElementDefinition_001_07_escape.xml"; public static String FILE_xsd = "Pos_070401_AttributeElementDefinition_001.xsd"; private File root; private XmlDiff differ; private StringBuilder errors; private Reader actual; @Before public void setUp() throws IOException { root = new File("xml/002"); differ = new XmlDiff(new File(root, FILE_base), null, null); errors = new StringBuilder(); } @Test public void test_whitespace() throws IOException, XmlDiffError { actual = new FileReader(new File(root, FILE_whitespace)); boolean v = differ.diff(actual, errors); assertEquals("", errors.toString()); assertTrue(v); } @Test public void test_comment() throws IOException, XmlDiffError { actual = new FileReader(new File(root, FILE_comment)); boolean v = differ.diff(actual, errors); assertEquals("", errors.toString()); assertTrue(v); } @Test public void test_nmsp_prefix() throws IOException, XmlDiffError { actual = new FileReader(new File(root, FILE_nmsp_prefix)); boolean v = differ.diff(actual, errors); assertEquals("", errors.toString()); assertTrue(v); } @Test public void test_attr_order() throws IOException, XmlDiffError { actual = new FileReader(new File(root, FILE_attr_order)); boolean v = differ.diff(actual, errors); assertEquals("", errors.toString()); assertTrue(v); } @Test public void test_no_nmsp_prefix() throws IOException, XmlDiffError { actual = new FileReader(new File(root, FILE_no_nmsp_prefix)); boolean v = differ.diff(actual, errors); assertEquals("", errors.toString()); assertTrue(v); } @Test public void test_escape() throws IOException, XmlDiffError { actual = new FileReader(new File(root, FILE_escape)); boolean v = differ.diff(actual, errors); assertEquals("", errors.toString()); assertTrue(v); } }
tools/XmlDiff/tests/org/etsi/mts/ttcn/part9/xmldiff/TestDiff3.java 0 → 100644 +49 −0 Original line number Diff line number Diff line package org.etsi.mts.ttcn.part9.xmldiff; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.Reader; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; public class TestDiff3 { public static String FILE_base = "Pos_07060101_extending_simple_content_001.xml"; public static String FILE_ttwb = "generated_ttwb.xml"; public static String FILE_tc = "generated_tc.xml"; private File root; private XmlDiff differ; private StringBuilder errors; private Reader actual; @Before public void setUp() throws IOException { root = new File("xml/003"); differ = new XmlDiff(new File(root, FILE_base), null, null); errors = new StringBuilder(); } @Test public void test_ttwb() throws IOException, XmlDiffError { actual = new FileReader(new File(root, FILE_ttwb)); boolean v = differ.diff(actual, errors); assertEquals("", errors.toString()); assertTrue(v); } @Test public void test_tc() throws IOException, XmlDiffError { actual = new FileReader(new File(root, FILE_tc)); boolean v = differ.diff(actual, errors); assertFalse(v); assertTrue(errors.toString().contains("attribute")); } }
tools/XmlDiff/tests/org/etsi/mts/ttcn/part9/xmldiff/TestSimpleDiff.java 0 → 100644 +30 −0 Original line number Diff line number Diff line package org.etsi.mts.ttcn.part9.xmldiff; import static org.junit.Assert.*; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import org.junit.Test; public class TestSimpleDiff { public static final String PREFIX = "xml/001"; public static final String REFERENCE_XML = PREFIX + "/books.xml"; @Test public void pos_001_nowhitespaces() throws IOException, XmlDiffError { XmlDiff differ = new XmlDiff(REFERENCE_XML, null, null); String textXml = "books_nowhitespaces.xml"; String text = new String(Files.readAllBytes(Paths.get(PREFIX, textXml)), StandardCharsets.UTF_8); StringBuilder error = new StringBuilder(); boolean v = differ.diff(text, error); assertEquals("", error.toString()); assertTrue("The XML files must be considered similar", v); } }