You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ke...@apache.org on 2007/03/29 11:23:08 UTC
svn commit: r523648 -
/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/api/XMLWithoutSchemaTest.java
Author: kelvingoodson
Date: Thu Mar 29 02:23:06 2007
New Revision: 523648
URL: http://svn.apache.org/viewvc?view=rev&rev=523648
Log:
TUSCANY=-1191 committed new test case
Added:
incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/api/XMLWithoutSchemaTest.java (with props)
Added: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/api/XMLWithoutSchemaTest.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/api/XMLWithoutSchemaTest.java?view=auto&rev=523648
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/api/XMLWithoutSchemaTest.java (added)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/api/XMLWithoutSchemaTest.java Thu Mar 29 02:23:06 2007
@@ -0,0 +1,125 @@
+/*
+ * 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.api;
+
+import junit.framework.TestCase;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XMLDocument;
+import commonj.sdo.DataObject;
+import commonj.sdo.Property;
+
+/**
+ * This tests compliance with section 9.10 of the SDO 2.1 Java specification.
+ */
+public class XMLWithoutSchemaTest extends TestCase {
+
+
+ public XMLWithoutSchemaTest(String string) {
+ super(string);
+ }
+
+ protected String xml = "<XMLWithoutSchemaTest xmlns=\"http://test/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
+ "<person id=\"1\"><name>Joe</name><age xsi:type=\"int\">21</age></person>" +
+ "<person id=\"2\"><name>Sam</name><age xsi:type=\"int\">40</age></person>" +
+ "</XMLWithoutSchemaTest>";
+
+ public void testRootObject() {
+ // section 9.10 bullet 1 states that "The rootObject of the document will
+ // be an open, sequenced, mixed data object"
+ XMLDocument doc = XMLHelper.INSTANCE.load( xml );
+ DataObject root = doc.getRootObject();
+ assertTrue( root.getType().isOpen() );
+ assertTrue( root.getType().isSequenced() );
+ }
+
+ public void testAttributeProperties() {
+ // section 9.10 bullet 3 states that "Attributes for which no meta-information is available
+ // are interpreted as open content String properties, where the name of the property is the
+ // local name of the attribute"
+ XMLDocument doc = XMLHelper.INSTANCE.load( xml );
+ DataObject root = doc.getRootObject();
+ DataObject person = root.getDataObject( "person.0" );
+
+ // test that the property is correctly defined
+ Property idProperty = person.getInstanceProperty( "id" );
+ assertTrue( idProperty.isOpenContent() );
+ assertTrue( idProperty.getType().isDataType() );
+ assertEquals( "String", idProperty.getType().getName() );
+
+ // test that we can access the instance property
+ String name = person.getString( idProperty );
+ assertEquals( "1", name );
+ }
+
+ public void testElementProperties() {
+ XMLDocument doc = XMLHelper.INSTANCE.load( xml );
+ DataObject root = doc.getRootObject();
+
+ // section 9.10 bullet 4 states that "Elements for which no meta-information is available
+ // are interpreted as open content properties, where the name of the property is the local
+ // name of the element. The property will always have containment=true."
+ Property personProperty = root.getInstanceProperty( "person" );
+ assertTrue( personProperty.isContainment() );
+
+ // section 9.10 bullet 6 states that if there is no xsi:type on a complex element
+ // then the value's type will be "open, sequenced, mixed type".
+ assertTrue( personProperty.isOpenContent() );
+ assertTrue( personProperty.getType().isSequenced() );
+
+ // section 9.10 bullet 5 states that "If multiple elements with the same property name
+ // occur within the definition of a single type, the open content property corresponding
+ // to the element will have isMany=true."
+ assertTrue( personProperty.isMany() );
+
+ // test that we can access the instance property
+ DataObject person = root.getDataObject( personProperty );
+ assertNotNull( person );
+ }
+
+ public void testComplexElementWithXsiType() {
+ XMLDocument doc = XMLHelper.INSTANCE.load( xml );
+ DataObject root = doc.getRootObject();
+ // section 9.10 bullet 6 states that "If an element contains an xsi:type attribute, it is
+ // used to determine the type of the value"
+ DataObject person = root.getDataObject( "person.0" );
+ Property ageProperty = person.getInstanceProperty( "age" );
+ assertEquals( "commonj.sdo", ageProperty.getType().getURI() );
+ assertEquals( "Int", ageProperty.getType().getName() );
+ }
+
+ public void testElementsWithSimpleContent() {
+ // section 9.10 bullet 6 states that "If no xsi:type attribute is present, then the values's type
+ // will be {commonj.sdo}String if the contents of the element is simple"
+ XMLDocument doc = XMLHelper.INSTANCE.load( xml );
+ DataObject root = doc.getRootObject();
+ DataObject person = root.getDataObject( "person.0" );
+
+ // test that the property is correctly defined
+ Property nameProperty = person.getInstanceProperty( "name" );
+ assertTrue( nameProperty.isOpenContent() );
+ assertTrue( nameProperty.getType().isDataType() );
+ assertEquals( "String", nameProperty.getType().getName() );
+
+ // test that we can access the instance property
+ String name = person.getString( nameProperty );
+ assertEquals( "Joe", name );
+ }
+
+}
Propchange: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/api/XMLWithoutSchemaTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/api/XMLWithoutSchemaTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org