diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-10 21:17:39 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-10 21:17:39 +0000 |
commit | eb11fd83f7908876fe6041086d6025c9468de672 (patch) | |
tree | 7475c93a5adceca4829d5c7bf6631d4b09749f4b /sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd/XSDSimpleTypeTest.java | |
parent | 39a3e278e786438a92428fe13646d09f3441d2e6 (diff) |
Moving SDO CTS
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@834672 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd/XSDSimpleTypeTest.java')
-rw-r--r-- | sdo-java/trunk-cts/sdo2.1/src/main/java/test/sdo21/tests/xsd/XSDSimpleTypeTest.java | 364 |
1 files changed, 364 insertions, 0 deletions
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()); + } + +} |