commit c4d1dd6f3296f6e5520113d6d5e88c7e74c54551
parent 80901383f59b6e7e64d67ab34f4abf2edd330b4b
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Sun, 15 Sep 2019 20:05:40 +0200
Local test of XML validation.
Diffstat:
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/main/java/tech/libeufin/XMLManagement.java b/src/main/java/tech/libeufin/XMLManagement.java
@@ -41,10 +41,16 @@ public class XMLManagement {
}
}
+ /**
+ *
+ * @param xmlDoc the XML document to validate
+ * @return true when validation passes, false otherwise
+ */
public boolean validate(Source xmlDoc){
try{
this.validator.validate(xmlDoc);
} catch (SAXException e) {
+ System.out.println("Validation did not pass " + e);
return false;
} catch (IOException e) {
System.out.println("Could not pass XML to validator.");
diff --git a/src/test/java/XMLManagementTest.java b/src/test/java/XMLManagementTest.java
@@ -1,6 +1,8 @@
import org.junit.Test;
import tech.libeufin.XMLManagement;
-
+import java.io.File;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
import static org.junit.Assert.*;
public class XMLManagementTest {
@@ -8,5 +10,8 @@ public class XMLManagementTest {
@Test
public void XMLManagementTest(){
XMLManagement xm = new XMLManagement();
+ ClassLoader classLoader = this.getClass().getClassLoader();
+ Source ebics_hev_sample = new StreamSource(classLoader.getResourceAsStream("ebics_hev.xsd"));
+ assertTrue(xm.validate(ebics_hev_sample));
}
}