Commit 04ea6a99 authored by R.W.Majeed's avatar R.W.Majeed
Browse files

made input/output file comparable

parent f6f0cb5d
......@@ -25,13 +25,13 @@
<meta>
<!-- Zeitpunkt, an dem der Export erstellt wurde bzw. Datenstand -->
<etl-strategy>replace-visit</etl-strategy>
<source timestamp="2015-04-21T08:58:00" id="test"/>
<source timestamp="2015-04-21T06:58:00Z" id="test"/>
<!-- weitere metadaten nötig? wertebereich, datentypen, ontologie, ...? -->
</meta>
<patient id="XX12345">
<patient id="XX12345"><!--
<surname>Dampf</surname>
<given-name>A</given-name>
<given-name>A</given-name> -->
<gender>Female</gender>
<birthdate>2001-01-01</birthdate>
<deathdate>2020</deathdate>
......@@ -39,8 +39,8 @@
<start>2014-01-01T10:30:00</start>
<end>2014-01-05T10:30:00</end>
<location>Zuhause</location>
<!-- TODO inpatient/outpatient -->
<provider>xxxa</provider>
<!-- TODO inpatient/outpatient
<provider>xxxa</provider>-->
<facts>
<fact concept="T:date:secs" start="2014-09-07T10:40:03"/>
<fact concept="T:date:mins" start="2014-09-07T10:40"/>
......
package de.sekmi.histream.io;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.time.Instant;
import java.util.stream.StreamSupport;
......@@ -14,6 +15,7 @@ import javax.xml.stream.XMLStreamException;
import org.junit.Assert;
import org.junit.Test;
import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.Document;
import de.sekmi.histream.ObservationSupplier;
......@@ -49,10 +51,21 @@ public class TestXMLWriter {
JAXB.marshal(meta, System.out);
}
private void normalizeDocument(Document dom){
DOMConfiguration c = dom.getDomConfig();
// XXX doesn't work
c.setParameter("cdata-sections", "false");
c.setParameter("element-content-whitespace", "false");
c.setParameter("comments", "false");
c.setParameter("normalize-characters", "true");
dom.normalizeDocument();
}
@Test
public void testReadWriteIdenticalXML() throws Exception{
if( true )return;
// TODO include XSD for validating parser
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(true);
dbf.setNamespaceAware(true);
dbf.setCoalescing(true);
dbf.setIgnoringElementContentWhitespace(true);
......@@ -61,10 +74,24 @@ public class TestXMLWriter {
Document doc1 = db.parse(new File("examples/dwh-jaxb.xml"));
doc1.normalizeDocument();
//normalizeDocument(doc1);
File dest = File.createTempFile("xmlwriter", ".xml");
FileOutputStream out = new FileOutputStream(dest);
FileObservationProviderTest t = new FileObservationProviderTest();
t.initializeObservationFactory();
ObservationSupplier s = t.getExampleSupplier();
XMLWriter w = new XMLWriter(out);
Meta.transfer(s, w);
StreamSupport.stream(AbstractObservationParser.nonNullSpliterator(s), false).forEach(w);
w.close();
out.close();
// TODO compare with generated DOM
Document doc2 = db.parse(new File("examples/dwh-jaxb.xml"));
doc2.normalizeDocument();
// compare with generated DOM
Document doc2 = db.parse(dest);
dest.delete();
doc2.normalizeDocument();//normalizeDocument(doc2);
Assert.assertTrue(doc1.isEqualNode(doc2));
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment