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/05/09 17:47:43 UTC
svn commit: r536572 - in /incubator/tuscany/java/cts:
sdo2.1-tuscany/src/main/java/test/sdo21/vendor/tuscany/testHelper/
sdo2.1/src/main/java/test/sdo21/framework/
sdo2.1/src/main/java/test/sdo21/paramatizedTests/general/
sdo2.1/src/main/java/test/sdo2...
Author: kelvingoodson
Date: Wed May 9 08:47:42 2007
New Revision: 536572
URL: http://svn.apache.org/viewvc?view=rev&rev=536572
Log:
Beginning to make some of the CTS improvements discussed on tuscany-dev.
Modified:
incubator/tuscany/java/cts/sdo2.1-tuscany/src/main/java/test/sdo21/vendor/tuscany/testHelper/TuscanyTestHelper.java
incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/framework/CTSTestCase.java
incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/framework/ParameterFactory.java
incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/framework/TestHelper.java
incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/general/ActiveUpdatingTest.java
incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/general/ContainmentTest.java
incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/api/DataObjectTest.java
incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XSDHelperTest.java
Modified: incubator/tuscany/java/cts/sdo2.1-tuscany/src/main/java/test/sdo21/vendor/tuscany/testHelper/TuscanyTestHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1-tuscany/src/main/java/test/sdo21/vendor/tuscany/testHelper/TuscanyTestHelper.java?view=diff&rev=536572&r1=536571&r2=536572
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1-tuscany/src/main/java/test/sdo21/vendor/tuscany/testHelper/TuscanyTestHelper.java (original)
+++ incubator/tuscany/java/cts/sdo2.1-tuscany/src/main/java/test/sdo21/vendor/tuscany/testHelper/TuscanyTestHelper.java Wed May 9 08:47:42 2007
@@ -1,4 +1,4 @@
-/*
+/**
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -16,8 +16,6 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- *
- * $Rev$ $Date$
*/
package test.sdo21.vendor.tuscany.testHelper;
@@ -113,8 +111,8 @@
* arguments to paramatized test cases. DataObjects should adhere to
* api_test.xsd and should be populated. The String should be a description
* of the mechanism used to create and populate the DataObject. See
- * {@link test.sdo21.vendor.tuscany.testHelper.TuscanyTestHelper} for
- * examples.
+ * {@link test.sdo21.vendor.tuscany.testHelper.TuscanyTestHelper}
+ * for examples.
*
* @return
*/
@@ -196,25 +194,7 @@
return SDOUtil.createHelperContext();
}
- /*
- * (non-Javadoc)
- *
- * @see test.sdo21.framework.TestHelper#registerStaticTypes(java.lang.Class)
- */
- public void registerStaticTypes(Class factoryClass) {
- try {
- Object regClass = factoryClass.newInstance();
- Class[] regMethodSig = new Class[] {HelperContext.class};
- Method regMethod = factoryClass.getDeclaredMethod("register", regMethodSig);
- regMethod.invoke(regClass, new Object[] {factoryClass});
- } catch (Throwable e) {
- logger.log(Level.WARNING,
- "Exception {} caught, will use deprecated method SDOUtil.registerStaticTypes() ",
- e);
- SDOUtil.registerStaticTypes(factoryClass);
- }
- }
-
+
/**
* Create a new DataObjectFactory
* @return the new DataObjectFactory instance.
Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/framework/CTSTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/framework/CTSTestCase.java?view=diff&rev=536572&r1=536571&r2=536572
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/framework/CTSTestCase.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/framework/CTSTestCase.java Wed May 9 08:47:42 2007
@@ -19,8 +19,16 @@
*/
package test.sdo21.framework;
+import junit.framework.TestCase;
import commonj.sdo.helper.HelperContext;
+/**
+ * A superclass for tests classes. It creates a HelperContext per test case invocation
+ * and provides initialization/access to the implementation sepcific test helper.
+ * See also the {@link test.sdo21.framework.junit3_8.CTSTestCase} Junit 3.8 variant of this
+ * class which inherits from {@link TestCase} in the junit 3.8 style of testing,
+ * but delegates to this class for much of its CTS function.
+ */
public class CTSTestCase {
private static TestHelper testHelper = null;
Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/framework/ParameterFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/framework/ParameterFactory.java?view=diff&rev=536572&r1=536571&r2=536572
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/framework/ParameterFactory.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/framework/ParameterFactory.java Wed May 9 08:47:42 2007
@@ -181,7 +181,7 @@
testDO.setLong("longVal", (long)88881113);
List children = new ArrayList();
children.add(getScope().getDataFactory().create(testDO.getType()));
- testDO.setList("children", children);
+ testDO.setList("containMany", children);
testDO.setBytes("bytesVal", new byte[] {120, 80, -40});
testDO.setBigInteger("integerVal", new BigInteger("88819313"));
testDO.setChar("charVal", '*');
Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/framework/TestHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/framework/TestHelper.java?view=diff&rev=536572&r1=536571&r2=536572
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/framework/TestHelper.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/framework/TestHelper.java Wed May 9 08:47:42 2007
@@ -33,6 +33,8 @@
import java.io.InputStream;
//import javax.xml.stream.XMLStreamWriter;
+import test.sdo21.tests.util.CTSUtil;
+
/**
* Vendors can provide an implementation of this interface to bootstrap their
* SDO implementation.
@@ -63,6 +65,8 @@
* @param name
* @param helperContext
* @return
+ * @deprecated
+ * @see CTSUtil
*/
public DataObject createTypeDef(String uri, String name, boolean open, HelperContext helperContext);
@@ -75,6 +79,8 @@
* @param isMany
* @param isContainment
* @return
+ * @deprecated
+ * @see CTSUtil
*/
public DataObject createPropertyDef(DataObject typeDef,
String name,
@@ -93,6 +99,10 @@
* @param isContainment
* @param helperContext
* @return
+ *
+ * @deprecated
+ * @see CTSUtil
+
*/
public DataObject createPropertyDef(DataObject typeDef,
String name,
@@ -104,8 +114,12 @@
/**
* Convenience method for creating a unique name that can be used for a
* property or type.
- *
+ *
* @return String containing a unique name
+ *
+ * @deprecated
+ * @see CTSUtil
+
*/
public String createUniqueName();
Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/general/ActiveUpdatingTest.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/general/ActiveUpdatingTest.java?view=diff&rev=536572&r1=536571&r2=536572
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/general/ActiveUpdatingTest.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/general/ActiveUpdatingTest.java Wed May 9 08:47:42 2007
@@ -82,12 +82,12 @@
returnedList.add(child2);
- assertEquals("Update to returned List did not affect DataObject correctly. Size of containMany is not 2", root
- .getList("containMany").size(), 2);
- assertEquals("Update to returned List did not affect DataObject correctly. child1 is equal to root", child1
- .getContainer(), root);
- assertEquals("Update to returned List did not affect DataObject correctly. child2 is equal to root", child2
- .getContainer(), root);
+ assertEquals("Update to returned List did not affect DataObject correctly. Size of children is not 2",
+ 2, root.getList("containMany").size());
+ assertEquals("Update to returned List did not affect DataObject correctly. child1's container is not equal to root",
+ root, child1.getContainer());
+ assertEquals("Update to returned List did not affect DataObject correctly. child2's container is not equal to root",
+ root, child2.getContainer());
/**
* Delete a child and verify that the returned List is automatically
Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/general/ContainmentTest.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/general/ContainmentTest.java?view=diff&rev=536572&r1=536571&r2=536572
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/general/ContainmentTest.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/general/ContainmentTest.java Wed May 9 08:47:42 2007
@@ -57,9 +57,9 @@
}
@Before
- public void setUp () {
- testDO = factory.createTestAPIObject();
- helperContext = factory.getHelperContext();
+ public void setUp() throws Exception {
+ testDO = factory.createTestAPIObject();
+ helperContext = factory.getHelperContext();
}
/**
Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/api/DataObjectTest.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/api/DataObjectTest.java?view=diff&rev=536572&r1=536571&r2=536572
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/api/DataObjectTest.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/api/DataObjectTest.java Wed May 9 08:47:42 2007
@@ -31,34 +31,46 @@
import test.sdo21.CTSSuite;
import test.sdo21.framework.TestHelper;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import test.sdo21.framework.CTSTestCase;
+import test.sdo21.tests.util.CTSUtil;
+
import commonj.sdo.DataObject;
-import commonj.sdo.Type;
import commonj.sdo.Property;
-import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.Type;
+import commonj.sdo.helper.HelperContext;
import commonj.sdo.helper.HelperContext;
/**
* Set of tests for DataObject APIs.
+ * Currently limited to a fairly narrow set of tests on the set(Property, value), isSet(), and unSet()
+ * methods.
+ * <p/>
+ * TODO Need to extend the test set or migrate tests from other existing tests as yet unidentified.
*/
-public class DataObjectTest {
- private static TestHelper testHelper;
- private boolean debug = false;
+public class DataObjectTest extends CTSTestCase {
- /**
- * set the testHelper for the class of test cases
- */
- @BeforeClass
- public static void setTestHelper() {
- testHelper = CTSSuite.getTestHelper();
+ private boolean debug = false;
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
}
+
/**
* This test checks that getInstanceProperties returns all properties
* defined by the DataObject's type, regardless of whether they are set or
* not. It also checks that open content properties only appear in
* getInstanceProperties if they are set. Related sections in the
- * specification are 3.1.1 / 3.1.9 / 3.1.11 Related JIRA SDO-179
- *
+ * specification are / 3.1.9 / 3.1.11 Related JIRA SDO-179
+ * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=14">2.1 spec section 3.1.1</a>
+ * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=18">2.1 spec section 3.1.9</a>
+ * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=20">2.1 spec section 3.1.11</a>
+ * @see <a href="http://www.xcalia.com/support/browse/SDO-179">SDO Spec JIRA 179</a>
* @throws Exception
*/
@Test
@@ -66,11 +78,11 @@
public void testGetInstancePropertiesSize() throws Exception {
// define a type with two properties
- HelperContext helperContext = testHelper.createHelperContext();
- String typeName = testHelper.createUniqueName();
- DataObject typeDef = testHelper.createTypeDef("", typeName, true, helperContext);
- testHelper.createPropertyDef(typeDef, "p1", "commonj.sdo#String", false, false, helperContext);
- testHelper.createPropertyDef(typeDef, "p2", "commonj.sdo#String", false, false, helperContext);
+ HelperContext helperContext = getScope();
+ String typeName = getTypeName();
+ DataObject typeDef = CTSUtil.createTypeDef("", typeName, true, helperContext);
+ CTSUtil.createPropertyDef(typeDef, "p1", "commonj.sdo#String", false, false, helperContext);
+ CTSUtil.createPropertyDef(typeDef, "p2", "commonj.sdo#String", false, false, helperContext);
helperContext.getTypeHelper().define(typeDef);
// create a DataObject that uses this type
@@ -106,14 +118,22 @@
assertEquals(2, dobj.getInstanceProperties().size());
}
+ /**
+ * Tests an isMany=false Boolean type property in an open type for being set to false/unset.
+ * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=16">2.1 spec section 3.1.5</a>
+ * @see commonj.sdo.DataObject#isSet()
+ * @see commonj.sdo.DataObject#unset()
+ * @see commonj.sdo.DataObject#set(Property, Boolean)
+ * @throws Exception
+ */
@Test
public void testIsSet_Boolean_false() throws Exception {
// define a type with two properties
- HelperContext helperContext = testHelper.createHelperContext();
- String typeName = testHelper.createUniqueName();
- DataObject typeDef = testHelper.createTypeDef("", typeName, true, helperContext);
- testHelper.createPropertyDef(typeDef, "b1", "commonj.sdo#Boolean", false, false, helperContext);
+ HelperContext helperContext = getScope();
+ String typeName = getTypeName();
+ DataObject typeDef = CTSUtil.createTypeDef("", typeName, true, helperContext);
+ CTSUtil.createPropertyDef(typeDef, "b1", "commonj.sdo#Boolean", false, false, helperContext);
helperContext.getTypeHelper().define(typeDef);
// create a DataObject that uses this type
@@ -121,20 +141,28 @@
Property p = testDO.getInstanceProperty("b1");
testDO.unset(p);
- assertFalse("testing that property is unset after unset is called", testDO.isSet(p));
+ assertFalse("Property was set", testDO.isSet(p));
testDO.set(p, false);
- assertTrue("testing that property is set after setting to false, value of property is " + testDO.get(p), testDO
- .isSet(p));
+ assertTrue("Property was not set ", testDO.isSet(p));
}
+ /**
+ * Tests an isMany=false Boolean type property in an open type for being set to true/unset.
+ * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=16">2.1 spec section 3.1.5</a>
+ * @see commonj.sdo.DataObject#getInstanceProperty(String)
+ * @see commonj.sdo.DataObject#isSet()
+ * @see commonj.sdo.DataObject#unset()
+ * @see commonj.sdo.DataObject#set(Property, Boolean)
+ * @throws Exception
+ */
@Test
public void testIsSet_Boolean_true() throws Exception {
// define a type with two properties
- HelperContext helperContext = testHelper.createHelperContext();
- String typeName = testHelper.createUniqueName();
- DataObject typeDef = testHelper.createTypeDef("", typeName, true, helperContext);
- testHelper.createPropertyDef(typeDef, "b1", "commonj.sdo#Boolean", false, false, helperContext);
+ HelperContext helperContext = getScope();
+ String typeName = getTypeName();
+ DataObject typeDef = CTSUtil.createTypeDef("", typeName, true, helperContext);
+ CTSUtil.createPropertyDef(typeDef, "b1", "commonj.sdo#Boolean", false, false, helperContext);
helperContext.getTypeHelper().define(typeDef);
// create a DataObject that uses this type
@@ -142,20 +170,28 @@
Property p = testDO.getInstanceProperty("b1");
testDO.unset(p);
- assertFalse("testing that property is unset after unset is called", testDO.isSet(p));
+ assertFalse("Property was set", testDO.isSet(p));
testDO.set(p, true);
- assertTrue("testing that property is set after setting to true, value of property is " + testDO.get(p), testDO
+ assertTrue("Property was not set " + testDO.get(p), testDO
.isSet(p));
}
+ /**
+ * Tests isSet() of Integer property where isMany = false in an open type.
+ * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=16">2.1 spec section 3.1.5</a>
+ * @see commonj.sdo.DataObject#isSet()
+ * @see commonj.sdo.DataObject#unset()
+ * @see commonj.sdo.DataObject#set(Property, Integer)
+ * @throws Exception
+ */
@Test
public void testIsSet_Integer_0() throws Exception {
// define a type with two properties
- HelperContext helperContext = testHelper.createHelperContext();
- String typeName = testHelper.createUniqueName();
- DataObject typeDef = testHelper.createTypeDef("", typeName, true, helperContext);
- testHelper.createPropertyDef(typeDef, "i1", "commonj.sdo#Integer", false, false, helperContext);
+ HelperContext helperContext = getScope();
+ String typeName = getTypeName();
+ DataObject typeDef = CTSUtil.createTypeDef("", typeName, true, helperContext);
+ CTSUtil.createPropertyDef(typeDef, "i1", "commonj.sdo#Integer", false, false, helperContext);
helperContext.getTypeHelper().define(typeDef);
// create a DataObject that uses this type
@@ -163,50 +199,65 @@
Property p = testDO.getInstanceProperty("i1");
testDO.unset(p);
- assertFalse("testing that property is unset after unset is called", testDO.isSet(p));
+ assertFalse("Property was set", testDO.isSet(p));
testDO.set(p, java.math.BigInteger.valueOf(0));
- assertTrue("testing that property is set after setting to 0, value of property is " + testDO.get(p), testDO
- .isSet(p));
+ assertTrue("Property was not set" + testDO.get(p), testDO.isSet(p));
}
+ /**
+ * Ensures correct behaviour (returns null) on attempting to get a non existent property in an open type.<br/>
+ * Tests isSet() after unset() and set() on isMany=false property
+ * @see commonj.sdo.DataObject#getInstanceProperty(String)
+ * @see commonj.sdo.DataObject#isSet()
+ * @see commonj.sdo.DataObject#unset()
+ * @see commonj.sdo.DataObject#set(Property, Integer)
+ * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=16">2.1 spec section 3.1.5</a>
+ * @throws Exception
+ */
@Test
public void testIsSet_Integer_1() throws Exception {
- // define a type with two properties
- HelperContext helperContext = testHelper.createHelperContext();
- String typeName = testHelper.createUniqueName();
- DataObject typeDef = testHelper.createTypeDef("", typeName, true, helperContext);
- testHelper.createPropertyDef(typeDef, "i1", "commonj.sdo#Integer", false, false, helperContext);
+ HelperContext helperContext = getScope();
+ String typeName = getTypeName();
+ DataObject typeDef = CTSUtil.createTypeDef("", typeName, true, helperContext);
+ CTSUtil.createPropertyDef(typeDef, "i1", "commonj.sdo#Integer", false, false, helperContext);
helperContext.getTypeHelper().define(typeDef);
// create a DataObject that uses this type
DataObject testDO = helperContext.getDataFactory().create("", typeName);
try {
Property p = testDO.getInstanceProperty("default");
- System.out.println(" default " + p);
+ assertTrue("non null return for non-existent property in an open type", p==null);
} catch (Exception e) {
- System.out.println("coudl not get default " + e.toString());
+ assertTrue("getInstanceProperty throws exception for non-existent property "+e, false);
}
Property p = testDO.getInstanceProperty("i1");
testDO.unset(p);
- assertFalse("testing that property is unset after unset is called", testDO.isSet(p));
+ assertFalse("Property was set ", testDO.isSet(p));
testDO.set(p, java.math.BigInteger.valueOf(1));
- assertTrue("testing that property is set after setting to 1, value of property is " + testDO.get(p), testDO
- .isSet(p));
+ assertTrue("Property was not set ", testDO.isSet(p));
}
+ /**
+ * Tests isSet() after unset() and set() on isMany=false property of type Int in an open type
+ * @see commonj.sdo.DataObject#getInstanceProperty(String)
+ * @see commonj.sdo.DataObject#isSet()
+ * @see commonj.sdo.DataObject#unset()
+ * @see commonj.sdo.DataObject#set(Property, Integer)
+ * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=16">2.1 spec section 3.1.5</a>
+ * @throws Exception
+ */
@Test
public void testIsSet_int_1() throws Exception {
- // define a type with two properties
- HelperContext helperContext = testHelper.createHelperContext();
- String typeName = testHelper.createUniqueName();
- DataObject typeDef = testHelper.createTypeDef("", typeName, true, helperContext);
+ HelperContext helperContext = getScope();
+ String typeName = getTypeName();
+ DataObject typeDef = CTSUtil.createTypeDef("", typeName, true, helperContext);
Type intType = helperContext.getTypeHelper().getType("commonj.sdo", "Int");
- testHelper.createPropertyDef(typeDef, "i1", intType, false, false);
+ CTSUtil.createPropertyDef(typeDef, "i1", intType, false, false);
helperContext.getTypeHelper().define(typeDef);
// create a DataObject that uses this type
@@ -214,23 +265,25 @@
Property p = testDO.getInstanceProperty("i1");
testDO.unset(p);
- assertFalse("testing that property is unset after unset is called", testDO.isSet(p));
+ assertFalse("Property was not unset", testDO.isSet(p));
testDO.set(p, 1);
- assertTrue("testing that property is set after setting to 1, value of property is " + testDO.get(p), testDO
- .isSet(p));
+ assertTrue("Property was not set " , testDO.isSet(p));
}
+ /**
+ * Tests an open type
+ * @throws Exception
+ */
@Test
public void testIsSet_int_0() throws Exception {
try {
- // define a type with two properties
- HelperContext helperContext = testHelper.createHelperContext();
- String typeName = testHelper.createUniqueName();
- DataObject typeDef = testHelper.createTypeDef("", typeName, true, helperContext);
+ HelperContext helperContext = getScope();
+ String typeName = getTypeName();
+ DataObject typeDef = CTSUtil.createTypeDef("", typeName, true, helperContext);
Type intType = helperContext.getTypeHelper().getType("commonj.sdo", "Int");
- testHelper.createPropertyDef(typeDef, "i1", intType, false, false);
+ CTSUtil.createPropertyDef(typeDef, "i1", intType, false, false);
helperContext.getTypeHelper().define(typeDef);
// create a DataObject that uses this type
@@ -238,19 +291,26 @@
Property p = testDO.getInstanceProperty("i1");
testDO.unset(p);
- assertFalse("testing that property is unset after unset is called", testDO.isSet(p));
+ assertFalse("Property was set", testDO.isSet(p));
testDO.set(p, 0);
if (debug) {
- XMLHelper.INSTANCE.save(testDO, "http://www.example.com/api_test", "apiTestElem", System.out);
+ helperContext.getXMLHelper().save(testDO, "http://www.example.com/api_test", "apiTestElem", System.out);
}
- assertTrue("testing that property is set after setting to 1, value of property is " + testDO.get(p), testDO
- .isSet(p));
+ assertTrue("Property was not set", testDO.isSet(p));
} catch (Exception e) {
- System.out.println("exception " + e.toString());
- e.printStackTrace();
- throw e;
+ assertFalse("No exception expected: received " + e.toString(), true);
}
+ }
+
+ /*
+ * KG -- keeping an indirection here temporarily since I think we can dispense with the need for
+ * a unique property name now that we use a fresh HelperContext per test method. TODO Remove this
+ * method when sure.
+ */
+ private String getTypeName() {
+ // return CTSUtil.createUniqueName();
+ return "T1";
}
}
Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XSDHelperTest.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XSDHelperTest.java?view=diff&rev=536572&r1=536571&r2=536572
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XSDHelperTest.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XSDHelperTest.java Wed May 9 08:47:42 2007
@@ -60,10 +60,14 @@
import commonj.sdo.helper.XSDHelper;
/**
- * Junit 4.1 test case. Tests XSD serialization/deserialization.
+ * Tests XSD serialization/deserialization.<p/>
+ * This tests requires extension by import or creation of further tests.
+ * It currently only tests one flavour of {@link XSDHelper#define(java.io.InputStream, String)} and {@link XSDHelper#generate(List)})
+ *
+ * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=52">2.1 spec section 3.13</a>
+ * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=56">2.1 spec section 4</a>
*
*/
-// FIXME ensure that the inherited HelperContext stuff is consistent with the test case code
public class XSDHelperTest extends CTSTestCase {
private static final String TEST_MODEL = "/simple.xsd";
private XmlSchemaCollection col = new XmlSchemaCollection();
@@ -87,8 +91,9 @@
}
/**
- * Verifies the performance of XSDHelper.define() when a SchemaLocation is
- * provided.
+ * Verifies the performance of XSDHelper.define() when a SchemaLocation is provided.
+ * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=52">2.1 spec section 3.13</a>
+ * @see commonj.sdo.XSDHelper#define(InputStream, String)
*/
@Test
public void testDefineWithLocation() {
@@ -97,17 +102,22 @@
XSDHelper xsdHelper = getScope().getXSDHelper();
List types = xsdHelper.define(modelURL.openStream(), modelURL.toString());
checkTypes(modelURL, getScope().getTypeHelper(), types);
- //assertEquals("XSDHelper.define() did not create the expected number of Types", 2, types.size());
- } catch (Exception e) {
- e.printStackTrace();
+ } catch (Exception e) {
fail("Exception calling xsdHelper.define" + e.toString());
}
}
+ /**
+ * Utility method to ensure that the set of types in the list includes all those explicity
+ * defined in the schema<p>
+ * Checking xsd type definition post condition ---<br/>
+ * <i>for all t in schemaTypes there exists a t' in types such that QName(t) == QName(t')</i>
+ * @param modelUrl location of the schema related to the set of types
+ * @param typeHelper associated with the scope for the types in the list
+ * @param types
+ */
private void checkTypes(URL modelUrl, TypeHelper typeHelper, List types) {
- // Checking xsd type definition post condition ---
- // for all t in schemaTypes there exists a t' in types such that QName(t) == QName(t')
try {
XmlSchema schema = col.read(new StreamSource(modelUrl.openStream()), null);
XmlSchemaObjectTable schemaTypes = schema.getSchemaTypes();
@@ -118,19 +128,19 @@
schemaType = it.next();
QName qname = schemaType.getQName();
Type sdoType = typeHelper.getType(qname.getNamespaceURI(), qname.getLocalPart());
- assertNotNull("Type not known to SDO environment "+ qname, sdoType);
- assertTrue("Sdo type not created from this invokation of type definition", types.contains(sdoType));
+ assertNotNull("Type not known to SDO environment: "+ qname, sdoType);
+ assertTrue("Sdo type not created from this invocation of type definition", types.contains(sdoType));
}
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- fail("Exception parsing schema");
+
+ fail("Exception parsing schema" + e);
}
}
/**
- * Verifies the performance of XSDHelper.define() when a SchemaLocation is
- * not provided.
+ * Verifies the performance of XSDHelper.define() when a SchemaLocation is not provided.
+ * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=52">2.1 spec section 3.13</a>
+ * @see commonj.sdo.XSDHelper#define(InputStream, String)
*/
@Test
public void testDefineWithNoLocation() {
@@ -148,13 +158,15 @@
/**
* Verifies that duplicate Types are not redefined.
+ * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=52">2.1 spec section 3.13</a>
+ * @see commonj.sdo.XSDHelper#define(InputStream, String)
*/
@Test
public void testDuplicateDefineWithLocation() {
try {
XSDHelper xsdHelper = getScope().getXSDHelper();
List types = xsdHelper.define(modelURL.openStream(), modelURL.toString());
- assertEquals("XSDHelper.define() did not create the expected number of Types", 2, types.size());
+ assertTrue("XSDHelper.define() did not create the expected number of Types", types.size() > 0);
// redefine type
List duplicateTypes = xsdHelper.define(modelURL.openStream(), modelURL.toString());
assertEquals("XSDHelper.define() did not create the expected number of Types", 0, duplicateTypes.size());
@@ -166,8 +178,11 @@
}
/**
- * Verifies the performance of XSDHelper.generate for dynamic SDOs with no
- * XSD model.
+ * Verifies the performance of XSDHelper.generate for dynamic SDOs with no XSD model.<p/>
+ * Could improve this by postconditions on generated schema.
+ * @see commonj.sdo.XSDHelper#generate(InputStream, String)
+ * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=53">2.1 spec section 3.13.2</a>
+ * @see <a href="http://osoa.org/download/attachments/36/Java-SDO-Spec-v2.1.0-FINAL.pdf?version=1#page=56">2.1 spec section 4</a>
*/
@Test
public void testXSDGeneration_DynamicSDOType() {
@@ -205,13 +220,14 @@
try {
xsd = xsdHelper.generate(types);
- // System.out.println(xsd);
+ assertNotNull("XSDHelper.generate() did not complete as expected for dynamic SDOs with no XSD model. Exception was thrown",
+ xsd);
} catch (IllegalArgumentException e) {
fail("XSDHelper.generate() did not complete as expected for dynamic SDOs with no XSD model. Exception was thrown : " + e
.toString());
+ } catch (Exception e) {
+ fail("Exception caught when generating a schema");
}
- assertNotNull("XSDHelper.generate() did not complete as expected for dynamic SDOs with no XSD model. Exception was thrown",
- xsd);
} catch (Exception e) {
e.printStackTrace();
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org