summaryrefslogtreecommitdiffstats
path: root/sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd
diff options
context:
space:
mode:
Diffstat (limited to 'sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd')
-rw-r--r--sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd/XSDBaseTestCase.java126
-rw-r--r--sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd/XSDChoiceTest.java173
-rw-r--r--sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd/XSDComplexTypeTest.java863
-rw-r--r--sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd/XSDSimpleTypeTest.java364
4 files changed, 1526 insertions, 0 deletions
diff --git a/sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd/XSDBaseTestCase.java b/sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd/XSDBaseTestCase.java
new file mode 100644
index 0000000000..c903fe6e63
--- /dev/null
+++ b/sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd/XSDBaseTestCase.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 test.sdo21.tests.xsd;
+
+import junit.framework.TestCase;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Iterator;
+import java.net.URL;
+
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.XSDHelper;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.Type;
+import commonj.sdo.Property;
+import test.sdo21.CTSSuite;
+import test.sdo21.framework.CTSTestCase;
+import test.sdo21.framework.TestHelper;
+
+import org.junit.After;
+import org.junit.Before;
+import static org.junit.Assert.*;
+
+/**
+ * Base class for all XSD tests.
+ */
+public class XSDBaseTestCase extends CTSTestCase {
+
+ protected TestHelper testHelper;
+ protected XSDHelper xsdHelper;
+ protected TypeHelper typeHelper;
+ protected DataFactory dataFactory;
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ testHelper = getTestHelper();
+ xsdHelper = getScope().getXSDHelper();
+ typeHelper = getScope().getTypeHelper();
+ dataFactory = getScope().getDataFactory();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Parse an XSD file.
+ */
+ protected List define(String filename) throws IOException {
+
+ URL url = getClass().getResource(filename);
+ if (url == null) {
+ throw new RuntimeException("Could not locate " + filename);
+ }
+ InputStream inputStream = url.openStream();
+ XSDHelper xsdHelper = getScope().getXSDHelper();
+ List typeList = xsdHelper.define(inputStream, url.toString());
+ inputStream.close();
+ return typeList;
+ }
+
+ protected void assertBaseTypeExists(Type type, String baseTypeName) {
+ boolean found = false;
+ Iterator iter = type.getBaseTypes().iterator();
+ while (!found && iter.hasNext()) {
+ String s = (String) iter.next();
+ if (s.equals(baseTypeName)) {
+ found = true;
+ }
+ }
+ if (!found) {
+ fail("Type '" + type.getName() + "' should have base type '" + baseTypeName + "'");
+ }
+ }
+
+ protected void assertPropertyExists(Type type, String propertyName, String propertyType, boolean isContainment, boolean isMany) {
+ Property p = type.getProperty(propertyName);
+ assertNotNull("property '" + propertyName + "'", p);
+ assertEquals("propertyType", propertyType, p.getType().getName());
+ assertEquals("isContainment", isContainment, p.isContainment());
+ assertEquals("isMany", isMany, p.isMany());
+ }
+
+ protected void assertPropertyExists(Type type, String propertyName, String propertyType, boolean isContainment, boolean isMany, boolean isNullable) {
+ Property p = type.getProperty(propertyName);
+ assertNotNull("property '" + propertyName + "'", p);
+ assertEquals("propertyType", propertyType, p.getType().getName());
+ assertEquals("isContainment", isContainment, p.isContainment());
+ assertEquals("isMany", isMany, p.isMany());
+ assertEquals("isNullable", isNullable, p.isNullable());
+ }
+
+ public Type getType(List types, String name) {
+ Iterator it = types.iterator();
+ while (it.hasNext()) {
+ Type t = (Type) it.next();
+ if (t.getName().equals(name)) {
+ return t;
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd/XSDChoiceTest.java b/sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd/XSDChoiceTest.java
new file mode 100644
index 0000000000..3f30fe590a
--- /dev/null
+++ b/sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd/XSDChoiceTest.java
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 test.sdo21.tests.xsd;
+
+import java.util.List;
+
+import commonj.sdo.Type;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class XSDChoiceTest extends XSDBaseTestCase {
+
+ /**
+ * @throws Exception if an exception occurs
+ */
+ @Test
+ public void testTC224_Choice() throws Exception
+ {
+ // load the schema and obtain TypeList
+ List typeList = define( "/choice/TC224.xsd" );
+
+ // assert that the correct number of SDO Types were created
+ assertTrue( typeList.size() > 0 );
+
+ Type choiceType = typeHelper.getType("http://www.example.com/TC224","choiceType");
+ assertNotNull( choiceType );
+
+ // make assertion on the SDO Type
+ assertEquals( "choiceType", choiceType.getName() );
+ assertFalse( choiceType.isDataType() );
+ assertFalse( choiceType.isOpen() );
+ assertFalse( choiceType.isSequenced() );
+
+ List propList = choiceType.getProperties();
+ assertEquals( 3, propList.size() );
+
+ // assert SDO Properties were created with correct type ...
+ assertPropertyExists( choiceType, "red", "DataObject", true, false );
+ assertFalse( choiceType.getProperty("red").isReadOnly() );
+
+ assertPropertyExists( choiceType, "green", "DataObject", true, false );
+ assertFalse( choiceType.getProperty("green").isReadOnly() );
+
+ assertPropertyExists( choiceType, "blue", "DataObject", true, false );
+ assertFalse( choiceType.getProperty("blue").isReadOnly() );
+ }
+
+ /**
+ * @throws Exception if an exception occurs
+ */
+ @Test
+ public void testTC225_Choice() throws Exception
+ {
+ // load the schema and obtain TypeList
+ List typeList = define( "/choice/TC225.xsd" );
+
+ // assert that the correct number of SDO Types were created
+ assertTrue( typeList.size() > 0 );
+
+ Type choiceType = typeHelper.getType("http://www.example.com/TC225","choiceType");
+ assertNotNull( choiceType );
+
+ // make assertion on the SDO Type
+ assertEquals( "choiceType", choiceType.getName() );
+ assertFalse( choiceType.isDataType() );
+ assertFalse( choiceType.isOpen() );
+
+ // this type should have sequenced=true because the choice is unbounded
+ assertTrue( choiceType.isSequenced() );
+
+ List propList = choiceType.getProperties();
+ assertEquals( 3, propList.size() );
+
+ // assert SDO Properties were created with correct type ...
+ assertPropertyExists( choiceType, "red", "DataObject", true, true );
+ assertFalse( choiceType.getProperty("red").isReadOnly() );
+
+ assertPropertyExists( choiceType, "green", "DataObject", true, true );
+ assertFalse( choiceType.getProperty("green").isReadOnly() );
+
+ assertPropertyExists( choiceType, "blue", "DataObject", true, true );
+ assertFalse( choiceType.getProperty("blue").isReadOnly() );
+ }
+
+ /**
+ * @throws Exception if an exception occurs
+ */
+ @Test
+ public void testTC226_Choice() throws Exception
+ {
+ // load the schema and obtain TypeList
+ List typeList = define( "/choice/TC226.xsd" );
+
+ // assert that the correct number of SDO Types were created
+ assertTrue( typeList.size() > 0 );
+
+ Type choiceType = typeHelper.getType("http://www.example.com/TC226","choiceType");
+ assertNotNull( choiceType );
+
+ // make assertion on the SDO Type
+ assertEquals( "choiceType", choiceType.getName() );
+ assertFalse( choiceType.isDataType() );
+ assertFalse( choiceType.isOpen() );
+ assertFalse( choiceType.isSequenced() );
+
+ List propList = choiceType.getProperties();
+ assertEquals( 3, propList.size() );
+
+ // assert SDO Properties were created with correct type ...
+ assertPropertyExists( choiceType, "red", "String", false, false );
+ assertFalse( choiceType.getProperty("red").isReadOnly() );
+
+ assertPropertyExists( choiceType, "green", "DataObject", true, false );
+ assertFalse( choiceType.getProperty("green").isReadOnly() );
+
+ assertPropertyExists( choiceType, "blue", "DataObject", true, false );
+ assertFalse( choiceType.getProperty("blue").isReadOnly() );
+ }
+
+ /**
+ * @throws Exception if an exception occurs
+ */
+ @Test
+ public void testTC227_Choice() throws Exception
+ {
+ // load the schema and obtain TypeList
+ List typeList = define( "/choice/TC227.xsd" );
+
+ // assert that the correct number of SDO Types were created
+ assertTrue( typeList.size() > 0 );
+
+ Type choiceType = typeHelper.getType("http://www.example.com/TC227","choiceType");
+ assertNotNull( choiceType );
+
+ // make assertion on the SDO Type
+ assertEquals( "choiceType", choiceType.getName() );
+ assertFalse( choiceType.isDataType() );
+ assertFalse( choiceType.isOpen() );
+
+ // the choice has maxOccurs > 1 so this type should be sequenced
+ assertTrue( choiceType.isSequenced() );
+
+ List propList = choiceType.getProperties();
+ assertEquals( 3, propList.size() );
+
+ // assert SDO Properties were created with correct type ...
+ assertPropertyExists( choiceType, "red", "DataObject", true, true );
+ assertFalse( choiceType.getProperty("red").isReadOnly() );
+
+ assertPropertyExists( choiceType, "green", "DataObject", true, true );
+ assertFalse( choiceType.getProperty("green").isReadOnly() );
+
+ assertPropertyExists( choiceType, "blue", "DataObject", true, true );
+ assertFalse( choiceType.getProperty("blue").isReadOnly() );
+ }
+}
diff --git a/sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd/XSDComplexTypeTest.java b/sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd/XSDComplexTypeTest.java
new file mode 100644
index 0000000000..ad1b446c3a
--- /dev/null
+++ b/sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd/XSDComplexTypeTest.java
@@ -0,0 +1,863 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 test.sdo21.tests.xsd;
+
+import java.util.List;
+import java.io.IOException;
+
+import commonj.sdo.Type;
+import commonj.sdo.Property;
+import commonj.sdo.DataObject;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class XSDComplexTypeTest extends XSDBaseTestCase {
+
+ /**
+ * <complexType> containing other elements.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testTC128ComplexTypeWithElement() throws Exception {
+
+ // parse the schema
+ List types = define("/complexType/cT_01.xsd");
+
+ Type type = (Type) types.get(0);
+ assertFalse(type.isSequenced());
+ assertFalse(type.isOpen());
+ assertFalse(type.isDataType());
+ assertFalse(type.isAbstract());
+ assertEquals("cT_01", type.getName());
+
+ assertPropertyExists(type, "id", "Int", false, false);
+ assertPropertyExists(type, "name", "String", false, false);
+ }
+
+ /**
+ * <complexType> with abstract="true".
+ *
+ * @throws Exception
+ */
+ @Test public void testTC129ComplexTypeAbstractTrue() throws Exception {
+
+ List types = define("/complexType/cT_02.xsd");
+
+ Type type = (Type) types.get(0);
+ assertFalse(type.isSequenced());
+ assertEquals("cT_02", type.getName());
+ assertTrue(type.isAbstract());
+
+ assertPropertyExists(type, "id", "Int", false, false);
+ assertFalse(type.getProperty("id").isReadOnly() );
+ assertPropertyExists(type, "name", "String", false, false);
+ assertFalse(type.getProperty("name").isReadOnly() );
+ }
+
+ /**
+ * <complexType> extending another <complexType>.
+ *
+ * @throws Exception
+ */
+ @Test public void testTC130ComplexTypeExtendingComplexType() throws Exception {
+
+ List types = define("/complexType/cT_03.xsd");
+ assertTrue(types.size() >= 2);
+
+ // parent
+ Type parentType = getType(types, "cT_03_parent");
+
+ List properties = parentType.getDeclaredProperties();
+ assertEquals(1, properties.size());
+
+ Property p1 = (Property) properties.get(0);
+
+ assertEquals("id", p1.getName());
+ assertEquals("Int", p1.getType().getName());
+
+ // child
+ Type childType = getType(types, "cT_03_child");
+
+ List baseTypes = childType.getBaseTypes();
+ assertEquals(1, baseTypes.size());
+ Type baseType = (Type) baseTypes.get(0);
+ assertEquals("cT_03_parent", baseType.getName());
+
+ properties = childType.getProperties();
+ assertEquals(2, properties.size());
+ assertEquals(1, childType.getDeclaredProperties().size() );
+
+ //verify name and type of Properties
+ // base properties appear first, derived properties are appended
+ Property childTypeProp1 = (Property) properties.get(0);
+ assertEquals("id", childTypeProp1.getName());
+ assertEquals("Int", childTypeProp1.getType().getName());
+
+ Property childTypeProp2 = (Property) properties.get(1);
+ assertEquals("name", childTypeProp2.getName());
+ assertEquals("String", childTypeProp2.getType().getName());
+ }
+
+ /**
+ * <complexType> derived from <complexType> with block="#all" (should not affect SDO Types generated).
+ *
+ * @throws Exception
+ */
+ @Test public void testTC131ComplexTypeBlockAll() throws Exception {
+ List types = define("/complexType/cT_04.xsd");
+ assertTrue(types.size() >= 2);
+
+ // parent
+ Type parentType = getType(types, "cT_04_parent");
+
+ List properties = parentType.getDeclaredProperties();
+ assertEquals(1, properties.size());
+
+ Property p1 = (Property) properties.get(0);
+
+ assertEquals("id", p1.getName());
+ assertEquals("Int", p1.getType().getName());
+
+ // child
+ Type childType = getType(types, "cT_04_child");
+
+ List baseTypes = childType.getBaseTypes();
+ assertEquals(1, baseTypes.size());
+ Type baseType = (Type) baseTypes.get(0);
+ assertEquals("cT_04_parent", baseType.getName());
+
+ properties = childType.getProperties();
+ assertEquals(2, properties.size());
+ assertEquals(1, childType.getDeclaredProperties().size() );
+
+ //verify name and type of Properties
+ // base properties appear first, derived properties are appended
+ Property childTypeProp1 = (Property) properties.get(0);
+ assertEquals("id", childTypeProp1.getName());
+ assertEquals("Int", childTypeProp1.getType().getName());
+
+ Property childTypeProp2 = (Property) properties.get(1);
+ assertEquals("name", childTypeProp2.getName());
+ assertEquals("String", childTypeProp2.getType().getName());
+ }
+
+ /**
+ * <complexType> containing <group> containing <sequence>.
+ *
+ * @throws Exception
+ */
+ @Test public void testTC132ComplexTypeGroupWithSequence() throws Exception {
+ List types = define("/complexType/cT_05.xsd");
+
+ Type type = (Type) types.get(0);
+ assertEquals("cT_05", type.getName());
+ assertFalse(type.isAbstract());
+
+ assertPropertyExists(type, "id", "Int", false, false);
+ assertFalse(type.getProperty("id").isReadOnly());
+ assertPropertyExists(type, "name", "String", false, false);
+ assertFalse(type.getProperty("name").isReadOnly());
+ }
+
+ /**
+ * <element> name="cT_06" containing anonymous <complexType>.
+ *
+ * @throws Exception
+ */
+ @Test public void testTC133ComplexTypeAnonymous() throws Exception {
+ List types = define("/complexType/cT_06.xsd");
+
+ // The spec maps the name of anonymous types to the name
+ // of their enclosing element. This is a broken method however,
+ // as it can conflict with same named types and other same
+ // named elements with anonymous types. So currently we are
+ // intentially non-compliant. using unique names for
+ // anonymous types
+
+ Property property = typeHelper.getOpenContentProperty( "http://www.example.com/xsd/6/",
+ "cT_06" );
+ Type type = property.getType();
+ assertFalse(type.isAbstract());
+ assertFalse(type.isSequenced());
+
+ assertPropertyExists(type, "id", "Int", false, false);
+ assertFalse(type.getProperty("id").isReadOnly());
+ assertPropertyExists(type, "name", "String", false, false);
+ assertFalse(type.getProperty("name").isReadOnly());
+ }
+
+ /**
+ * <complexType> with name.
+ *
+ * @throws Exception
+ */
+ @Test public void testTC134ComplexTypeNamed() throws Exception {
+ List types = define("/complexType/cT_07.xsd");
+
+ Type type = (Type) types.get(0);
+ assertEquals("cT_07", type.getName());
+ assertFalse(type.isAbstract());
+ assertFalse(type.isSequenced());
+
+ assertPropertyExists(type, "id", "Int", false, false);
+ assertFalse(type.getProperty("id").isReadOnly());
+ assertPropertyExists(type, "name", "String", false, false);
+ assertFalse(type.getProperty("name").isReadOnly());
+ }
+
+ /**
+ * <complexType> with final="true" containing <complexContent> containing <extension> of a <complexType> with abstract="true".
+ *
+ * @throws Exception
+ */
+ @Test public void testTC136ComplexTypeExtendAbstractTrue() throws Exception {
+ List types = define("/complexType/cT_09.xsd");
+ assertTrue(types.size() >= 2);
+
+ // parent
+ Type parentType = typeHelper.getType("http://www.example.com/xsd/9/", "cT_09_parent");
+
+ List properties = parentType.getDeclaredProperties();
+ assertEquals(1, properties.size());
+
+ Property p1 = (Property) properties.get(0);
+
+ assertEquals("id", p1.getName());
+ assertEquals("Int", p1.getType().getName());
+
+ // child
+ Type childType = typeHelper.getType("http://www.example.com/xsd/9/", "cT_09_child");
+
+ List baseTypes = childType.getBaseTypes();
+ assertEquals(1, baseTypes.size());
+ Type baseType = (Type) baseTypes.get(0);
+ assertEquals("cT_09_parent", baseType.getName());
+
+ properties = childType.getDeclaredProperties();
+ assertEquals(1, properties.size());
+ assertEquals(2, childType.getProperties().size() );
+
+ Property p2 = (Property) properties.get(0);
+
+ assertEquals("name", p2.getName());
+ assertEquals("String", p2.getType().getName());
+ }
+
+ /**
+ * <complexType> containing <complexContent> containing <restriction> of a <complexType> with abstract="true".
+ *
+ * @throws Exception
+ */
+ @Test public void testTC137ComplexTypeExtendWithRestriction() throws Exception {
+ List types = define("/complexType/cT_10.xsd");
+ assertTrue(types.size() >= 2);
+
+ // parent
+ Type parentType = getType(types, "cT_10_parent");
+
+ List properties = parentType.getDeclaredProperties();
+ assertEquals(1, properties.size());
+
+ Property p1 = (Property) properties.get(0);
+ assertEquals("id", p1.getName());
+ assertEquals("Int", p1.getType().getName());
+
+ // child
+ Type childType = getType(types, "cT_10_child");
+
+ List baseTypes = childType.getBaseTypes();
+ assertEquals(1, baseTypes.size());
+ Type baseType = (Type) baseTypes.get(0);
+ assertEquals("cT_10_parent", baseType.getName());
+
+ properties = childType.getDeclaredProperties();
+ assertEquals(1, properties.size());
+
+ Property p2 = (Property) properties.get(0);
+ assertEquals("name", p2.getName());
+ assertEquals("String", p2.getType().getName());
+ }
+
+ /**
+ * <complexType> containing <complexContent> containing <extension> of a <complexType> with abstract="true".
+ *
+ * @throws Exception
+ */
+ @Test public void testTC138ComplexTypeExtend() throws Exception {
+ List types = define("/complexType/cT_11.xsd");
+ assertTrue(types.size() >= 2);
+
+ // parent
+ Type parentType = getType(types, "cT_11_parent");
+
+ List properties = parentType.getDeclaredProperties();
+ assertEquals(1, properties.size());
+
+ Property p1 = (Property) properties.get(0);
+
+ assertEquals("id", p1.getName());
+ assertEquals("Int", p1.getType().getName());
+
+ // child
+ Type childType = getType(types, "cT_11_child");
+
+ List baseTypes = childType.getBaseTypes();
+ assertEquals(1, baseTypes.size());
+ Type baseType = (Type) baseTypes.get(0);
+ assertEquals("cT_11_parent", baseType.getName());
+
+ properties = childType.getDeclaredProperties();
+ assertEquals(1, properties.size());
+
+ Property p2 = (Property) properties.get(0);
+
+ assertEquals("name", p2.getName());
+ assertEquals("String", p2.getType().getName());
+ }
+
+ /**
+ * <complexType> containing <simpleContent> containing <extension>.
+ *
+ * @throws Exception
+ */
+ @Test public void testTC143ComplexTypeSimpleContent() throws Exception {
+ List types = define("/complexType/cT_18.xsd");
+
+ Type type = typeHelper.getType("http://www.example.com/xsd/18/", "cT_18");
+
+ // 10.8. Corner cases
+ // ...
+ // 5. In some cases it is not possible to maintain an SDO base
+ // relationship when one exists in schema. This can happen for
+ // example when complex types extend simple types
+ //
+ // So a complexType extending a simple type doesn't have an SDO
+ // base type set
+
+ List baseTypes = type.getBaseTypes();
+ assertEquals(0, baseTypes.size());
+
+ // however complex types with simple content get a special
+ // property named "value" to represent their content
+ // p100, box 3 of the latest C++ 2.1 draft
+ // Complex Type extending a SimpleType
+ // <complexType name=[NAME]>
+ // <simpleContent>
+ // <extension
+ // base=[BASE]/>
+ // </simpleContent>
+ // </complexType>
+ //
+ // Type name=[NAME]
+ // uri=[URI]
+ // Property:
+ // name="value" type=[BASE]
+ // Properties are created for attribute
+ // declarations.
+
+ Property valueProperty = type.getProperty("value");
+ Type valueType = valueProperty.getType();
+ assertEquals("String", valueType.getName());
+ assertEquals("commonj.sdo", valueType.getURI());
+ }
+
+ /**
+ * <complexType> containing <simpleContent> containing <extension> containing <attribute>.
+ *
+ * @throws Exception
+ */
+ @Test public void test_cT_19() throws Exception {
+ List types = define("/complexType/cT_19.xsd");
+
+ // parent
+ Type type = getType(types, "cT_19");
+
+ // 10.8. Corner cases
+ // ...
+ // 5. In some cases it is not possible to maintain an SDO base
+ // relationship when one exists in schema. This can happen for
+ // example when complex types extend simple types
+ //
+ // So a complexType extending a simple type doesn't have an SDO
+ // base type set
+
+ List baseTypes = type.getBaseTypes();
+ assertEquals(0, baseTypes.size());
+
+ List properties = type.getDeclaredProperties();
+ assertEquals(2, properties.size());
+
+ Property p1 = type.getProperty( "lang" );
+ assertEquals("String", p1.getType().getName());
+
+ // however complex types with simple content get a special
+ // property named "value" to represent their content
+ // p100, box 3 of the latest C++ 2.1 draft
+ // Complex Type extending a SimpleType
+ // <complexType name=[NAME]>
+ // <simpleContent>
+ // <extension
+ // base=[BASE]/>
+ // </simpleContent>
+ // </complexType>
+ //
+ // Type name=[NAME]
+ // uri=[URI]
+ // Property:
+ // name="value" type=[BASE]
+ // Properties are created for attribute
+ // declarations.
+
+ Property valueProperty = type.getProperty("value");
+ Type valueType = valueProperty.getType();
+ assertEquals("String", valueType.getName());
+ assertEquals("commonj.sdo", valueType.getURI());
+ }
+
+ /**
+ * <complexType> containing <simpleContent> containing <extension> containing <attribute>.
+ *
+ * @throws Exception
+ */
+ @Test public void test_cT_22() throws Exception {
+ List types = define("/complexType/cT_22.xsd");
+
+ Type type = getType(types, "cT_22");
+ assertFalse(type.isSequenced());
+
+ // 10.8. Corner cases
+ // ...
+ // 5. In some cases it is not possible to maintain an SDO base
+ // relationship when one exists in schema. This can happen for
+ // example when complex types extend simple types
+ //
+ // So a complexType extending a simple type doesn't have an SDO
+ // base type set
+
+ List baseTypes = type.getBaseTypes();
+ assertEquals(0, baseTypes.size());
+
+ List properties = type.getDeclaredProperties();
+ assertEquals(2, properties.size());
+
+ Property p1 = type.getProperty( "lang" );
+ assertEquals("String", p1.getType().getName());
+
+ // however complex types with simple content get a special
+ // property named "value" to represent their content
+ // p100, box 3 of the latest C++ 2.1 draft
+ // Complex Type extending a SimpleType
+ // <complexType name=[NAME]>
+ // <simpleContent>
+ // <extension
+ // base=[BASE]/>
+ // </simpleContent>
+ // </complexType>
+ //
+ // Type name=[NAME]
+ // uri=[URI]
+ // Property:
+ // name="value" type=[BASE]
+ // Properties are created for attribute
+ // declarations.
+
+ Property valueProperty = type.getProperty("value");
+ Type valueType = valueProperty.getType();
+ assertEquals("String", valueType.getName());
+ assertEquals("commonj.sdo", valueType.getURI());
+ }
+
+ /**
+ * <complexType> containing <simpleContent> containing <extension> containing <attribute>
+ * containing <simpleType> containing <restriction>.
+ *
+ * @throws Exception
+ */
+ @Test public void test_cT_23() throws Exception {
+ List types = define("/complexType/cT_23.xsd");
+ // two types are output the one for the complex type
+ // and the simple type
+ assertTrue(types.size() >= 2);
+ Type type = getType(types, "cT_23");
+ assertFalse(type.isSequenced());
+
+ // 10.8. Corner cases
+ // ...
+ // 5. In some cases it is not possible to maintain an SDO base
+ // relationship when one exists in schema. This can happen for
+ // example when complex types extend simple types
+ //
+ // So a complexType extending a simple type doesn't have an SDO
+ // base type set
+
+ List baseTypes = type.getBaseTypes();
+ assertEquals(0, baseTypes.size());
+
+ List properties = type.getDeclaredProperties();
+ assertEquals(2, properties.size());
+
+ Property p1 = type.getProperty( "lang" );
+ assertNotNull( p1 );
+
+ // the actual type here for the lang attribute will be
+ // the anonymous simple type, which as it's base will
+ // be commonj.sdo#String
+ Type langBaseType = (Type)p1.getType().getBaseTypes().get(0);
+ assertEquals("String", langBaseType.getName());
+
+ // however complex types with simple content get a special
+ // property named "value" to represent their content
+ // p100, box 3 of the latest C++ 2.1 draft
+ // Complex Type extending a SimpleType
+ // <complexType name=[NAME]>
+ // <simpleContent>
+ // <extension
+ // base=[BASE]/>
+ // </simpleContent>
+ // </complexType>
+ //
+ // Type name=[NAME]
+ // uri=[URI]
+ // Property:
+ // name="value" type=[BASE]
+ // Properties are created for attribute
+ // declarations.
+
+ Property valueProperty = type.getProperty("value");
+ Type valueType = valueProperty.getType();
+ assertEquals("String", valueType.getName());
+ assertEquals("commonj.sdo", valueType.getURI());
+ }
+
+ /**
+ * <complexType> containing <all> containing <element> with minOccurs="1", maxOccurs="1".
+ *
+ * @throws Exception
+ */
+ @Test public void testTC300ComplexTypeContainingAllGroupWithElements() throws Exception {
+ List types = define("/complexType/cT_24.xsd");
+ Type type = getType(types, "cT_24");
+ assertPropertyExists(type, "p1", "String", false, false);
+ }
+
+ /**
+ * <complexType> containing <sequence> containing <element> with minOccurs="1", maxOccurs="1".
+ *
+ * @throws Exception
+ */
+ @Test public void test_cT_25() throws Exception {
+ List types = define("/complexType/cT_25.xsd");
+ Type type = getType(types, "cT_25");
+ assertPropertyExists(type, "p1", "String", false, false);
+ }
+
+ /**
+ * <complexType> containing <sequence> containing <element> with minOccurs="0", maxOccurs="unbounded".
+ *
+ * @throws Exception
+ */
+ @Test public void test_cT_26() throws Exception {
+ List types = define("/complexType/cT_26.xsd");
+ Type type = getType(types, "cT_26");
+ assertPropertyExists(type, "p1", "String", false, true);
+ }
+
+ /**
+ * <complexType> containing <sequence> containing <element> with minOccurs="1", maxOccurs="unbounded".
+ *
+ * @throws Exception
+ */
+ @Test public void testTC299ComplexTypeContainingUnboundedElement() throws Exception {
+ List types = define("/complexType/cT_27.xsd");
+ Type type = typeHelper.getType("http://www.example.com/xsd/27/", "cT_27");
+ assertPropertyExists(type, "p1", "String", false, true);
+ }
+
+ /**
+ * <complexType> containing an <element> for each XSD type supported by SDO.
+ *
+ * @throws Exception
+ */
+ @Test public void testTC297ComplexTypeContainingElementsOfAllTypes() throws Exception {
+ List types = define("/complexType/cT_28.xsd");
+
+ Type type = getType(types, "cT_28");
+ assertFalse(type.isSequenced());
+ assertEquals( 44, type.getProperties().size() );
+ assertPropertyExists(type, "type_date", "YearMonthDay", false, false);
+ assertPropertyExists(type, "type_dateTime", "DateTime", false, false);
+ assertPropertyExists(type, "type_decimal", "Decimal", false, false);
+ assertPropertyExists(type, "type_double", "Double", false, false);
+ assertPropertyExists(type, "type_duration", "Duration", false, false);
+ assertPropertyExists(type, "type_float", "Float", false, false);
+ assertPropertyExists(type, "type_gDay", "Day", false, false);
+ assertPropertyExists(type, "type_gMonth", "Month", false, false);
+ assertPropertyExists(type, "type_gMonthDay", "MonthDay", false, false);
+ assertPropertyExists(type, "type_gYear", "Year", false, false);
+ assertPropertyExists(type, "type_gYearMonth", "YearMonth", false, false);
+ assertPropertyExists(type, "type_int", "Int", false, false);
+ assertPropertyExists(type, "type_integer", "Integer", false, false);
+ assertPropertyExists(type, "type_long", "Long", false, false);
+ assertPropertyExists(type, "type_negativeInteger", "Integer", false, false);
+ assertPropertyExists(type, "type_nonNegativeInteger", "Integer", false, false);
+ assertPropertyExists(type, "type_nonPositiveInteger", "Integer", false, false);
+ assertPropertyExists(type, "type_positiveInteger", "Integer", false, false);
+ assertPropertyExists(type, "type_short", "Short", false, false);
+ assertPropertyExists(type, "type_string", "String", false, false);
+ assertPropertyExists(type, "type_time", "Time", false, false);
+ assertPropertyExists(type, "type_unsignedByte", "Short", false, false);
+ assertPropertyExists(type, "type_unsignedInt", "Long", false, false);
+ assertPropertyExists(type, "type_unsignedLong", "Integer", false, false);
+ assertPropertyExists(type, "type_unsignedShort", "Int", false, false);
+ assertPropertyExists(type, "type_anyType", "DataObject", true, false);
+ assertPropertyExists(type, "type_anyURI", "URI", false, false);
+ assertPropertyExists(type, "type_base64Binary", "Bytes", false, false);
+ assertPropertyExists(type, "type_byte", "Byte", false, false);
+ assertPropertyExists(type, "type_ENTITY", "String", false, false);
+ assertPropertyExists(type, "type_hexBinary", "Bytes", false, false);
+ assertPropertyExists(type, "type_ID", "String", false, false);
+ assertPropertyExists(type, "type_IDREF", "String", false, false);
+ assertPropertyExists(type, "type_language", "String", false, false);
+ assertPropertyExists(type, "type_Name", "String", false, false);
+ assertPropertyExists(type, "type_NCName", "String", false, false);
+ assertPropertyExists(type, "type_QName", "URI", false, false);
+ assertPropertyExists(type, "type_token", "String", false, false);
+ assertPropertyExists(type, "type_NMTOKEN", "String", false, false);
+ assertPropertyExists(type, "type_NMTOKENS", "Strings", false, false);
+ assertPropertyExists(type, "type_IDREFS", "Strings", false, false);
+ assertPropertyExists(type, "type_ENTITIES", "Strings", false, false);
+ assertPropertyExists(type, "type_anySimpleType", "Object", false, false);
+ }
+
+ /**
+ * <complexType> containing an <attribute> for each XSD type supported by SDO.
+ *
+ * @throws Exception
+ */
+ @Test public void test_cT_29() throws Exception {
+ List types = define("/complexType/cT_29.xsd");
+
+ Type type = getType(types, "cT_29");
+ assertFalse(type.isSequenced());
+ assertPropertyExists(type, "type_date", "YearMonthDay", false, false);
+ assertPropertyExists(type, "type_dateTime", "DateTime", false, false);
+ assertPropertyExists(type, "type_decimal", "Decimal", false, false);
+ assertPropertyExists(type, "type_double", "Double", false, false);
+ assertPropertyExists(type, "type_duration", "Duration", false, false);
+ assertPropertyExists(type, "type_float", "Float", false, false);
+ assertPropertyExists(type, "type_gDay", "Day", false, false);
+ assertPropertyExists(type, "type_gMonth", "Month", false, false);
+ assertPropertyExists(type, "type_gMonthDay", "MonthDay", false, false);
+ assertPropertyExists(type, "type_gYear", "Year", false, false);
+ assertPropertyExists(type, "type_gYearMonth", "YearMonth", false, false);
+ assertPropertyExists(type, "type_int", "Int", false, false);
+ assertPropertyExists(type, "type_integer", "Integer", false, false);
+ assertPropertyExists(type, "type_long", "Long", false, false);
+ assertPropertyExists(type, "type_negativeInteger", "Integer", false, false);
+ assertPropertyExists(type, "type_nonNegativeInteger", "Integer", false, false);
+ assertPropertyExists(type, "type_nonPositiveInteger", "Integer", false, false);
+ assertPropertyExists(type, "type_positiveInteger", "Integer", false, false);
+ assertPropertyExists(type, "type_short", "Short", false, false);
+ assertPropertyExists(type, "type_string", "String", false, false);
+ assertPropertyExists(type, "type_time", "Time", false, false);
+ assertPropertyExists(type, "type_unsignedByte", "Short", false, false);
+ assertPropertyExists(type, "type_unsignedInt", "Long", false, false);
+ assertPropertyExists(type, "type_unsignedLong", "Integer", false, false);
+ assertPropertyExists(type, "type_unsignedShort", "Int", false, false);
+ assertPropertyExists(type, "type_anyURI", "URI", false, false);
+ assertPropertyExists(type, "type_base64Binary", "Bytes", false, false);
+ assertPropertyExists(type, "type_byte", "Byte", false, false);
+ assertPropertyExists(type, "type_ENTITIES", "Strings", false, false);
+ assertPropertyExists(type, "type_ENTITY", "String", false, false);
+ assertPropertyExists(type, "type_hexBinary", "Bytes", false, false);
+ assertPropertyExists(type, "type_ID", "String", false, false);
+ assertPropertyExists(type, "type_IDREF", "String", false, false);
+ assertPropertyExists(type, "type_IDREFS", "Strings", false, false);
+ assertPropertyExists(type, "type_language", "String", false, false);
+ assertPropertyExists(type, "type_Name", "String", false, false);
+ assertPropertyExists(type, "type_NMTOKEN", "String", false, false);
+ assertPropertyExists(type, "type_NMTOKENS", "Strings", false, false);
+ assertPropertyExists(type, "type_QName", "URI", false, false);
+ assertPropertyExists(type, "type_token", "String", false, false);
+ assertPropertyExists(type, "type_NCName", "String", false, false);
+ assertPropertyExists(type, "type_anySimpleType", "Object", false, false);
+ }
+
+ /**
+ * <complexType> containing a <sequence> which contains a <group> reference and an <element>. The <group>
+ * also contains a <sequence>.
+ *
+ * @throws Exception
+ */
+ @Test public void test_cT_30() throws Exception {
+ List types = define("/complexType/cT_30.xsd");
+
+ Type type = getType(types, "cT_30");
+ assertFalse(type.isSequenced());
+ assertPropertyExists(type, "p1", "String", false, false);
+ assertPropertyExists(type, "p2", "String", false, false);
+ assertPropertyExists(type, "p3", "Int", false, false);
+ }
+
+ /**
+ * <complexContent> using <extension> to extend another <complexContent>. The derived <complexContent>
+ * references a <group> which contains a <sequence>.
+ *
+ * @throws Exception
+ */
+ @Test public void test_cT_31() throws Exception {
+ List types = define("/complexType/cT_31.xsd");
+ assertTrue(types.size() >= 2);
+
+ Type type = getType(types, "cT_31");
+ assertFalse(type.isSequenced());
+ assertPropertyExists(type, "p1", "String", false, false);
+ assertPropertyExists(type, "p2", "String", false, false);
+ assertPropertyExists(type, "p3", "Int", false, false);
+ assertPropertyExists(type, "p4", "String", false, false);
+ assertPropertyExists(type, "p5", "String", false, false);
+ }
+
+ /**
+ * <complexType> with mixed="true". Must create SDO Type with sequenced="true".
+ *
+ * @throws Exception
+ */
+ @Test public void test_cT_42() throws Exception {
+ List types = define("/complexType/cT_42.xsd");
+
+ Type type = getType(types, "cT_42");
+ assertTrue(type.isSequenced());
+ assertPropertyExists(type, "id", "Int", false, false);
+ assertPropertyExists(type, "name", "String", false, false);
+ }
+
+
+ /**
+ * <complexType> containing <any> with maxOccurs="unbounded". Should map to SDO Type with
+ * sequenced="true" and no declared properties.
+ *
+ * @throws Exception
+ */
+ @Test public void test_cT_43() throws Exception {
+ List types = define("/complexType/cT_43.xsd");
+
+ Type type = getType(types, "cT_43");
+ assertTrue(type.isOpen());
+ assertEquals(0, type.getProperties().size());
+ }
+
+ /**
+ * <complexType> containing <any> with maxOccurs="1". Should map to SDO Type with
+ * sequenced="false" and no declared properties.
+ *
+ * @throws Exception
+ */
+ @Test public void test_cT_44() throws Exception {
+ List types = define("/complexType/cT_44.xsd");
+
+ Type type = getType(types, "cT_44");
+ assertTrue(type.isOpen());
+ assertFalse(type.isSequenced());
+ assertEquals(0, type.getProperties().size());
+ }
+
+ /**
+ * <complexType> containing <anyAttribute> . Should map to SDO Type with
+ * no declared properties.
+ *
+ * @throws Exception
+ */
+ @Test public void test_cT_45() throws Exception {
+ List types = define("/complexType/cT_45.xsd");
+
+ Type type = getType(types, "cT_45");
+ assertTrue(type.isOpen());
+ assertFalse(type.isSequenced());
+ assertEquals(0, type.getProperties().size());
+ }
+
+ /**
+ * <complexType> containing element with nillable="true"
+ *
+ * @throws Exception
+ */
+ @Test public void test_cT_46() throws Exception {
+
+ List types = define("/complexType/cT_46.xsd");
+
+ Type type = (Type) types.get(0);
+ assertFalse(type.isSequenced());
+ assertFalse(type.isOpen());
+ assertFalse(type.isDataType());
+ assertFalse(type.isAbstract());
+ assertEquals("cT_46", type.getName());
+
+ assertPropertyExists(type, "id", "Int", false, false);
+ assertPropertyExists(type, "name", "String", false, false);
+
+ assertEquals( false, type.getProperty("id").isNullable() );
+ assertEquals( true, type.getProperty("name").isNullable() );
+ }
+
+ /**
+ * <complexType> containing an anySimpletype element
+ *
+ * @throws Exception
+ */
+ @Test public void testTC298ComplexTypeSetAnySimpleTypeWithStringValue() throws Exception {
+ List types = define("/complexType/cT_47.xsd");
+
+ DataObject dobj = getScope().getDataFactory().create( "http://www.example.com/xsd/47/", "cT_47" );
+ Property p = dobj.getProperty( "type_anySimpleType" );
+ assertNotNull( p );
+
+ assertEquals( "commonj.sdo", p.getType().getURI() );
+ assertEquals( "Object", p.getType().getName() );
+
+ dobj.set( "type_anySimpleType", "foo" );
+ assertEquals( "foo", dobj.get( "type_anySimpleType") );
+ }
+
+ @Test public void test_cT_48() throws IOException {
+ List types = define("/complexType/cT_48.xsd");
+ assertTrue(types.size() >= 4);
+
+ Type t1 = getType(types, "complextype1");
+ Property p1 = t1.getProperty("person");
+ assertNotNull(p1);
+
+ Type t2 = getType(types, "complextype2");
+ Property p2 = t2.getProperty("person");
+ assertNotNull(p2);
+
+ // although the 2.1 spec says that the name of the anonymous types should be the same as the name of the
+ // enclosing element or attribute, this would result in a name clash so we need to ensure that the type
+ // names are not the same
+ String typeName1 = p1.getType().getName();
+ String typeName2 = p2.getType().getName();
+ assertFalse( typeName1.equals(typeName2) );
+ }
+
+}
+
+
diff --git a/sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd/XSDSimpleTypeTest.java b/sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd/XSDSimpleTypeTest.java
new file mode 100644
index 0000000000..dfeb5cccc1
--- /dev/null
+++ b/sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd/XSDSimpleTypeTest.java
@@ -0,0 +1,364 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 test.sdo21.tests.xsd;
+
+import java.util.List;
+import java.io.File;
+
+import commonj.sdo.Type;
+import commonj.sdo.Property;
+import commonj.sdo.DataObject;
+import commonj.sdo.DataGraph;
+
+import org.junit.Test;
+import org.junit.Ignore;
+import static org.junit.Assert.*;
+
+
+public class XSDSimpleTypeTest extends XSDBaseTestCase {
+
+ /**
+ * <simpleType> with a restriction from type xs:string
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testRestriction() throws Exception {
+ List types = define("/simpleType/restriction.xsd");
+
+ // at least one type should have been returned
+ assertTrue(types.size() > 0);
+
+ Type type = getType(types, "simpleTypeRestriction");
+ assertEquals(false, type.isAbstract());
+ assertEquals(true, type.isDataType());
+ assertEquals(false, type.isOpen());
+ assertEquals(false, type.isSequenced());
+ assertEquals(0, type.getProperties().size());
+ assertEquals(1, type.getBaseTypes().size());
+ Type baseType = (Type) type.getBaseTypes().get(0);
+ assertEquals("commonj.sdo", baseType.getURI());
+ assertEquals("String", baseType.getName());
+ }
+
+ /**
+ * <element> using anonymous <simpleType>. We expect the SDO Type to have the same name as the element
+ * as per page 80 of the Java spec.
+ */
+ @Test
+ public void testAnonOpenContentProperty() throws Exception {
+ List types = define("/simpleType/anonymous.xsd");
+
+ // at least one type should have been returned
+ assertTrue(types.size() > 0);
+
+ // get open content property defined by global element in XSD
+ String uri = "http://www.example.com/simpleType/anonymous";
+ Property property = typeHelper.getOpenContentProperty(uri, "simpleTypeAnon");
+
+ assertNotNull(property);
+
+ // The spec maps the name of anonymous types to the name
+ // of their enclosing element. This is a broken method however,
+ // as it can conflict with same named types and other same
+ // named elements with anonymous types. So currently we are
+ // intentially non-compliant. using unique names for
+ // anonymous types
+
+ Type type = property.getType();
+ assertEquals(false, type.isAbstract());
+ assertEquals(true, type.isDataType());
+ assertEquals(false, type.isOpen());
+ assertEquals(false, type.isSequenced());
+ assertEquals(0, type.getProperties().size());
+ assertEquals(1, type.getBaseTypes().size());
+ Type baseType = (Type) type.getBaseTypes().get(0);
+ assertEquals("commonj.sdo", baseType.getURI());
+ assertEquals("String", baseType.getName());
+ }
+
+ /**
+ * <simpleType> with final="list"
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testFinalList() throws Exception {
+ List types = define("/simpleType/finalList.xsd");
+
+ // at least one type should have been returned
+ assertTrue(types.size() > 0);
+
+ Type type = getType(types, "simpleTypeFinalList");
+ assertEquals(false, type.isAbstract());
+ assertEquals(true, type.isDataType());
+ assertEquals(false, type.isOpen());
+ assertEquals(false, type.isSequenced());
+ assertEquals(0, type.getProperties().size());
+ assertEquals(1, type.getBaseTypes().size());
+
+ Type baseType = (Type) type.getBaseTypes().get(0);
+ assertEquals("commonj.sdo", baseType.getURI());
+ assertEquals("String", baseType.getName());
+ }
+
+ /**
+ * <simpleType> with final="union"
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testFinalUnion() throws Exception {
+ List types = define("/simpleType/finalUnion.xsd");
+
+ Type type = getType(types, "simpleTypeFinalUnion");
+ assertEquals(false, type.isAbstract());
+ assertEquals(true, type.isDataType());
+ assertEquals(false, type.isOpen());
+ assertEquals(false, type.isSequenced());
+ assertEquals(0, type.getProperties().size());
+ assertEquals(1, type.getBaseTypes().size());
+
+ Type baseType = (Type) type.getBaseTypes().get(0);
+ assertEquals("commonj.sdo", baseType.getURI());
+ assertEquals("String", baseType.getName());
+ }
+
+ /**
+ * <simpleType> with final="restriction"
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testFinalRestriction() throws Exception {
+ List types = define("/simpleType/finalRestriction.xsd");
+
+ // at least one type should have been returned
+ assertTrue(types.size() > 0);
+
+ Type type = getType(types, "simpleTypeFinalRestriction");
+ assertEquals(false, type.isAbstract());
+ assertEquals(true, type.isDataType());
+ assertEquals(false, type.isOpen());
+ assertEquals(false, type.isSequenced());
+ assertEquals(0, type.getProperties().size());
+ assertEquals(1, type.getBaseTypes().size());
+
+ Type baseType = (Type) type.getBaseTypes().get(0);
+ assertEquals("commonj.sdo", baseType.getURI());
+ assertEquals("String", baseType.getName());
+ }
+
+ /**
+ * @throws Exception
+ */
+ @Test
+ @Ignore
+ public void testDerivedType() throws Exception {
+ List types = define("/simpleType/derived.xsd");
+
+ // at least one type should have been returned
+ assertTrue(types.size() > 0);
+
+ Type type0 = getType(types, "derivedType");
+ Type type1 = getType(types, "baseType");
+
+ assertEquals("baseType", type1.getName());
+ assertEquals("derivedType", type0.getName());
+
+ assertTrue(type0.isDataType());
+ assertTrue(type1.isDataType());
+ assertFalse(type0.isOpen());
+ assertFalse(type0.isSequenced());
+ assertEquals(0, type0.getProperties().size());
+ assertEquals(1, type0.getBaseTypes().size());
+
+ List baseTypes = type0.getBaseTypes();
+ assertEquals(1, baseTypes.size());
+
+ Type baseType = (Type) baseTypes.get(0);
+ assertEquals("commonj.sdo", baseType.getURI());
+ assertEquals("Integer", baseType.getName());
+ }
+
+ /**
+ * @throws Exception
+ */
+ @Test
+ @Ignore
+ public void testDerivedType2() throws Exception {
+ List types = define("/simpleType/derived2.xsd");
+
+ // at least one type should have been returned
+ assertTrue(types.size() > 0);
+
+ Type type0 = getType(types, "baseType");
+ Type type1 = getType(types, "derivedType");
+
+ assertEquals("baseType", type0.getName());
+ assertEquals("derivedType", type1.getName());
+
+ assertTrue(type0.isDataType());
+ assertTrue(type1.isDataType());
+ assertFalse(type0.isOpen());
+ assertFalse(type0.isSequenced());
+ assertEquals(0, type0.getProperties().size());
+ assertEquals(1, type0.getBaseTypes().size());
+
+ List baseTypes = type0.getBaseTypes();
+ assertEquals(1, baseTypes.size());
+
+ Type baseType = (Type) baseTypes.get(0);
+ assertEquals("commonj.sdo", baseType.getURI());
+ assertEquals("Integer", baseType.getName());
+
+ List derivedTypes = type1.getBaseTypes();
+ assertEquals(1, derivedTypes.size());
+ Type derivedType = (Type) derivedTypes.get(0);
+
+ assertEquals("Integer", derivedType.getName());
+ }
+
+ @Test
+ public void testDerivedUnionType() throws Exception {
+ List types = define("/simpleType/derivedUnion.xsd");
+
+ // at least one type should have been returned
+ assertTrue(types.size() > 0);
+
+ Type type0 = getType(types, "fontbystringname");
+ Type type1 = getType(types, "fontbynumber");
+
+ assertEquals("fontbynumber", type1.getName());
+ assertEquals("fontbystringname", type0.getName());
+
+ assertTrue(type0.isDataType());
+ assertTrue(type1.isDataType());
+
+ assertFalse(type0.isOpen());
+ assertFalse(type0.isSequenced());
+ assertEquals(0, type0.getProperties().size());
+ assertEquals(1, type0.getBaseTypes().size());
+
+ //Get the first union type and check
+ List basetypes1 = type0.getBaseTypes();
+ assertEquals(1, basetypes1.size());
+ Type basetype1 = (Type) basetypes1.get(0);
+
+ assertEquals(basetype1.getURI(), "commonj.sdo");
+ assertEquals(basetype1.getName(), "String");
+
+ //Get the second union type and check
+ List basetypes2 = type1.getBaseTypes();
+ assertEquals(1, basetypes2.size());
+ Type basetype2 = (Type) basetypes2.get(0);
+
+ assertEquals(basetype2.getName(), "Integer");
+ }
+
+ /**
+ * <simpleType> containing <annotation> (no effect on SDO type but want to make
+ * sure we can parse it ok)
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testAnnotation() throws Exception {
+ List types = define("/simpleType/annotation.xsd");
+
+ // at least one type should have been returned
+ assertTrue(types.size() > 0);
+
+ Type type = getType(types, "simpleTypeAnnotated");
+ assertEquals(false, type.isAbstract());
+ assertEquals(true, type.isDataType());
+ assertEquals(false, type.isOpen());
+ assertEquals(false, type.isSequenced());
+ assertEquals(0, type.getProperties().size());
+ assertEquals(1, type.getBaseTypes().size());
+
+ Type baseType = (Type) type.getBaseTypes().get(0);
+ assertEquals("commonj.sdo", baseType.getURI());
+ assertEquals("String", baseType.getName());
+ }
+
+ /**
+ * <simpleType> containing <list>
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testTC200SimpleType() throws Exception {
+ List types = define("/simpleType/list.xsd");
+
+ Type type = getType(types, "simpleTypeList");
+ assertEquals(false, type.isAbstract());
+ assertEquals(true, type.isDataType());
+ assertEquals(false, type.isOpen());
+ assertEquals(false, type.isSequenced());
+ assertEquals(0, type.getProperties().size());
+ assertEquals(0, type.getBaseTypes().size());
+ }
+
+ @Test
+ public void testEnumeration() throws Exception {
+ List types = define("/simpleType/enumeration.xsd");
+
+ // at least one type should have been returned
+ assertTrue(types.size() > 0);
+
+ Type thing = getType(types, "thing");
+ Property colorofthing = thing.getProperty("colorofthing");
+ Property sizeofthing = thing.getProperty("sizeofthing");
+
+ assertEquals("thing", thing.getName());
+ assertEquals("colorofthing", colorofthing.getName());
+ assertEquals("sizeofthing", sizeofthing.getName());
+
+ DataObject dobj = dataFactory.create(thing.getURI(), thing.getName());
+ dobj.setInt("sizeofthing", 2);
+ dobj.setString("colorofthing", "red");
+
+ assertEquals("red", dobj.getString("colorofthing"));
+ assertEquals(2, dobj.getInt("sizeofthing"));
+ }
+
+ /**
+ * <simpleType> containing <union>
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testUnion() throws Exception {
+ List types = define("/simpleType/union.xsd");
+
+ // at least one type should have been returned
+ assertTrue(types.size() > 0);
+
+ Type type = getType(types, "simpleTypeUnion");
+ assertEquals(false, type.isAbstract());
+ assertEquals(true, type.isDataType());
+ assertEquals(false, type.isOpen());
+ assertEquals(false, type.isSequenced());
+ assertEquals(0, type.getProperties().size());
+ assertEquals(0, type.getBaseTypes().size());
+ }
+
+}