Index: schema/src/test/java/org/castor/xml/schema/TestAll.java
===================================================================
--- schema/src/test/java/org/castor/xml/schema/TestAll.java (revision 0)
+++ schema/src/test/java/org/castor/xml/schema/TestAll.java (revision 0)
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2008 Le Duc Bao
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.castor.xml.schema;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.log4j.xml.DOMConfigurator;
+/**
+ * Test all Schema API
+ * @author Le Duc Bao
+ */
+public class TestAll extends TestCase {
+
+ /**log file*/
+ private static final String LOG_FILE = "log4j-test.xml";
+
+ /**
+ * Constructor for TestAll
+ * @param name name
+ */
+ public TestAll(final String name) { super(name); }
+
+ /**
+ *
+ * @param args params
+ */
+ public static void main(final String[] args) {
+ try {
+ DOMConfigurator.configure(LOG_FILE);
+
+// TestResult result =
+ junit.textui.TestRunner.run(TestAll.suite());
+// junit.swingui.TestRunner.run(TestAll.class);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ *
+ * @return Test
+ * @throws Exception exception
+ */
+ public static Test suite() throws Exception {
+ TestSuite suite = new TestSuite("All org.castor.xml.schema tests");
+
+ //add test suite
+ suite.addTest(NamespaceTest.suite());
+ suite.addTest(ComplexTypeTest.suite());
+ return suite;
+ }
+
+}
Index: schema/src/test/java/org/castor/xml/schema/ComplexTypeTest.java
===================================================================
--- schema/src/test/java/org/castor/xml/schema/ComplexTypeTest.java (revision 0)
+++ schema/src/test/java/org/castor/xml/schema/ComplexTypeTest.java (revision 0)
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2008 Le Duc Bao
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.castor.xml.schema;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.castor.xml.schema.framework.AbstractSchemaTest;
+import org.exolab.castor.xml.schema.ComplexType;
+import org.exolab.castor.xml.schema.ElementDecl;
+import org.exolab.castor.xml.schema.Group;
+
+/**
+ * Complex type tests
+ * @author Le Duc Bao
+ */
+public class ComplexTypeTest extends AbstractSchemaTest {
+
+ /**
+ * @param testcase
+ */
+ public ComplexTypeTest(String testcase) {
+ super(testcase);
+ }
+ //-------------------------------------------------------------------
+ /**
+ * create a test suite for this tests
+ * @return a test suite
+ * @throws Exception
+ */
+ public static Test suite() throws Exception {
+ TestSuite suite = new TestSuite("All org.castor.xml.schema Namespace tests");
+
+ // schema test
+ suite.addTest(new ComplexTypeTest("testSingleAttribute"));
+
+ return suite;
+ }
+
+ //-------------------------------------------------------------------
+ /**
+ * Create simple type
+ */
+ public void testSingleAttribute() {
+
+ try {
+ //create targeted schema
+ _schema.addNamespace("pre", "my.namespace.org");
+ ComplexType cType = _schema.createComplexType("myType");
+ _schema.addComplexType(cType);
+
+ Group group = new Group();
+ cType.addGroup(group);
+
+ ElementDecl e = new ElementDecl(_schema);
+ e.setName("myAttr");
+ group.addElementDecl(e);
+
+ //compare
+ int result = doTest("complextype_singleattribute.xsd");
+ assertEquals("single attribute test failed", NO_DIFFERENCE, result);
+ } catch (Exception e) {
+ fail("testSingleNamespace: " + e.getMessage());
+ }
+ }
+
+}
Index: schema/src/test/java/org/castor/xml/schema/NamespaceTest.java
===================================================================
--- schema/src/test/java/org/castor/xml/schema/NamespaceTest.java (revision 0)
+++ schema/src/test/java/org/castor/xml/schema/NamespaceTest.java (revision 0)
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2008 Le Duc Bao
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.castor.xml.schema;
+
+import java.io.ByteArrayOutputStream;
+
+import org.castor.xml.schema.framework.AbstractSchemaTest;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Namespace tests.
+ *
+ * @author Le Duc Bao
+ */
+public final class NamespaceTest extends AbstractSchemaTest {
+ public NamespaceTest(final String testcase) {
+ super(testcase);
+ }
+ //-------------------------------------------------------------------
+ /**
+ * create a test suite for this tests
+ * @return a test suite
+ * @throws Exception
+ */
+ public static Test suite() throws Exception {
+ TestSuite suite = new TestSuite("All org.castor.xml.schema Namespace tests");
+
+ // schema test
+ suite.addTest(new NamespaceTest("testSingleNamespace"));
+
+ return suite;
+ }
+
+ //-------------------------------------------------------------------
+ /**
+ * Create a schema with single namespace
+ */
+ public void testSingleNamespace() {
+
+ try {
+ //create targeted schema
+ _schema.addNamespace("myprefix", "my.namespace.org");
+
+ int result = doTest("namespace_1.xsd");
+ assertEquals("single namespace add failed", NO_DIFFERENCE, result);
+ } catch (Exception e) {
+ fail("testSingleNamespace: " + e.getMessage());
+ }
+ }
+}
Index: schema/src/test/java/org/castor/xml/schema/ComplexTypeTest.java
===================================================================
--- schema/src/test/java/org/castor/xml/schema/ComplexTypeTest.java (revision 0)
+++ schema/src/test/java/org/castor/xml/schema/ComplexTypeTest.java (revision 0)
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2008 Le Duc Bao
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.castor.xml.schema;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.castor.xml.schema.framework.AbstractSchemaTest;
+import org.exolab.castor.xml.schema.ComplexType;
+import org.exolab.castor.xml.schema.ElementDecl;
+import org.exolab.castor.xml.schema.Group;
+
+/**
+ * Complex type tests
+ * @author Le Duc Bao
+ */
+public class ComplexTypeTest extends AbstractSchemaTest {
+
+ /**
+ * @param testcase
+ */
+ public ComplexTypeTest(String testcase) {
+ super(testcase);
+ }
+ //-------------------------------------------------------------------
+ /**
+ * create a test suite for this tests
+ * @return a test suite
+ * @throws Exception
+ */
+ public static Test suite() throws Exception {
+ TestSuite suite = new TestSuite("All org.castor.xml.schema Namespace tests");
+
+ // schema test
+ suite.addTest(new ComplexTypeTest("testSingleAttribute"));
+
+ return suite;
+ }
+
+ //-------------------------------------------------------------------
+ /**
+ * Create simple type
+ */
+ public void testSingleAttribute() {
+
+ try {
+ //create targeted schema
+ _schema.addNamespace("pre", "my.namespace.org");
+ ComplexType cType = _schema.createComplexType("myType");
+ _schema.addComplexType(cType);
+
+ Group group = new Group();
+ cType.addGroup(group);
+
+ ElementDecl e = new ElementDecl(_schema);
+ e.setName("myAttr");
+ group.addElementDecl(e);
+
+ //compare
+ int result = doTest("complextype_singleattribute.xsd");
+ assertEquals("single attribute test failed", NO_DIFFERENCE, result);
+ } catch (Exception e) {
+ fail("testSingleNamespace: " + e.getMessage());
+ }
+ }
+
+}
Index: schema/src/test/java/org/castor/xml/schema/framework/AbstractSchemaTest.java
===================================================================
--- schema/src/test/java/org/castor/xml/schema/framework/AbstractSchemaTest.java (revision 0)
+++ schema/src/test/java/org/castor/xml/schema/framework/AbstractSchemaTest.java (revision 0)
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2008 Le Duc Bao
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.castor.xml.schema.framework;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.net.URL;
+
+import org.castor.xmlctf.xmldiff.XMLDiff;
+import org.exolab.castor.xml.schema.Schema;
+import org.exolab.castor.xml.schema.writer.SchemaWriter;
+
+import junit.framework.TestCase;
+
+
+/**
+ * This class aims to set up a test environment and to provide a skeleton
+ * for testing Schema API. A typical scenarios test is
+ *
Create Schema related to targeted test case
+ * Generate Schema fragment by calling SchemaWriter
+ * Load expected schema file
+ * Compare generated schema vs expected schema
+ *
+ * @author Le Duc Bao
+ */
+public abstract class AbstractSchemaTest extends TestCase {
+ //--------------------------------------------------------------------------
+
+ /** Path of the expected result pattern files. */
+// private static final String EXPECTED_PATH = "..";
+ //--------------------------------------------------------------------------
+ /**Handle targeted schema*/
+ protected Schema _schema = null;
+
+ protected static final int NO_DIFFERENCE = 0;
+ //--------------------------------------------------------------------------
+
+ /**
+ * Constructor for BaseGeneratorTest
+ *
+ * @param testcase test case
+ */
+ public AbstractSchemaTest(final String testcase) {
+ super(testcase);
+ }
+
+ //--------------------------------------------------------------------------
+
+ /**
+ * create a new schema instance
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ _schema = new Schema ();
+ }
+
+
+ /**
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ _schema = null;
+ }
+
+ //--------------------------------------------------------------------------
+
+ /**
+ * This function aims to generate schema fragment, load expected schema and compare them.
+ * @param expectedFilename expected schema filename.
+ * @return 0, if no differences are found, otherwise a positive number
+ * indicating the number of differences. @see org.castor.xmlctf.xmldiff.XMLDiff#compare()
+ * @throws Exception if any
+ */
+ protected final int doTest (String expected) throws Exception{
+ //To reuse the existent source code from XMLCTF Framework, all schemas will be
+ //represented as a XML content. They are inputed to org.castor.xmlctf.xmldiff.XMLDiff
+ //to get the final result.
+
+ //1. generate schema and product a xml content, write it in a temporary file
+ File targetedOutput = File.createTempFile("doTest", "xmlctf");
+ Writer writer = new BufferedWriter (new PrintWriter (targetedOutput));
+ SchemaWriter swriter = new SchemaWriter(writer);
+ swriter.write(_schema);
+
+ //2. load expected schema
+ URL expectedUrl = this.getClass().getResource(expected);
+
+ //3. compare using org.castor.xmlctf.xmldiff.XMLDiff
+ XMLDiff diff = new XMLDiff(targetedOutput.getAbsolutePath(), expectedUrl.getFile());
+ int result = diff.compare();
+
+ //4. delete temporary file
+ targetedOutput.delete();
+
+ return result;
+ }
+ //--------------------------------------------------------------------------
+}
Index: schema/src/test/java/org/castor/xml/schema/framework/AbstractSchemaTest.java
===================================================================
--- schema/src/test/java/org/castor/xml/schema/framework/AbstractSchemaTest.java (revision 0)
+++ schema/src/test/java/org/castor/xml/schema/framework/AbstractSchemaTest.java (revision 0)
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2008 Le Duc Bao
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.castor.xml.schema.framework;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.net.URL;
+
+import org.castor.xmlctf.xmldiff.XMLDiff;
+import org.exolab.castor.xml.schema.Schema;
+import org.exolab.castor.xml.schema.writer.SchemaWriter;
+
+import junit.framework.TestCase;
+
+
+/**
+ * This class aims to set up a test environment and to provide a skeleton
+ * for testing Schema API. A typical scenarios test is
+ * Create Schema related to targeted test case
+ * Generate Schema fragment by calling SchemaWriter
+ * Load expected schema file
+ * Compare generated schema vs expected schema
+ *
+ * @author Le Duc Bao
+ */
+public abstract class AbstractSchemaTest extends TestCase {
+ //--------------------------------------------------------------------------
+
+ /** Path of the expected result pattern files. */
+// private static final String EXPECTED_PATH = "..";
+ //--------------------------------------------------------------------------
+ /**Handle targeted schema*/
+ protected Schema _schema = null;
+
+ protected static final int NO_DIFFERENCE = 0;
+ //--------------------------------------------------------------------------
+
+ /**
+ * Constructor for BaseGeneratorTest
+ *
+ * @param testcase test case
+ */
+ public AbstractSchemaTest(final String testcase) {
+ super(testcase);
+ }
+
+ //--------------------------------------------------------------------------
+
+ /**
+ * create a new schema instance
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ _schema = new Schema ();
+ }
+
+
+ /**
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ _schema = null;
+ }
+
+ //--------------------------------------------------------------------------
+
+ /**
+ * This function aims to generate schema fragment, load expected schema and compare them.
+ * @param expectedFilename expected schema filename.
+ * @return 0, if no differences are found, otherwise a positive number
+ * indicating the number of differences. @see org.castor.xmlctf.xmldiff.XMLDiff#compare()
+ * @throws Exception if any
+ */
+ protected final int doTest (String expected) throws Exception{
+ //To reuse the existent source code from XMLCTF Framework, all schemas will be
+ //represented as a XML content. They are inputed to org.castor.xmlctf.xmldiff.XMLDiff
+ //to get the final result.
+
+ //1. generate schema and product a xml content, write it in a temporary file
+ File targetedOutput = File.createTempFile("doTest", "xmlctf");
+ Writer writer = new BufferedWriter (new PrintWriter (targetedOutput));
+ SchemaWriter swriter = new SchemaWriter(writer);
+ swriter.write(_schema);
+
+ //2. load expected schema
+ URL expectedUrl = this.getClass().getResource(expected);
+
+ //3. compare using org.castor.xmlctf.xmldiff.XMLDiff
+ XMLDiff diff = new XMLDiff(targetedOutput.getAbsolutePath(), expectedUrl.getFile());
+ int result = diff.compare();
+
+ //4. delete temporary file
+ targetedOutput.delete();
+
+ return result;
+ }
+ //--------------------------------------------------------------------------
+}
Index: schema/src/test/java/org/castor/xml/schema/NamespaceTest.java
===================================================================
--- schema/src/test/java/org/castor/xml/schema/NamespaceTest.java (revision 0)
+++ schema/src/test/java/org/castor/xml/schema/NamespaceTest.java (revision 0)
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2008 Le Duc Bao
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.castor.xml.schema;
+
+import java.io.ByteArrayOutputStream;
+
+import org.castor.xml.schema.framework.AbstractSchemaTest;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Namespace tests.
+ *
+ * @author Le Duc Bao
+ */
+public final class NamespaceTest extends AbstractSchemaTest {
+ public NamespaceTest(final String testcase) {
+ super(testcase);
+ }
+ //-------------------------------------------------------------------
+ /**
+ * create a test suite for this tests
+ * @return a test suite
+ * @throws Exception
+ */
+ public static Test suite() throws Exception {
+ TestSuite suite = new TestSuite("All org.castor.xml.schema Namespace tests");
+
+ // schema test
+ suite.addTest(new NamespaceTest("testSingleNamespace"));
+
+ return suite;
+ }
+
+ //-------------------------------------------------------------------
+ /**
+ * Create a schema with single namespace
+ */
+ public void testSingleNamespace() {
+
+ try {
+ //create targeted schema
+ _schema.addNamespace("myprefix", "my.namespace.org");
+
+ int result = doTest("namespace_1.xsd");
+ assertEquals("single namespace add failed", NO_DIFFERENCE, result);
+ } catch (Exception e) {
+ fail("testSingleNamespace: " + e.getMessage());
+ }
+ }
+}
Index: schema/src/test/java/org/castor/xml/schema/TestAll.java
===================================================================
--- schema/src/test/java/org/castor/xml/schema/TestAll.java (revision 0)
+++ schema/src/test/java/org/castor/xml/schema/TestAll.java (revision 0)
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2008 Le Duc Bao
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.castor.xml.schema;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.log4j.xml.DOMConfigurator;
+/**
+ * Test all Schema API
+ * @author Le Duc Bao
+ */
+public class TestAll extends TestCase {
+
+ /**log file*/
+ private static final String LOG_FILE = "log4j-test.xml";
+
+ /**
+ * Constructor for TestAll
+ * @param name name
+ */
+ public TestAll(final String name) { super(name); }
+
+ /**
+ *
+ * @param args params
+ */
+ public static void main(final String[] args) {
+ try {
+ DOMConfigurator.configure(LOG_FILE);
+
+// TestResult result =
+ junit.textui.TestRunner.run(TestAll.suite());
+// junit.swingui.TestRunner.run(TestAll.class);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ *
+ * @return Test
+ * @throws Exception exception
+ */
+ public static Test suite() throws Exception {
+ TestSuite suite = new TestSuite("All org.castor.xml.schema tests");
+
+ //add test suite
+ suite.addTest(NamespaceTest.suite());
+ suite.addTest(ComplexTypeTest.suite());
+ return suite;
+ }
+
+}
Index: schema/src/test/resources/org/castor/xml/schema/namespace_1.xsd
===================================================================
--- schema/src/test/resources/org/castor/xml/schema/namespace_1.xsd (revision 0)
+++ schema/src/test/resources/org/castor/xml/schema/namespace_1.xsd (revision 0)
@@ -0,0 +1,2 @@
+
+
Index: schema/src/test/resources/org/castor/xml/schema/complextype_singleattribute.xsd
===================================================================
--- schema/src/test/resources/org/castor/xml/schema/complextype_singleattribute.xsd (revision 0)
+++ schema/src/test/resources/org/castor/xml/schema/complextype_singleattribute.xsd (revision 0)
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
Index: schema/src/test/resources/org/castor/xml/schema/complextype_singleattribute.xsd
===================================================================
--- schema/src/test/resources/org/castor/xml/schema/complextype_singleattribute.xsd (revision 0)
+++ schema/src/test/resources/org/castor/xml/schema/complextype_singleattribute.xsd (revision 0)
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
Index: schema/src/test/resources/org/castor/xml/schema/namespace_1.xsd
===================================================================
--- schema/src/test/resources/org/castor/xml/schema/namespace_1.xsd (revision 0)
+++ schema/src/test/resources/org/castor/xml/schema/namespace_1.xsd (revision 0)
@@ -0,0 +1,2 @@
+
+