fix bug doing non-namespaced XML comparison
This commit is contained in:
parent
21128fb670
commit
73fa4fb242
|
@ -171,7 +171,7 @@ public class TestingUtilities extends BaseTestingUtilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String compareElements(String path, Element e1, Element e2) {
|
private static String compareElements(String path, Element e1, Element e2) {
|
||||||
if (!e1.getNamespaceURI().equals(e2.getNamespaceURI()))
|
if (!namespacesMatch(e1.getNamespaceURI(), e2.getNamespaceURI()))
|
||||||
return "Namespaces differ at " + path + ": " + e1.getNamespaceURI() + "/" + e2.getNamespaceURI();
|
return "Namespaces differ at " + path + ": " + e1.getNamespaceURI() + "/" + e2.getNamespaceURI();
|
||||||
if (!e1.getLocalName().equals(e2.getLocalName()))
|
if (!e1.getLocalName().equals(e2.getLocalName()))
|
||||||
return "Names differ at " + path + ": " + e1.getLocalName() + "/" + e2.getLocalName();
|
return "Names differ at " + path + ": " + e1.getLocalName() + "/" + e2.getLocalName();
|
||||||
|
@ -209,6 +209,10 @@ public class TestingUtilities extends BaseTestingUtilities {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean namespacesMatch(String ns1, String ns2) {
|
||||||
|
return ns1 == null ? ns2 == null : ns1.equals(ns2);
|
||||||
|
}
|
||||||
|
|
||||||
private static Object normalise(String text) {
|
private static Object normalise(String text) {
|
||||||
String result = text.trim().replace('\r', ' ').replace('\n', ' ').replace('\t', ' ');
|
String result = text.trim().replace('\r', ' ').replace('\n', ' ').replace('\t', ' ');
|
||||||
while (result.contains(" "))
|
while (result.contains(" "))
|
||||||
|
|
|
@ -56,7 +56,6 @@ public class NarrativeGenerationTests {
|
||||||
public Base parseType(String xml, String type) throws FHIRFormatError, IOException, FHIRException {
|
public Base parseType(String xml, String type) throws FHIRFormatError, IOException, FHIRException {
|
||||||
return new org.hl7.fhir.r5.formats.XmlParser().parseType(xml, type);
|
return new org.hl7.fhir.r5.formats.XmlParser().parseType(xml, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String WINDOWS = "WINDOWS";
|
public static final String WINDOWS = "WINDOWS";
|
||||||
|
@ -143,9 +142,12 @@ public class NarrativeGenerationTests {
|
||||||
XhtmlNode x = RendererFactory.factory(source, rc).build(source);
|
XhtmlNode x = RendererFactory.factory(source, rc).build(source);
|
||||||
String target = TextFile.streamToString(TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + ".html"));
|
String target = TextFile.streamToString(TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + ".html"));
|
||||||
String output = HEADER+new XhtmlComposer(true, true).compose(x)+FOOTER;
|
String output = HEADER+new XhtmlComposer(true, true).compose(x)+FOOTER;
|
||||||
TextFile.stringToFile(target, TestingUtilities.tempFile("narrative", test.getId() + ".target.html"));
|
String tfn = TestingUtilities.tempFile("narrative", test.getId() + ".target.html");
|
||||||
TextFile.stringToFile(output, TestingUtilities.tempFile("narrative", test.getId() + ".output.html"));
|
String ofn = TestingUtilities.tempFile("narrative", test.getId() + ".output.html");
|
||||||
Assertions.assertTrue(output.equals(target), "Output does not match expected");
|
TextFile.stringToFile(target, tfn);
|
||||||
|
TextFile.stringToFile(output, ofn);
|
||||||
|
String msg = TestingUtilities.checkXMLIsSame(ofn, tfn);
|
||||||
|
Assertions.assertTrue(msg == null, "Output does not match expected: "+msg);
|
||||||
|
|
||||||
if (test.isMeta()) {
|
if (test.isMeta()) {
|
||||||
org.hl7.fhir.r5.elementmodel.Element e = Manager.parseSingle(context, TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + ".xml"), FhirFormat.XML);
|
org.hl7.fhir.r5.elementmodel.Element e = Manager.parseSingle(context, TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + ".xml"), FhirFormat.XML);
|
||||||
|
@ -153,8 +155,10 @@ public class NarrativeGenerationTests {
|
||||||
|
|
||||||
target = TextFile.streamToString(TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + "-meta.html"));
|
target = TextFile.streamToString(TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + "-meta.html"));
|
||||||
output = HEADER+new XhtmlComposer(true, true).compose(x)+FOOTER;
|
output = HEADER+new XhtmlComposer(true, true).compose(x)+FOOTER;
|
||||||
TextFile.stringToFile(output, TestingUtilities.tempFile("narrative", test.getId() + "-meta.output.html"));
|
ofn = TestingUtilities.tempFile("narrative", test.getId() + "-meta.output.html");
|
||||||
Assertions.assertTrue(output.equals(target), "Output does not match expected (meta)");
|
TextFile.stringToFile(output, ofn);
|
||||||
|
msg = TestingUtilities.checkXMLIsSame(ofn, tfn);
|
||||||
|
Assertions.assertTrue(msg == null, "Meta output does not match expected: "+msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ class UtilitiesTest {
|
||||||
public static final String WIN_JAVA_HOME = System.getenv("JAVA_HOME") + "\\";
|
public static final String WIN_JAVA_HOME = System.getenv("JAVA_HOME") + "\\";
|
||||||
|
|
||||||
public static final String OSX_USER_DIR = System.getProperty("user.home") + "/";
|
public static final String OSX_USER_DIR = System.getProperty("user.home") + "/";
|
||||||
public static final String OSX_JAVA_HOME = Paths.get(System.getenv("JAVA_HOME")).normalize().toString() + "/";
|
public static final String OSX_JAVA_HOME = System.getenv("JAVA_HOME") == null ? null : Paths.get(System.getenv("JAVA_HOME")).normalize().toString() + "/";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Test Utilities.path maps temp directory correctly")
|
@DisplayName("Test Utilities.path maps temp directory correctly")
|
||||||
|
|
Loading…
Reference in New Issue