db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r993142 - /db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/stream/XmlParserTest.java
Date Mon, 06 Sep 2010 20:17:06 GMT
Author: tfischer
Date: Mon Sep  6 20:17:06 2010
New Revision: 993142

URL: http://svn.apache.org/viewvc?rev=993142&view=rev
Log:
Added test for schema validation

Modified:
    db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/stream/XmlParserTest.java

Modified: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/stream/XmlParserTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/stream/XmlParserTest.java?rev=993142&r1=993141&r2=993142&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/stream/XmlParserTest.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/stream/XmlParserTest.java
Mon Sep  6 20:17:06 2010
@@ -22,13 +22,14 @@ package org.apache.torque.generator.sour
 import static org.junit.Assert.assertEquals;
 
 import java.io.File;
+import java.io.IOException;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.torque.generator.configuration.UnitConfiguration;
 import org.apache.torque.generator.configuration.source.EntityReferences;
 import org.apache.torque.generator.control.ControllerState;
 import org.apache.torque.generator.source.SourceElement;
-import org.apache.torque.generator.source.stream.FileSource;
-import org.apache.torque.generator.source.stream.XmlSourceFormat;
+import org.apache.torque.generator.source.SourceException;
 import org.junit.Test;
 
 public class XmlParserTest
@@ -38,7 +39,22 @@ public class XmlParserTest
     public XmlParserTest()
     {
         UnitConfiguration unitConfiguration = new UnitConfiguration();
-        unitConfiguration.setEntityReferences(new EntityReferences());
+        EntityReferences entityReferences = new EntityReferences();
+        File schemaFile = new File("src/test/resources/"
+                + "org/apache/torque/generator/source/xml/schema.xsd");
+        byte[] schemaContent;
+        try
+        {
+            schemaContent = FileUtils.readFileToByteArray(schemaFile);
+        }
+        catch (IOException e)
+        {
+            throw new RuntimeException(e);
+        }
+        entityReferences.addEntityReference(
+                "http://db.apache.org/torque/4.0/generator/test/namespace.xsd",
+                schemaContent);
+        unitConfiguration.setEntityReferences(entityReferences);
         controllerState.setUnitConfiguration(unitConfiguration);
     }
 
@@ -97,4 +113,31 @@ public class XmlParserTest
                 "  text For Second Level Element 4  ",
                 child4.getAttribute((String) null));
     }
+    
+    @Test
+    public void testReadXmlSourceWithSchema() throws Exception
+    {
+        File xmlFile = new File(
+            "src/test/resources/org/apache/torque/generator/source/xml/"
+                + "sourceConformingWithSchema.xml");
+        FileSource fileSource = new FileSource(
+                new XmlSourceFormat(),
+                xmlFile,
+                controllerState);
+        SourceElement rootElement = fileSource.getRootElement();
+        assertEquals("value", rootElement.getAttribute("attribute"));
+    }
+
+    @Test(expected = SourceException.class)
+    public void testReadXmlSourceNotConformWithSchema() throws Exception
+    {
+        File xmlFile = new File(
+            "src/test/resources/org/apache/torque/generator/source/xml/"
+                + "sourceNotConformingWithSchema.xml");
+        FileSource fileSource = new FileSource(
+                new XmlSourceFormat(),
+                xmlFile,
+                controllerState);
+        fileSource.getRootElement();
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message