Commit 0c2a7fda authored by R.W.Majeed's avatar R.W.Majeed
Browse files

verbose assertations for missing files from art-decor resources

parent 01e4514d
package org.aktin.cda;
import java.io.IOException;
import java.net.URL;
import javax.xml.XMLConstants;
import javax.xml.transform.Source;
......@@ -8,6 +9,7 @@ import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.junit.Assert;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
......@@ -17,7 +19,9 @@ public class SchemaValidator {
public SchemaValidator() throws SAXException{
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
this.schema = sf.newSchema(getClass().getResource("/schemas/CDA.xsd"));
URL url = getClass().getResource("/schemas/CDA.xsd");
Assert.assertNotNull("CDA XSD resource not found from external release", url);
this.schema = sf.newSchema(url);
}
public static class ErrorForwarder implements ErrorHandler{
......
......@@ -2,6 +2,7 @@ package org.aktin.cda;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
......@@ -47,11 +48,18 @@ public class TestCDAParser {
}
}
*/
private final InputStream openExampleDocument(String source) throws IOException {
URL url = getClass().getResource(source);
Assert.assertNotNull("CDA example document not found in external release: "+url, url);
System.out.println(url);
return url.openStream();
}
@Test
public void extractDocumentIDs() throws TransformerException, IOException, XPathExpressionException, ParserConfigurationException, SAXException{
CDAParser parser = new CDAParser();
try( InputStream in = getClass().getResourceAsStream(exampleDocuments[0]) ){
try( InputStream in = openExampleDocument(exampleDocuments[0]) ){
Assert.assertTrue(in.available() > 0);
Document cda = parser.buildDOM(new StreamSource(in));
String docId = parser.extractDocumentId(cda);
......@@ -64,7 +72,7 @@ public class TestCDAParser {
@Test
public void extractPatientID() throws TransformerException, IOException, XPathExpressionException, ParserConfigurationException, SAXException{
CDAParser parser = new CDAParser();
try( InputStream in = getClass().getResourceAsStream(exampleDocuments[0]) ){
try( InputStream in = openExampleDocument(exampleDocuments[0]) ){
Assert.assertTrue(in.available() > 0);
Document cda = parser.buildDOM(new StreamSource(in));
String[] pat = parser.extractPatientId(cda);
......
Markdown is supported
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