aligned schema API with that of XSL transformation.
[utils] / support / general / src / test / java / org / wamblee / xml / XMLSchemaTest.java
index 4881824d3b1cf1008dd45bdfb44bb178fd37f670..ab4603c8ec9c74f71d24fbe2c0c727526d39cbd1 100644 (file)
@@ -34,14 +34,18 @@ import static org.wamblee.xml.XMLDocument.*;
 
 public class XMLSchemaTest {
     
+    private URI getResourceUri(String aResource) throws URISyntaxException { 
+        return getClass().getResource(aResource).toURI();
+    }
+    
     private InputStream getResource(String aResource) { 
         return getClass().getResourceAsStream(aResource);
     }
     
     @Test
-    public void testReadAndValidateOk() throws Exception { 
+    public void testReadAndValidateOkUseUri() throws Exception { 
         
-        XMLDocument xmldoc = xmldocument("test.xml", getResource("test.xml")).validate("test.xsd", getResource("test.xsd"), null);
+        XMLDocument xmldoc = xmldocument("test.xml", getResource("test.xml")).validate(getResourceUri("test.xsd"));
         Document doc = xmldoc.getDocument();
         Element element = doc.getDocumentElement();
         assertEquals("http://wamblee.org/test", element.getNamespaceURI());
@@ -52,8 +56,31 @@ public class XMLSchemaTest {
         XmlUtils.assertEquals("", doc, doc2);
     }
     
+    @Test
+    public void testReadAndValidateOkUseClasspath() throws Exception { 
+        
+        XMLDocument xmldoc = xmldocument("test.xml", getResource("test.xml")).validate(
+            "test.xsd", new ClasspathUriResolver("org/wamblee/xml"));
+        Document doc = xmldoc.getDocument();
+        Element element = doc.getDocumentElement();
+        assertEquals("http://wamblee.org/test", element.getNamespaceURI());
+        
+        String val = xmldoc.print(false);
+        // parse the written document
+        Document doc2 = xmldocument("input.xml", new ByteArrayInputStream(val.getBytes())).getDocument();
+        XmlUtils.assertEquals("", doc, doc2);
+    }
+    
+    @Test(expected = XMLException.class)
+    public void testSchemaNotFoundUseClasspath() throws Exception { 
+        
+        XMLDocument xmldoc = xmldocument("test.xml", getResource("test.xml")).validate(
+            "test.xsd.unknown", new ClasspathUriResolver("org/wamblee/xml"));
+    }
+    
+    
     @Test(expected = XMLException.class)
     public void testReadAndValidateNotOk() throws Exception {
-        XMLDocument xmldoc = xmldocument("testInvalid.xml", getResource("testInvalid.xml")).validate("test.xsd", getResource("test.xsd"), null);
+        XMLDocument xmldoc = xmldocument("testInvalid.xml", getResource("testInvalid.xml")).validate(getResourceUri("test.xsd"));
     }
 }