You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by gw...@apache.org on 2007/02/27 13:54:59 UTC
svn commit: r512241 [3/5] - in /incubator/tuscany/java/cts: sdo2.1-tuscany/
sdo2.1-tuscany/src/test/java/test/sdo21/vendor/tuscany/tests/ sdo2.1/
sdo2.1/src/main/java/test/sdo21/ sdo2.1/src/main/java/test/sdo21/framework/
sdo2.1/src/main/java/test/sdo2...
Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/api/TypeTest.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/api/TypeTest.java?view=diff&rev=512241&r1=512240&r2=512241
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/api/TypeTest.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/api/TypeTest.java Tue Feb 27 04:54:57 2007
@@ -25,16 +25,19 @@
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.util.List;
import org.junit.Test;
+import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import test.sdo21.CTSSuite;
import test.sdo21.paramatizedTests.BaseSDOParamatizedTest;
import test.sdo21.paramatizedTests.util.ParamatizedTestUtil;
+import test.sdo21.framework.TestHelper;
import commonj.sdo.DataObject;
import commonj.sdo.Property;
@@ -46,117 +49,237 @@
*/
@RunWith(Parameterized.class)
public class TypeTest extends BaseSDOParamatizedTest {
-
public TypeTest(DataObject testDO, String description) {
super(testDO, description);
}
/**
- * testTypeAPI is used to test the methods of the Type object their return
- * values.
- *
- * @param testDO
- * @throws ReturnValueError
+ * Verify the value returned by Type.getName()
*/
@Test
- public void testTypeAPI() {
+ public void typeGetName() {
Type type = testDO.getType();
- Type booleanType = testDO.getProperty("booleanVal").getType();
- Type sequencedType = testDO.getProperty("sequencedElem").getType();
- Type abstractType = CTSSuite.getTestHelper().getTypeHelper().getType(ParamatizedTestUtil.TEST_NAMESPACE, "Abstract");
- Class instanceClass;
+ assertEquals("Type.getName() returned an unexpected value.", ParamatizedTestUtil.TEST_TYPE, type.getName());
+ }
+
+ /**
+ * Verify the value returned by Type.getURI()
+ */
+ @Test
+ public void typeGetURI() {
+ Type type = testDO.getType();
+ assertEquals("Type.getURI() returned an unexpected value.", ParamatizedTestUtil.TEST_NAMESPACE, type.getURI());
+ }
- /**
- * Verify the accuracy of Type.getName() and Type.getURI()
- */
-
- assertEquals("Type.getName() returned an unexpected value.", type.getName(), ParamatizedTestUtil.TEST_TYPE);
- assertEquals("Type.getURI() returned an unexpected value.", type.getURI(), ParamatizedTestUtil.TEST_NAMESPACE);
-
- /**
- * Verify the accuracy of Type.getInstanceClass(). For the dynamic cases
- * it will return null. For the static case it will return
- * test.sdo21.generated.staticSdo.APITest.
- */
+ /**
+ * Verify the value returned by Type.getInstanceClass()
+ */
+ @Test
+ public void typeGetInstanceClass() {
+ Type type = testDO.getType();
+
+ // For the dynamic cases Type.getInstanceClass() will return null. For
+ // the static case it will return
+ // "test.sdo21.vendorSpecific.tuscany.generated.staticSdo.api.APITest
+
+ Class instanceClass = type.getInstanceClass();
- instanceClass = type.getInstanceClass();
if (instanceClass != null) {
assertEquals("Type.getInstanceClass() did not return the instance class with the expected name.",
- "test.sdo21.vendorSpecific.tuscany.generated.staticSdo.api.APITest", instanceClass.getName());
+ "test.sdo21.vendorSpecific.tuscany.generated.staticSdo.api.APITest",
+ instanceClass.getName());
}
- /**
- * Verify Type.isInstance() == true and == false
- */
- assertFalse("Type.getInstance() returned an unexpected value.", type.isInstance(booleanType));
+ }
+
+ /**
+ * Verify the value returned by Type.isInstance() == true
+ */
+ @Test
+ public void typeIsInstanceTrue() {
+ Type type = testDO.getType();
+
assertTrue("Type.getInstance() returned an unexpected value.", type.isInstance(testDO));
- /**
- * Verify Type.isDataType() == true and == false
- */
- assertFalse("Type.isDataType() returned an unexpected value.", type.isDataType());
+ }
+
+ /**
+ * Verify the value returned by Type.isInstance() == false
+ */
+ @Test
+ public void typeIsInstanceFalse() {
+ Type booleanType = testDO.getProperty("booleanVal").getType();
+ Type type = testDO.getType();
+
+ assertFalse("Type.getInstance() returned an unexpected value.", type.isInstance(booleanType));
+ }
+
+ /**
+ * Verify the value returned by Type.isDataType() == true
+ */
+ @Test
+ public void typeIsDataTypeTrue() {
+ Type booleanType = testDO.getProperty("booleanVal").getType();
+
assertTrue("Type.isDataType() returned an unexpected value.", booleanType.isDataType());
+ }
+
+ /**
+ * Verify the value returned by Type.isDataType() == False
+ */
+ @Test
+ public void typeIsDataTypeFalse() {
+ Type type = testDO.getType();
+
+ assertFalse("Type.isDataType() returned an unexpected value.", type.isDataType());
+ }
+
+ /**
+ * Verify the value returned by Type.isSequenced() == true
+ */
+ @Test
+ public void typeIsSequencedTrue() {
+ Type sequencedType = testDO.getProperty("sequencedElem").getType();
- /**
- * Verify Type.isSequenced() == true and == false
- */
- assertFalse("Type.isSequenced() returned an unexpected value.", type.isSequenced());
assertTrue("Type.isSequenced() returned an unexpected value.", sequencedType.isSequenced());
+ }
+
+ /**
+ * Verify the value returned by Type.isSequenced() == False
+ */
+ @Test
+ public void typeIsSequencedFalse() {
+ Type type = testDO.getType();
+
+ assertFalse("Type.isSequenced() returned an unexpected value.", type.isSequenced());
+ }
+
+ /**
+ * Verify the value returned by Type.isOpen() == true
+ */
+ @Test
+ public void typeIsOpenTrue() {
+ fail(TestHelper.INCOMPLETE_TEST_CASE_FAILURE);
+ }
+
+ /**
+ * Verify the value returned by Type.isOpen() == False
+ */
+ @Test
+ public void typeIsOpenFalse() {
+ Type type = testDO.getType();
- /**
- * Verify Type.isOpen() == true and == false
- */
- // TODO Verify isOpen == true
assertFalse("Type.isOpen() returned an unexpected value.", type.isOpen());
+ }
+
+ /**
+ * Verify the value returned by Type.isAbstract() == true
+ */
+ @Test
+ public void typeIsAbstractTrue() {
+ Type abstractType =
+ CTSSuite.getTestHelper().getTypeHelper().getType(ParamatizedTestUtil.TEST_NAMESPACE, "Abstract");
- /**
- * Verify Type.isAbstract() == true and == false
- */
- assertFalse("Type.isAbstract() returned an unexpected value.", type.isAbstract());
assertTrue("Type.isAbstract() returned an unexpected value.", abstractType.isAbstract());
+ }
+
+ /**
+ * Verify the value returned by Type.isAbstract() == False
+ */
+ @Test
+ public void typeIsAbstractFalse() {
+ Type type = testDO.getType();
+
+ assertFalse("Type.isAbstract() returned an unexpected value.", type.isAbstract());
+ }
+
+ /**
+ * Verify the value returned by Type.getBaseTypes() when there are no base
+ * types
+ */
+ @Test
+ public void typeGetBaseTypesNone() {
+ Type type = testDO.getType();
+
+ assertEquals("Type.getBaseTypes() returned a List of unexpected size.", 0, type.getBaseTypes().size());
+ }
+
+ /**
+ * Verify the value returned by Type.getBaseTypes() when there are base
+ * Types to return
+ */
+ @Test
+ public void typeGetBaseTypes() {
+ Type sequencedType = testDO.getProperty("sequencedElem").getType();
+
+ assertNotSame("Type.getBaseTypes() did not return the expected base type.", 0, sequencedType.getBaseTypes()
+ .size());
+ }
+
+ /**
+ * Verify the value returned by Type.getAliasNames() when there are no alias
+ * names
+ */
+ @Test
+ public void typeGetAliasNamesNone() {
+ Type type = testDO.getType();
+
+ assertEquals("Type.getAliasNames() returned a List of unexpected size.", 0, type.getAliasNames().size());
+ }
+
+ /**
+ * Verify the value returned by Type.getAliasNames() when there are alias
+ * names to return
+ */
+ @Ignore("typeGetAliasNames test case is suppressed until SDOUtil.addAliasName is implemented.")
+ @Test
+ public void typeGetAliasNames() {
+ Type sequencedType = testDO.getProperty("sequencedElem").getType();
+ List aliases = sequencedType.getAliasNames();
+
+ assertEquals("The List returned by Type.getAliasNames was not of the expected size.", 1, aliases.size());
+
+ String aliasName = (String)aliases.get(1);
+ assertEquals("The alias returned by Type.getAliasNames was not the expected name.", "Seq2", aliasName);
+ }
+
+ /**
+ * Verify the List returned by Type.getProperties()
+ */
+ @Test
+ public void typeGetProperties() {
+ Type type = testDO.getType();
- /**
- * Verify Type.getBaseTypes() for empty and nonempty Lists of BaseTypes.
- */
- assertEquals("Type.getBaseTypes() returned a List of unexpected size.", type.getBaseTypes().size(), 0);
- assertNotSame("Type.getBaseTypes() did not return the expected base type.",
- sequencedType.getBaseTypes().size(),
- 0);
-
- /**
- * Verify Type.getAliasNames for empty and nonempty Lists of alias
- * names.
- */
- assertEquals("Type.getAliasNames() returned a List of unexpected size.", type.getAliasNames().size(), 0);
-
- // TODO: Uncomment the following when SDOUtil.addAliasName is
- // implemented
- /*
- * aliases = sequencedType.getAliasNames(); if (aliases.size() != 1)
- * throw new ReturnValueError("Type.getAliasNames() returned a List of
- * unexpected size.", Integer.valueOf(1),
- * Integer.valueOf(aliases.size())); else if
- * (aliases.get(1).equals("Seq2")) throw new
- * ReturnValueError("Type.getAliasNames() returned a List with
- * unexpected contents.", "Seq2", aliases.get(0));;
- */
-
- /**
- * Verify the Lists returned by Type.getProperties() and
- * Type.getDeclaredProperties()
- */
assertTrue("Type.getProperties() did not return the expected List.", verifyPropertyList(type.getProperties()));
+ }
+
+ /**
+ * Verify the List returned by Type.getDeclaredProperties()
+ */
+ @Test
+ public void typeGetDeclaredProperties() {
+ Type type = testDO.getType();
+
assertTrue("Type.getProperties() did not return the expected List.", verifyPropertyList(type
.getDeclaredProperties()));
+ }
+
+ /**
+ * Verify the value returned by Type.getProperty()
+ */
+ @Test
+ public void typeGetProperty() {
+ Type type = testDO.getType();
+
+ assertEquals("Type.getProperty() returned an unexpected Property.", "booleanVal", type
+ .getProperty("booleanVal").getName());
+ }
+
+ /**
+ * Verify the handling of an inaccurate name by Type.getProperty()
+ */
+ @Test
+ public void typeGetPropertyInvalidString() {
+ Type type = testDO.getType();
- /**
- * Verify the accuracy of Type.getProperty()
- */
- assertEquals("Type.getProperty() returned an unexpected Property.",
- type.getProperty("booleanVal").getName(),
- "booleanVal");
-
- /**
- * Verify the handling of an inaccurate name by Type.getProperty()
- */
assertNull("Type.getProperty() returned an unexpected Property.", type.getProperty("madeUpName"));
}
Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/api/XMLHelperTest.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/api/XMLHelperTest.java?view=diff&rev=512241&r1=512240&r2=512241
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/api/XMLHelperTest.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/api/XMLHelperTest.java Tue Feb 27 04:54:57 2007
@@ -21,64 +21,121 @@
package test.sdo21.paramatizedTests.api;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import org.junit.Test;
+import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import test.sdo21.CTSSuite;
import test.sdo21.paramatizedTests.BaseSDOParamatizedTest;
import test.sdo21.paramatizedTests.util.ParamatizedTestUtil;
+import test.sdo21.framework.TestHelper;
import commonj.sdo.DataObject;
/**
- * Junit 4.1 test case. Tests XMLHelper methods.
+ * Junit 4.1 test case. Tests XMLHelper methods
*
*/
@RunWith(Parameterized.class)
public class XMLHelperTest extends BaseSDOParamatizedTest {
-
public XMLHelperTest(DataObject testDO, String description) {
super(testDO, description);
}
/**
- * Serialize the DataObject then Deserialize the output. Result should be
- * equivalent to testDO.
+ * Serialize the DataObject then Deserialize the output using Java
+ * serialization. Result should be equivalent to testDO.
*/
@Test
- public void testSerializeDeserialize() {
+ public void testJavaSerializeDeserialize() {
try {
ParamatizedTestUtil.populateFields(testDO);
- ParamatizedTestUtil.serializeDataObject(testDO, "temporaryFile");
- DataObject tempDO = ParamatizedTestUtil.deserializeDataObject("temporaryFile");
+ } catch (Exception e) {
+ fail("Could not populate DataObject");
+ }
+ DataObject tempDO = null;
+
+ try {
+ ParamatizedTestUtil.serializeDataObjectJava(testDO, "temporaryFile");
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("An Exception occurred while serializing the DataObject: " + e.toString());
+ }
+
+ try {
+ tempDO = ParamatizedTestUtil.deserializeDataObjectJava("temporaryFile");
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("An Exception occurred while deserializing the output of the serialization: " + e.toString());
+ }
+
+ assertNotNull("Deserialization returned a null value.", tempDO);
+ assertTrue("Serialization and deserialization resulted in a nonequivalent DataObject.", ParamatizedTestUtil
+ .equalDataObjects(testDO, tempDO));
+ }
- // TODO: Remove the unsets and return equalShallow to equal when
- // CMVC defect 404384 is resolved.
- // NOTE: The temporary masks (unset and equal->equalShallow) seem
- // only to work for the dynamic case.
+ /**
+ * Serialize the DataObject then Deserialize the output using the XMLHelper.
+ * Result should be equivalent to testDO.
+ */
+ @Test
+ public void testXMLHelperSerializeDeserialize() {
+ try {
+ ParamatizedTestUtil.populateFields(testDO);
+ } catch (Exception e) {
+ fail("Could not populate DataObject");
+ }
+ DataObject tempDO = null;
- tempDO.unset("bytesVal");
- testDO.unset("bytesVal");
+ try {
+ ParamatizedTestUtil.serializeDataObjectXML(testDO, "temporaryFile");
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("An Exception occurred while serializing the DataObject: " + e.toString());
+ }
- assertTrue("Serialization and deserialization resulted in a nonequivalent DataObject.",
- CTSSuite.getTestHelper().getEqualityHelper().equalShallow(testDO, tempDO));
+ try {
+ tempDO = ParamatizedTestUtil.deserializeDataObjectXML("temporaryFile");
} catch (Exception e) {
e.printStackTrace();
- fail("unexpected exception serializing xml " + e.toString());
+ fail("An Exception occurred while deserializing the output of the serialization: " + e.toString());
+ }
+
+ assertNotNull("Deserialization returned a null value.", tempDO);
+ assertTrue("Serialization and deserialization resulted in a nonequivalent DataObject.", ParamatizedTestUtil
+ .equalDataObjects(testDO, tempDO));
+ }
+
+ /**
+ * Verifies that appropriate exception is thrown when an invalid XML
+ * document is specified.
+ */
+ @Test
+ public void testFaultyXML() {
+ try {
+ CTSSuite.getTestHelper().getXMLHelper().load(XMLHelperTest.class.getResourceAsStream("/faulty.xml"));
+ fail("Attempting to load a faulty XML file should result in an Exception.");
+ } catch (Exception e) {
+ // success
}
}
/**
- * Verifies that appropriate exception is thrown when an
- * invalid XML document is specified. It will also test the condition that
- * an XML document is in itself valid, but does not comply with the XSD.<br>
- * (To be implemented)
+ * Tests the condition that an XML document is in itself valid, but does not
+ * comply with the XSD.
*/
- @org.junit.Ignore
- public static void testFaultyXML(DataObject testDO) {
- // TODO: complete
+ @Test
+ public void testXMLWrongXSD() {
+ try {
+ CTSSuite.getTestHelper().getXMLHelper()
+ .load(XMLHelperTest.class.getResourceAsStream("/wrongNamespace.xml"));
+ fail("Attempting to load an XML specifying the wrong namespace file should result in an Exception.");
+ } catch (Exception e) {
+ // success
+ }
}
}
Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/conversion/TypeConversionTest.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/conversion/TypeConversionTest.java?view=diff&rev=512241&r1=512240&r2=512241
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/conversion/TypeConversionTest.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/conversion/TypeConversionTest.java Tue Feb 27 04:54:57 2007
@@ -45,7 +45,6 @@
/**
* Junit 4.1 test case. Tests that each of the permitted Type conversions
* performs properly.
- *
*/
@RunWith(Parameterized.class)
@@ -1214,7 +1213,6 @@
* testBigIntegerExceptions verifies that the appropriate Exceptions are
* thrown when an unpermitted conversion from BigInteger is attempted.
*
- * @param testDO
* @throws Exception
*/
@org.junit.Test
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=512241&r1=512240&r2=512241
==============================================================================
--- 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 Tue Feb 27 04:54:57 2007
@@ -40,14 +40,15 @@
import commonj.sdo.helper.DataFactory;
/**
- * Tests for proper updates to DataObject and their value changes due to the updates.
+ * Tests for proper updates to DataObject and their value changes due to the
+ * updates.
*/
@RunWith(Parameterized.class)
public class ActiveUpdatingTest extends BaseSDOParamatizedTest {
-
/**
- * Tests for proper updates to DataObject and their value changes due to the updates.
+ * Tests for proper updates to DataObject and their value changes due to the
+ * updates.
*/
public ActiveUpdatingTest(DataObject testDO, String description) {
super(testDO, description);
@@ -59,7 +60,7 @@
*/
@Test
public void testActiveUpdatingList() {
-
+
Type type = testDO.getType();
DataFactory df = CTSSuite.getTestHelper().getDataFactory();
DataObject root = df.create(type);
@@ -163,7 +164,6 @@
@Test
public void testActiveUpdatingSequence() {
-
DataObject sequenceDO = testDO.getDataObject("sequencedElem");
Sequence sequence = sequenceDO.getSequence();
List letterList = sequenceDO.getList("Letters");
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=512241&r1=512240&r2=512241
==============================================================================
--- 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 Tue Feb 27 04:54:57 2007
@@ -29,6 +29,7 @@
import java.util.List;
import org.junit.Test;
+import org.junit.Before;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -40,302 +41,415 @@
import commonj.sdo.Type;
/**
- * Junit 4.1 test case. Tests containment alterations:
- * <ul>
- * <li>container/contained relationship</li>
- * <li>containment cycle</li>
- * </ul>
+ * Junit 4.1 test case. ContainmentTest insures that containment alterations are
+ * reflected on both sides of the container/contained relationship.
+ * Additionally, containment eclusivity is verified.
+ *
*/
@RunWith(Parameterized.class)
public class ContainmentTest extends BaseSDOParamatizedTest {
-
public ContainmentTest(DataObject testDO, String description) {
super(testDO, description);
}
/**
- * testContainmentIntegrity insures that containment alterations are
- * reflected on both sides of the container/contained relationship.
- * Additionally, containment eclusivity is checked following several
- * scenarios.
+ * Insures that the different test cases do not affect each other. Is called
+ * before each test.
+ */
+ @Before
+ public void clearContainment() {
+ List addList = new ArrayList();
+
+ // Ensure that any previous containment relationships are broken.
+
+ addList.clear();
+ testDO.setList("children", addList);
+ testDO.detach();
+ }
+
+ /**
+ * Verfies that the Property being tested throughout these tests is a
+ * contaiment Property
*/
@Test
- public void testContainmentIntegrity() {
- Type type = testDO.getType();
- List returnedList;
+ public void verifyIsContainment() {
+ Property containmentProp = testDO.getProperty("children");
+ assertTrue("Property.isContainment() returned an unexpected value.", containmentProp.isContainment());
+ }
+
+ /**
+ * Verifies that the initial state after clearContainer is a state in which
+ * the DataObject does not have a container.
+ */
+ @Test
+ public void verifyNullContainer() {
+ assertNull("DataObject.getContainer() returned an unexpected value.", testDO.getContainer());
+ }
+
+ /**
+ * Verfiies that the containerless DataObject returns null for
+ * getContainmentProperty
+ */
+ @Test
+ public void verifyNullContainmentProperty() {
+ assertNull("DataObject.getContainmentProprety() returned an unexpected value.", testDO.getContainmentProperty());
+ }
+
+ /**
+ * Assign both dataObj1 and dataObj2 to testDO container, then verify
+ * DataObject.getContainer() for dataObj1 and dataObj2
+ */
+ @Test
+ public void verifyGetContainer() {
List addList = new ArrayList();
+ Type type = testDO.getType();
+ Property containmentProp = testDO.getProperty("children");
+
DataObject dataObj1 = CTSSuite.getTestHelper().getDataFactory().create(type);
DataObject dataObj2 = CTSSuite.getTestHelper().getDataFactory().create(type);
- Property containmentProp = testDO.getProperty("children");
// Ensure that any previous containment relationships are broken.
addList.clear();
testDO.setList("children", addList);
testDO.detach();
+ addList.clear();
- // Assign identifier to the created DataObjects
+ addList.add(dataObj1);
+ addList.add(dataObj2);
+ testDO.setList(containmentProp, addList);
- testDO.setString("stringVal", "testDO");
- dataObj1.setString("stringVal", "dataObj1");
- dataObj2.setString("stringVal", "dataObj2");
+ // Verify containment of dataObj1 and dataObj2 by testDO
- // Verify pre-conditions
+ assertEquals("DataObject.getContainer() did not return the appropriate DataObject.", testDO, dataObj1
+ .getContainer());
- assertTrue("Property.isContainment() returned an unexpected value.", containmentProp.isContainment());
+ assertEquals("DataObject.getContainer() did not return the appropriate DataObject.", testDO, dataObj2
+ .getContainer());
+ }
- assertNull("DataObject.getContainer() returned an unexpected value.", testDO.getContainer());
- assertNull("DataObject.getContainmentProprety() returned an unexpected value.", testDO.getContainmentProperty());
+ /**
+ * Assign both dataObj1 and dataObj2 to testDO container, then verify
+ * DataObject.getContainmentProperty for dataObj1 and dataObj2
+ */
+ @Test
+ public void verifyGetContainmentProperty() {
+ Property containmentProp = testDO.getProperty("children");
+ List addList = new ArrayList();
+ Type type = testDO.getType();
+ DataObject dataObj1 = CTSSuite.getTestHelper().getDataFactory().create(type);
+ DataObject dataObj2 = CTSSuite.getTestHelper().getDataFactory().create(type);
- /**
- * Assign both dataObj1 and dataObj2 to testDO container, then verify
- * containment of dataObj1 and dataObj2 by testDO
- */
+ addList.add(dataObj1);
+ addList.add(dataObj2);
+ testDO.setList(containmentProp, addList);
+
+ assertEquals("DataObject.getContainmentProperty() did not return the appropriate Property.",
+ containmentProp,
+ dataObj1.getContainmentProperty());
+
+ assertEquals("DataObject.getContainmentProperty() did not return the appropriate Property.",
+ containmentProp,
+ dataObj2.getContainmentProperty());
+ }
+
+ /**
+ * Assign both dataObj1 and dataObj2 to testDO container, then verify the
+ * contents of the containing property in testDO
+ */
+ @Test
+ public void verifyContainmentContents() {
+ assertNull("testDO container != null", testDO.getContainer());
+ assertEquals("testDO.children != 0", 0, testDO.getList("children").size());
+
+ Property containmentProp = testDO.getProperty("children");
+ List addList = new ArrayList();
+ Type type = testDO.getType();
+ DataObject dataObj1 = CTSSuite.getTestHelper().getDataFactory().create(type);
+ DataObject dataObj2 = CTSSuite.getTestHelper().getDataFactory().create(type);
addList.add(dataObj1);
addList.add(dataObj2);
testDO.setList(containmentProp, addList);
- // Verify containment of dataObj1 and dataObj2 by testDO
- assertEquals("DataObject.getContainer() did not return the appropriate DataObject.",
- dataObj1.getContainer(),
- testDO);
-
- assertEquals("DataObject.getContainer() did not return the appropriate DataObject.",
- dataObj2.getContainer(),
- testDO);
-
- assertEquals("DataObject.getContainmentProperty() did not return the appropriate Property.", dataObj1
- .getContainmentProperty(), containmentProp);
-
- assertEquals("DataObject.getContainmentProperty() did not return the appropriate Property.", dataObj2
- .getContainmentProperty(), containmentProp);
-
- returnedList = testDO.getList(containmentProp);
-
- assertEquals("DataObject.getList() size is incorrect", returnedList.size(), 2);
- assertEquals("DataObject.getList() did not return the List specified in DataObject.setList()", returnedList
- .get(0), dataObj1);
- assertEquals("DataObject.getList() did not return the List specified in DataObject.setList()", returnedList
- .get(1), dataObj2);
-
- /**
- * Assign dataObj2 to dataObj1 container, then verify dataObj2 is
- * automatically removed from testDO container
- */
+ List returnedList = testDO.getList(containmentProp);
+
+ assertEquals("DataObject.getList() size is incorrect", 2, returnedList.size());
+ assertEquals("DataObject.getList() did not return the List specified in DataObject.setList()",
+ dataObj1,
+ returnedList.get(0));
+ assertEquals("DataObject.getList() did not return the List specified in DataObject.setList()",
+ dataObj2,
+ returnedList.get(1));
+ }
+
+ /**
+ * Assign both dataObj1 and dataObj2 to testDO container, then Assign
+ * dataObj2 to dataObj1 container. Verify dataObj2 is automatically removed
+ * from testDO container
+ */
+ @Test
+ public void verifyAutomaticRemoval() {
+ Property containmentProp = testDO.getProperty("children");
+ List addList = new ArrayList();
+ Type type = testDO.getType();
+ DataObject dataObj1 = CTSSuite.getTestHelper().getDataFactory().create(type);
+ DataObject dataObj2 = CTSSuite.getTestHelper().getDataFactory().create(type);
+
+ addList.add(dataObj1);
+ addList.add(dataObj2);
+ testDO.setList(containmentProp, addList);
+
+ // Verify the precondition
+
+ assertEquals("DataObject.getContainer() did not return the appropriate DataObject.", testDO, dataObj1
+ .getContainer());
+
+ assertEquals("DataObject.getContainer() did not return the appropriate DataObject.", testDO, dataObj2
+ .getContainer());
// After the following section, it should be true that: testDO contains
// dataObj1 contains dataObj2
+
addList.clear();
addList.add(dataObj2);
dataObj1.setList(containmentProp, addList);
// Verify automatic removal of dataObj2 from testDO container
- returnedList = testDO.getList(containmentProp);
+ List returnedList = testDO.getList(containmentProp);
assertEquals("Once placed in a new container, the DataObject should no longer appear in the former container.",
- returnedList.size(),
- 1);
+ 1,
+ returnedList.size());
assertEquals("Once placed in a new container, the DataObject should no longer appear in the former container.",
- returnedList.get(0),
- dataObj1);
+ dataObj1,
+ returnedList.get(0));
+ }
+
+ /**
+ * Assign both dataObj1 and dataObj2 to testDO container, then Assign
+ * dataObj2 to dataObj1 container. Verify dataObj2 is contained by dataObj1
+ */
+ @Test
+ public void verifyNewContainer() {
+ Property containmentProp = testDO.getProperty("children");
+ List addList = new ArrayList();
+ Type type = testDO.getType();
+ DataObject dataObj1 = CTSSuite.getTestHelper().getDataFactory().create(type);
+ DataObject dataObj2 = CTSSuite.getTestHelper().getDataFactory().create(type);
+
+ addList.add(dataObj1);
+ addList.add(dataObj2);
+ testDO.setList(containmentProp, addList);
+
+ // After the following section, it should be true that: testDO contains
+ // dataObj1 contains dataObj2
+
+ addList.clear();
+ addList.add(dataObj2);
+ dataObj1.setList(containmentProp, addList);
// Verify that dataObj2 was correctly added to dataObj1 container
- returnedList = dataObj1.getList(containmentProp);
+ List returnedList = dataObj1.getList(containmentProp);
assertEquals("Once assigned to a new container, the DataObject should appear in the new container.",
- returnedList.size(),
- 1);
+ 1,
+ returnedList.size());
assertEquals("Once assigned to a new container, the DataObject should appear in the new container.",
- returnedList.get(0),
- dataObj2);
- assertEquals("DataObject.getContainer() did not return the appropriate DataObject.",
- dataObj2.getContainer(),
- dataObj1);
+ dataObj2,
+ returnedList.get(0));
+ assertEquals("DataObject.getContainer() did not return the appropriate DataObject.", dataObj1, dataObj2
+ .getContainer());
+ }
+
+ /**
+ * Verify that detach() removes the object from its container.
+ */
+ @Test
+ public void verifyDetachRemoval() {
+ Property containmentProp = testDO.getProperty("children");
+ List addList = new ArrayList();
+ Type type = testDO.getType();
+ DataObject dataObj1 = CTSSuite.getTestHelper().getDataFactory().create(type);
+ DataObject dataObj2 = CTSSuite.getTestHelper().getDataFactory().create(type);
// After the following section, it should be true that: dataObj1
// contains testDO contains dataObj2
- dataObj1.detach();
- addList.clear();
addList.add(dataObj2);
testDO.setList(containmentProp, addList);
addList.clear();
addList.add(testDO);
dataObj1.setList(containmentProp, addList);
- /**
- * Verify that detach() removes the object from its container.
- */
-
testDO.detach();
- returnedList = dataObj1.getList(containmentProp);
- assertEquals("Detaching the contained object did not remove it from container", returnedList.size(), 0);
+ List returnedList = dataObj1.getList(containmentProp);
+ assertEquals("Detaching the contained object did not remove it from container", 0, returnedList.size());
assertNull("DataObject.getContainer() did not return null as expected for a detached DataObject.", testDO
.getContainer());
+ }
- /**
- * Verify that DataObject.detach() does not affect objects contained by
- * the detached DataObject
- */
-
- returnedList = testDO.getList(containmentProp);
-
- assertEquals("Detaching a DataObject should not affect it as a container.", returnedList.size(), 1);
- assertEquals("Detaching a DataObject should not affect it as a container.", returnedList.get(0), dataObj2);
- assertEquals("Detaching a DataObject should not affect it as a container.", dataObj2.getContainer(), testDO);
-
- /**
- * Verify that DataObject.delete() removes the object from its container
- * and affects the containment of objects within the deleted DataObject
- */
+ /**
+ * Verify that DataObject.detach() does not affect objects contained by the
+ * detached DataObject
+ */
+ @Test
+ public void verifyDetachContainer() {
+ Property containmentProp = testDO.getProperty("children");
+ List addList = new ArrayList();
+ Type type = testDO.getType();
+ DataObject dataObj1 = CTSSuite.getTestHelper().getDataFactory().create(type);
+ DataObject dataObj2 = CTSSuite.getTestHelper().getDataFactory().create(type);
// After the following section, it should be true that: dataObj1
// contains testDO contains dataObj2
- addList.clear();
+
addList.add(testDO);
dataObj1.setList(containmentProp, addList);
+ addList.clear();
+ addList.add(dataObj2);
+ testDO.setList(containmentProp, addList);
- assertEquals("DataObject.getContainer() did not result in the set value.", testDO.getContainer(), dataObj1);
+ testDO.detach();
- testDO.delete();
+ List returnedList = testDO.getList(containmentProp);
+
+ assertEquals("Detaching a DataObject should not detach its contained DataObjects.", 1, returnedList.size());
+ assertEquals("Detaching a DataObject should not affect it as a container.", dataObj2, returnedList.get(0));
+ }
- assertEquals("Deleting the DataObject did not remove it from its container.", dataObj1.getList(containmentProp)
- .size(), 0);
+ /**
+ * Verify that DataObject.detach() does not affect objects contained by the
+ * detached DataObject
+ */
+ @Test
+ public void verifyDetachContainedDOs() {
+ Property containmentProp = testDO.getProperty("children");
+ List addList = new ArrayList();
+ Type type = testDO.getType();
+ DataObject dataObj1 = CTSSuite.getTestHelper().getDataFactory().create(type);
+ DataObject dataObj2 = CTSSuite.getTestHelper().getDataFactory().create(type);
- assertNotNull("Deleting the DataObject did not affect its view of its container.", testDO);
+ // After the following section, it should be true that: dataObj1
+ // contains testDO contains dataObj2
- assertEquals("Deleting the DataObject did not empty it as a container.",
- testDO.getList(containmentProp).size(),
- 0);
+ addList.add(testDO);
+ dataObj1.setList(containmentProp, addList);
+ addList.clear();
+ addList.add(dataObj2);
+ testDO.setList(containmentProp, addList);
- assertNull("Deleting the containing DataObject was not reflected in the contained DataObject.", dataObj2
- .getContainer());
+ testDO.detach();
+ assertEquals("Detaching a DataObject should not affect contained DataObjects.", testDO, dataObj2.getContainer());
}
/**
- * testContainmentCycle ensures that a containment cycle is prevented
- * appropriately. Attempts are made at 1-member and n-member cycles, as well
- * as cycles created via setting the containment property through the
- * DataObject and setting through a returned List. In all cases, an
- * exception should be thrown and the cycle prevented
- *
- * @param testDO
+ * Verify that DataObject.delete() removes the object from its container.
*/
-
- public static void testContainmentCycle(DataObject testDO) {
- Type type = testDO.getType();
+ @Test
+ public void verifyDeleteRemoval() {
+ Property containmentProp = testDO.getProperty("children");
List addList = new ArrayList();
- List returnedList = testDO.getList("children");
+ Type type = testDO.getType();
DataObject dataObj1 = CTSSuite.getTestHelper().getDataFactory().create(type);
DataObject dataObj2 = CTSSuite.getTestHelper().getDataFactory().create(type);
- boolean exceptionCaught;
- // Ensure that any previous containment relationships are broken.
+ // After the following section, it should be true that: dataObj1
+ // contains testDO contains dataObj2
+ addList.add(testDO);
+ dataObj1.setList(containmentProp, addList);
addList.clear();
- testDO.setList("children", addList);
- testDO.detach();
+ addList.add(dataObj2);
+ testDO.setList(containmentProp, addList);
- // Assign identifier to the created DataObjects
+ testDO.delete();
- testDO.setString("stringVal", "testDO");
- dataObj1.setString("stringVal", "dataObj1");
- dataObj2.setString("stringVal", "dataObj2");
-
- /**
- * Attempt to create a one-member containment cycle via
- * DataObject.set____ and verify that an exception is thrown
- */
+ assertEquals("Deleting the DataObject did not remove it from its container.", 0, dataObj1
+ .getList(containmentProp).size());
+ }
- addList.add(dataObj1);
- addList.add(testDO);
+ /**
+ * Verify that DataObject.delete() removes the containment reflected by the
+ * deleted DataObject
+ */
+ @Test
+ public void verifyDeleteResultsOnDeleted() {
+ Property containmentProp = testDO.getProperty("children");
+ List addList = new ArrayList();
+ Type type = testDO.getType();
+ DataObject dataObj1 = CTSSuite.getTestHelper().getDataFactory().create(type);
+ DataObject dataObj2 = CTSSuite.getTestHelper().getDataFactory().create(type);
- exceptionCaught = false;
- try {
- testDO.setList("children", addList);
- } catch (Exception e) {
- exceptionCaught = true;
- }
-
- assertTrue("Attempting to create a one member containment cycle using a set method on the DataObject should result in an Exception.",
- exceptionCaught);
-
- /**
- * Attempt to create a one-member containment cycle via a returned List
- * and verify that an exception is thrown
- */
+ // After the following section, it should be true that: dataObj1
+ // contains testDO contains dataObj2
+ addList.add(testDO);
+ dataObj1.setList(containmentProp, addList);
addList.clear();
- testDO.setList("children", addList);
+ addList.add(dataObj2);
+ testDO.setList(containmentProp, addList);
+
+ testDO.delete();
- exceptionCaught = false;
- try {
- returnedList.add(testDO);
- } catch (Exception e) {
- exceptionCaught = true;
- }
- assertTrue("Attempting to create a one member containment cycle using a returned List should result in an Exception.",
- exceptionCaught);
-
- /**
- * Attempt to create an n-member containment cycle via
- * DataObject.set____ and verify that an exception is thrown
- */
+ assertNotNull("A deleted DataObject should remain programatically accessible.", testDO);
+ assertNull("Deleting the DataObject did not affect its view of its container.", testDO.getContainer());
+ }
- addList.clear();
- addList.add(dataObj1);
+ /**
+ * Verify that DataObject.delete() removes its contents as a container.
+ */
+ @Test
+ public void verifyDeleteAsContainer() {
+ Property containmentProp = testDO.getProperty("children");
+ List addList = new ArrayList();
+ Type type = testDO.getType();
+ DataObject dataObj1 = CTSSuite.getTestHelper().getDataFactory().create(type);
+ DataObject dataObj2 = CTSSuite.getTestHelper().getDataFactory().create(type);
- testDO.setList("children", addList);
+ // After the following section, it should be true that: dataObj1
+ // contains testDO contains dataObj2
+ addList.add(testDO);
+ dataObj1.setList(containmentProp, addList);
addList.clear();
addList.add(dataObj2);
+ testDO.setList(containmentProp, addList);
- dataObj1.setList("children", addList);
+ testDO.delete();
- addList.clear();
- addList.add(testDO);
+ assertNotNull("A deleted DataObject should remain programatically accessible.", testDO);
+ assertEquals("Deleting the DataObject did not empty it as a container.", 0, testDO.getList(containmentProp)
+ .size());
+ }
- // testDO contains dataObj1 contains dataObj2. dataObj2 containing
- // testDO (or dataObj1 or dataObj2) would form a cycle.
+ /**
+ * Verify that DataObject.delete() affects contained DataObjects.
+ */
+ @Test
+ public void verifyDeleteAffectOnContained() {
+ Property containmentProp = testDO.getProperty("children");
+ List addList = new ArrayList();
+ Type type = testDO.getType();
+ DataObject dataObj1 = CTSSuite.getTestHelper().getDataFactory().create(type);
+ DataObject dataObj2 = CTSSuite.getTestHelper().getDataFactory().create(type);
- exceptionCaught = false;
- try {
- dataObj2.setList("children", addList);
- } catch (Exception e) {
- exceptionCaught = true;
- }
- assertTrue("Attempting to create a containment cycle should result in an Exception.", exceptionCaught);
-
- /**
- * Attempt to create an n-member containment cycle via a returned List
- * and verify that an exception is thrown
- */
+ // After the following section, it should be true that: dataObj1
+ // contains testDO contains dataObj2
+ addList.add(testDO);
+ dataObj1.setList(containmentProp, addList);
addList.clear();
- testDO.setList("children", addList);
-
addList.add(dataObj2);
- dataObj1.setList("children", addList);
-
- addList.clear();
- addList.add(testDO);
- dataObj2.setList("children", addList);
-
- // dataObj1 contains dataObj2 contains testDO. testDO containing
- // dataObj1 (or dataObj2 or testDO) would form a cycle.
+ testDO.setList(containmentProp, addList);
- exceptionCaught = false;
- try {
- returnedList.add(dataObj1);
- } catch (Exception e) {
- exceptionCaught = true;
- }
+ testDO.delete();
- assertTrue("Attempting to create an n-member containment cycle using a returned List should result in an Exception.",
- exceptionCaught);
+ assertNull("Deleting the containing DataObject was not reflected in the contained DataObject.", dataObj2
+ .getContainer());
}
+
}
Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/general/DeleteTest.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/general/DeleteTest.java?view=diff&rev=512241&r1=512240&r2=512241
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/general/DeleteTest.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/general/DeleteTest.java Tue Feb 27 04:54:57 2007
@@ -42,9 +42,8 @@
/**
* Junit 4.1 test case. Tests containment alterations:
* <ul>
- * <li>recursive deletion</li>
+ * <li>recursive deletion</li>
* </ul>
- *
*/
@RunWith(Parameterized.class)
public class DeleteTest extends BaseSDOParamatizedTest {
@@ -65,7 +64,7 @@
assertTrue("Cannot continue with test because Property.isContainment() is false.", containmentProp
.isContainment());
- DataFactory df = CTSSuite.getTestHelper().getDataFactory();
+ DataFactory df = CTSSuite.getTestHelper().getDataFactory();
DataObject child1 = df.create(type);
DataObject child2 = df.create(type);
DataObject child3 = df.create(type);
Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/util/ParamatizedTestUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/util/ParamatizedTestUtil.java?view=diff&rev=512241&r1=512240&r2=512241
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/util/ParamatizedTestUtil.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/util/ParamatizedTestUtil.java Tue Feb 27 04:54:57 2007
@@ -39,7 +39,6 @@
/**
* Utility methods for SDO Tests. Provides methods to populate fields of
* DataObjects, serializing DataObjects etc.
- *
*/
public class ParamatizedTestUtil {
public final static String TEST_TYPE = "APITest";
@@ -52,7 +51,6 @@
* DataObject. It is used to ensure a known set of expected values that are
* not other than the default values for the various fields.
*
- * TODO: need to create a static sequence here.
* @param testDO
* @throws ExpectedConditionError
*/
@@ -77,24 +75,145 @@
testDO.setBigInteger("integerVal", new BigInteger("88819313"));
testDO.setChar("charVal", '*');
if (testDO.getType().getInstanceClass() != null) {
- //TODO: need to create a static sequence here.
- //Sequenced createStatic = StaticSdoFactory.INSTANCE.createSequenced();
- //testDO.setDataObject("sequencedElem", (DataObject)createStatic);
+ // TODO: need to create a static sequence here.
+ // Sequenced createStatic =
+ // StaticSdoFactory.INSTANCE.createSequenced();
+ // testDO.setDataObject("sequencedElem", (DataObject)createStatic);
} else {
testDO.setDataObject("sequencedElem", CTSSuite.getTestHelper().getDataFactory().create(CTSSuite
.getTestHelper().getTypeHelper().getType(TEST_NAMESPACE, "Sequenced")));
- }
+ }
+ }
+
+ /**
+ * Calls equalDataObjects only after it has been verified that the two
+ * Objects are instanceof DataObject.
+ */
+ public static boolean equalDObjects(Object object1, Object object2) {
+ if (object1 == null && object2 == null)
+ return true;
+ else if (object1 == null || object2 == null)
+ return false;
+
+ if (!(object1 instanceof DataObject) && !(object2 instanceof DataObject))
+ return false; // not equal DataObjects since not DataObjects
+ else if (!(object1 instanceof DataObject) || !(object2 instanceof DataObject))
+ return false;
+ else
+ return equalDataObjects((DataObject)object1, (DataObject)object2);
+ }
+
+ /**
+ * Compares two DataObjects Property by Property. Returns true if they have
+ * the same values assigned to each Property, but does not require that the
+ * Properties appear in the same order.
+ */
+ public static boolean equalDataObjects(DataObject dataObj1, DataObject dataObj2) {
+ if (dataObj1 == null && dataObj2 == null)
+ return true;
+ else if (dataObj1 == null || dataObj2 == null)
+ return false;
+
+ if (!areEqualTypes(dataObj1.getType(), dataObj2.getType()))
+ return false;
+
+ List properties1 = dataObj1.getType().getProperties();
+ List properties2 = dataObj2.getType().getProperties();
+ Property property;
+
+ if (properties1.size() != properties2.size())
+ return false;
+
+ for (int i = 0; i < properties1.size(); i++) {
+ property = (Property)properties1.get(i);
+ if (property.isContainment()) {
+ if (property.isMany()) {
+ List dataObjList1 = (List)dataObj1.get(property.getName());
+ List dataObjList2 = (List)dataObj2.get(property.getName());
+
+ if (dataObjList1 == null && dataObjList2 == null)
+ return true;
+ else if (dataObjList1 == null || dataObjList2 == null)
+ return false;
+ else if (dataObjList1.size() != dataObjList2.size())
+ return false;
+ else {
+ for (int j = 0; j < dataObjList1.size(); j++) {
+ if (!(equalDObjects(dataObjList1.get(j), dataObjList2.get(j))))
+ return false;
+ }
+ }
+ } else {
+ if (!(equalDObjects(dataObj1.get(property.getName()), dataObj2.get(property.getName()))))
+ return false;
+ }
+ } else if (property.getType().isDataType()) {
+ if (property.getName().equals("mixed")) {
+ // do nothing - this Property should not be visible and
+ // there is a Jira to make that so
+ } else if (property.getType().getInstanceClass() != null && property.getType().getInstanceClass()
+ .toString().indexOf('[') != -1) {
+ byte[] bytes1 = dataObj1.getBytes(property.getName());
+ byte[] bytes2 = dataObj2.getBytes(property.getName());
+
+ if (bytes1 == null && bytes2 == null)
+ ; // do nothing
+ else if (bytes1 == null || bytes2 == null)
+ return false;
+ else {
+ for (int j = 0; j < bytes1.length; j++) {
+ if (bytes1[j] != bytes2[j])
+ return false;
+ }
+ }
+ } else if (dataObj1.get(property.getName()) != null) {
+ if (!(dataObj1.get(property.getName()).equals(dataObj2.get(property.getName()))))
+ return false;
+ } else if (dataObj2.get(property.getName()) != null)
+ return false;
+ } else {
+ if (!(equalDObjects(dataObj1.get(property.getName()), dataObj2.get(property.getName()))))
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Uses the XMLHelper to serialize the input DataObject
+ *
+ * @param dataObject
+ * @param fileName
+ * @throws IOException
+ */
+ public static void serializeDataObjectXML(DataObject dataObject, String fileName) throws IOException {
+ FileOutputStream fos = new FileOutputStream(fileName);
+ Type type = dataObject.getType();
+ CTSSuite.getTestHelper().getXMLHelper().save(dataObject, type.getURI(), type.getName(), fos);
+ }
+
+ /**
+ * Uses the XMLHelper to deserialize the input XML file
+ *
+ * @param fileName
+ * @return
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
+ public static DataObject deserializeDataObjectXML(String fileName) throws IOException, ClassNotFoundException {
+ FileInputStream fis = new FileInputStream(fileName);
+
+ return CTSSuite.getTestHelper().getXMLHelper().load(fis).getRootObject();
}
/**
- * serializeDataObject is a private method to be called by the other methods
- * in the ScrenarioLibrary
+ * Uses Java serialization to serialize the input DataObject
*
* @param dataObject
* @param fileName
* @throws IOException
*/
- public static void serializeDataObject(DataObject dataObject, String fileName) throws IOException {
+ public static void serializeDataObjectJava(DataObject dataObject, String fileName) throws IOException {
FileOutputStream fos = new FileOutputStream(fileName);
ObjectOutputStream out = new ObjectOutputStream(fos);
out.writeObject(dataObject);
@@ -102,15 +221,14 @@
}
/**
- * deserializeDataObject is a private method to be called by the other
- * methods in the ScrenarioLibrary
+ * Uses Java deserialization to deserialize the input XML file
*
* @param fileName
* @return
* @throws IOException
* @throws ClassNotFoundException
*/
- public static DataObject deserializeDataObject(String fileName) throws IOException, ClassNotFoundException {
+ public static DataObject deserializeDataObjectJava(String fileName) throws IOException, ClassNotFoundException {
FileInputStream fis = new FileInputStream(fileName);
ObjectInputStream input = new ObjectInputStream(fis);
DataObject dataObject = (DataObject)input.readObject();
@@ -138,20 +256,34 @@
* @param indent
*/
public static void printDataObject(DataObject dataObject, int indent) {
- // For each property
+ List properties;
- List properties = dataObject.getInstanceProperties();
+ if (dataObject == null) {
+ properties = new ArrayList();
+ System.out.println("DataObject is null.");
+ } else
+ properties = dataObject.getInstanceProperties();
+
+ // For each property
for (int i = 0, size = properties.size(); i < size; i++) {
if (dataObject.isSet(i)) {
Property property = (Property)properties.get(i);
if (property.isMany()) {
// For many-valued properties, process a list of values
List values = dataObject.getList(i);
- for (int j = 0, count = values.size(); j < count; j++)
- printValue(values.get(j), property, indent);
+ if (property.isContainment()) {
+ for (int j = 0, count = values.size(); j < count; j++)
+ printDataObject((DataObject)values.get(j), indent);
+ } else {
+ for (int j = 0, count = values.size(); j < count; j++)
+ printValue(values.get(j), property, indent);
+ }
} else {
// for single-valued properties, print out the value
- printValue(dataObject.get(i), property, indent);
+ if (property.isContainment())
+ printDataObject((DataObject)dataObject.get(i), indent + 1);
+ else
+ printValue(dataObject.get(i), property, indent);
}
}
}
@@ -213,14 +345,11 @@
if (!(property1.getType().getName().equals(property2.getType().getName())))
return false;
}
-
k++;
}
-
if (!found)
return false;
}
-
return true;
}
@@ -252,7 +381,5 @@
// For non-containment properties, just print the value
System.out.println(margin + propertyName + ": " + value);
}
-
}
-
}
Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/util/TypeCreateUtility.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/util/TypeCreateUtility.java?view=diff&rev=512241&r1=512240&r2=512241
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/util/TypeCreateUtility.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/util/TypeCreateUtility.java Tue Feb 27 04:54:57 2007
@@ -34,7 +34,6 @@
/**
* Utility to create Types for DataObject using a variety of mechanisms
- *
*/
public class TypeCreateUtility {
@@ -105,7 +104,7 @@
firstProperty.set("name", "firstName");
firstProperty.set("type", stringType);
- DataObject lastProperty = abstractTypeDO.createDataObject("property");
+ DataObject lastProperty = abstractTypeDO.createDataObject("property");
lastProperty.set("name", "lastName");
lastProperty.set("type", stringType);
Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/CTSGeneralSuite.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/CTSGeneralSuite.java?view=diff&rev=512241&r1=512240&r2=512241
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/CTSGeneralSuite.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/CTSGeneralSuite.java Tue Feb 27 04:54:57 2007
@@ -25,23 +25,24 @@
import test.sdo21.tests.api.DataObjectTest;
import test.sdo21.tests.conversion.DateConversionTest;
-import test.sdo21.tests.conversion.TypeConversionTest;
import test.sdo21.tests.general.XSDSerializationTest;
-
+import test.sdo21.tests.api.DynamicTypesFromSchemaTestCase;
/**
* Declares general test classes to be run within Junit 4.1 Suite for SDO CTS
* which includes the following classes:<br>
* <ul>
- * <li>test.sdo21.tests.api.DataObjectTest</li>
- * <li>test.sdo21.tests.conversion.DateConversionTest</li>
- * <li>test.sdo21.tests.conversion.TypeConversionTest</li>
- * <li>test.sdo21.tests.general.XSDSerializationTest</li>
+ * <li>{@link test.sdo21.tests.api.DataObjectTest}</li>
+ * <li>{@link test.sdo21.tests.conversion.DateConversionTest}</li>
+ * <li>{@link test.sdo21.tests.general.XSDSerializationTest}</li>
+ * <li>{@link test.sdo21.tests.api.DynamicTypesFromSchemaTestCase}</li>
* </ul>
- * These test cases should only be run once.
+ * New test cases, or test cases that do not have consencus by the community
+ * should be placed in the {@link test.sdo21.UnderReviewSuite} suite.
*/
@RunWith(Suite.class)
-@Suite.SuiteClasses( {DateConversionTest.class, XSDSerializationTest.class, DataObjectTest.class, TypeConversionTest.class})
+@Suite.SuiteClasses( {DateConversionTest.class, XSDSerializationTest.class, DataObjectTest.class,
+ DynamicTypesFromSchemaTestCase.class})
public class CTSGeneralSuite {
}
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=512241&r1=512240&r2=512241
==============================================================================
--- 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 Tue Feb 27 04:54:57 2007
@@ -20,16 +20,20 @@
*/
package test.sdo21.tests.api;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import junit.framework.TestCase;
import test.sdo21.CTSSuite;
import test.sdo21.framework.TestHelper;
import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.Property;
+import commonj.sdo.helper.XMLHelper;
-
-public class DataObjectTest extends TestCase
-{
+public class DataObjectTest extends TestCase {
private TestHelper testHelper;
+ private boolean debug = false;
/**
* Set of tests for DataObject APIs.
@@ -41,54 +45,189 @@
}
/**
- * 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
- *
+ * 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
+ *
* @throws Exception
*/
public void testGetInstancePropertiesSize() throws Exception {
// define a type with two properties
String typeName = testHelper.createUniqueName();
- DataObject typeDef = testHelper.createTypeDef( "", typeName, true );
- testHelper.createPropertyDef( typeDef, "p1", "commonj.sdo#String", false, false );
- testHelper.createPropertyDef( typeDef, "p2", "commonj.sdo#String", false, false );
- testHelper.getTypeHelper().define( typeDef );
+ DataObject typeDef = testHelper.createTypeDef("", typeName, true);
+ testHelper.createPropertyDef(typeDef, "p1", "commonj.sdo#String", false, false);
+ testHelper.createPropertyDef(typeDef, "p2", "commonj.sdo#String", false, false);
+ testHelper.getTypeHelper().define(typeDef);
// create a DataObject that uses this type
- DataObject dobj = testHelper.getDataFactory().create( "", typeName );
+ DataObject dobj = testHelper.getDataFactory().create("", typeName);
- // getInstanceProperties() should return p1, p2 even though they are not set
- //System.out.println(dobj.getInstanceProperties());
- assertEquals( 2, dobj.getInstanceProperties().size() );
+ // getInstanceProperties() should return p1, p2 even though they are not
+ // set
+ // System.out.println(dobj.getInstanceProperties());
+ assertEquals(2, dobj.getInstanceProperties().size());
- dobj.set( "p1", "foo" );
+ dobj.set("p1", "foo");
// getInstanceProperties() should still return p1, p2
- assertEquals( 2, dobj.getInstanceProperties().size() );
+ assertEquals(2, dobj.getInstanceProperties().size());
- dobj.unset( "p1" );
+ dobj.unset("p1");
// getInstanceProperties() should still return p1, p2
- assertEquals( 2, dobj.getInstanceProperties().size() );
+ assertEquals(2, dobj.getInstanceProperties().size());
// set an on-demand open content property
- dobj.set( "p3", "foo" );
+ dobj.set("p3", "foo");
// getInstanceProperties() should now return p1, p2, p3
- assertEquals( 3, dobj.getInstanceProperties().size() );
+ assertEquals(3, dobj.getInstanceProperties().size());
// unset the on-demand property
- dobj.unset( "p3" );
+ dobj.unset("p3");
- // the spec says that open content properties only appear in getInstancePropeties if
+ // the spec says that open content properties only appear in
+ // getInstancePropeties if
// they are set so we expect the list to be smaller now
- assertEquals( 2, dobj.getInstanceProperties().size() );
+ assertEquals(2, dobj.getInstanceProperties().size());
+ }
+
+ public void testIsSet_Boolean_false() throws Exception {
+
+ // define a type with two properties
+ String typeName = testHelper.createUniqueName();
+ DataObject typeDef = testHelper.createTypeDef("", typeName, true);
+ testHelper.createPropertyDef(typeDef, "b1", "commonj.sdo#Boolean", false, false);
+ testHelper.getTypeHelper().define(typeDef);
+
+ // create a DataObject that uses this type
+ DataObject testDO = testHelper.getDataFactory().create("", typeName);
+
+ Property p = testDO.getProperty("b1");
+ testDO.unset(p);
+ assertFalse("testing that property is unset after unset is called", 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));
+ }
+
+ public void testIsSet_Boolean_true() throws Exception {
+
+ // define a type with two properties
+ String typeName = testHelper.createUniqueName();
+ DataObject typeDef = testHelper.createTypeDef("", typeName, true);
+ testHelper.createPropertyDef(typeDef, "b1", "commonj.sdo#Boolean", false, false);
+ testHelper.getTypeHelper().define(typeDef);
+
+ // create a DataObject that uses this type
+ DataObject testDO = testHelper.getDataFactory().create("", typeName);
+
+ Property p = testDO.getProperty("b1");
+ testDO.unset(p);
+ assertFalse("testing that property is unset after unset is called", 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
+ .isSet(p));
}
+ public void testIsSet_Integer_0() throws Exception {
+
+ // define a type with two properties
+ String typeName = testHelper.createUniqueName();
+ DataObject typeDef = testHelper.createTypeDef("", typeName, true);
+ testHelper.createPropertyDef(typeDef, "i1", "commonj.sdo#Integer", false, false);
+ testHelper.getTypeHelper().define(typeDef);
+
+ // create a DataObject that uses this type
+ DataObject testDO = testHelper.getDataFactory().create("", typeName);
+
+ Property p = testDO.getProperty("i1");
+ testDO.unset(p);
+ assertFalse("testing that property is unset after unset is called", 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));
+ }
+
+ public void testIsSet_Integer_1() throws Exception {
+
+ // define a type with two properties
+ String typeName = testHelper.createUniqueName();
+ DataObject typeDef = testHelper.createTypeDef("", typeName, true);
+ testHelper.createPropertyDef(typeDef, "i1", "commonj.sdo#Integer", false, false);
+ testHelper.getTypeHelper().define(typeDef);
+
+ // create a DataObject that uses this type
+ DataObject testDO = testHelper.getDataFactory().create("", typeName);
+ try {
+ Property p = testDO.getProperty("default");
+ System.out.println(" default " + p);
+ } catch (Exception e) {
+ System.out.println("coudl not get default " + e.toString());
+ }
+
+ Property p = testDO.getProperty("i1");
+ testDO.unset(p);
+ assertFalse("testing that property is unset after unset is called", 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));
+ }
+
+ public void testIsSet_int_1() throws Exception {
+
+ // define a type with two properties
+ String typeName = testHelper.createUniqueName();
+ DataObject typeDef = testHelper.createTypeDef("", typeName, true);
+ Type intType = testHelper.getTypeHelper().getType("commonj.sdo", "Int");
+
+ testHelper.createPropertyDef(typeDef, "i1", intType, false, false);
+ testHelper.getTypeHelper().define(typeDef);
+
+ // create a DataObject that uses this type
+ DataObject testDO = testHelper.getDataFactory().create("", typeName);
+
+ Property p = testDO.getProperty("i1");
+ testDO.unset(p);
+ assertFalse("testing that property is unset after unset is called", 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));
+ }
+
+ public void testIsSet_int_0() throws Exception {
+ try {
+
+ // define a type with two properties
+ String typeName = testHelper.createUniqueName();
+ DataObject typeDef = testHelper.createTypeDef("", typeName, true);
+ Type intType = testHelper.getTypeHelper().getType("commonj.sdo", "Int");
+ testHelper.createPropertyDef(typeDef, "i1", intType, false, false);
+ testHelper.getTypeHelper().define(typeDef);
+
+ // create a DataObject that uses this type
+ DataObject testDO = testHelper.getDataFactory().create("", typeName);
+
+ Property p = testDO.getProperty("i1");
+ testDO.unset(p);
+ assertFalse("testing that property is unset after unset is called", testDO.isSet(p));
+
+ testDO.set(p, 0);
+ if (debug) {
+ XMLHelper.INSTANCE.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));
+
+ } catch (Exception e) {
+ System.out.println("exception " + e.toString());
+ e.printStackTrace();
+ throw e;
+ }
+ }
}
Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/api/DynamicTypesFromSchemaTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/api/DynamicTypesFromSchemaTestCase.java?view=diff&rev=512241&r1=512240&r2=512241
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/api/DynamicTypesFromSchemaTestCase.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/api/DynamicTypesFromSchemaTestCase.java Tue Feb 27 04:54:57 2007
@@ -44,13 +44,14 @@
import commonj.sdo.helper.XSDHelper;
/**
- * Tests methods of DataGraph except for change summary which is tested elsewhere.
+ * Tests methods of DataGraph except for change summary which is tested
+ * elsewhere.
*/
public class DynamicTypesFromSchemaTestCase extends TestCase {
private final String DYNAMIC_ROOT_TYPE_0 = "TestType0";
private final String DYNAMIC_ROOT_TYPE_1 = "TestType1";
-
+
private final String DYNAMIC_ROOT_TYPE_2 = "TestType2";
private final String DYNAMIC_TYPES_SCHEMA = "/dynamicTypesFromSchema.xsd";
@@ -62,11 +63,11 @@
private final String TEST_XML_DOC_0 = "/dynamicTypesFromSchema0.xml";
private final String TEST_XML_DOC_1 = "/dynamicTypesFromSchema1.xml";
-
+
private final String TEST_XML_DOC_2 = "/dynamicTypesFromSchema2.xml";
private List typeList;
-
+
/**
* Set of tests for dynamic types.
*/
@@ -76,7 +77,7 @@
protected void setUp() throws Exception {
super.setUp();
- TestHelper testHelper = CTSSuite.getTestHelper();
+ TestHelper testHelper = CTSSuite.getTestHelper();
hc = testHelper.createHelperContext();
// Populate the meta data for the types defined in schema
@@ -86,7 +87,7 @@
typeList = xsdHelper.define(inputStream, url.toString());
inputStream.close();
}
-
+
/**
* test of Schema complex types
*/
@@ -102,7 +103,7 @@
if (obj instanceof Type) {
typeNameSet.add(((Type)obj).getName());
} else {
- fail("a type list entry was not a type: "+obj.toString());
+ fail("a type list entry was not a type: " + obj.toString());
}
}
assertTrue(typeNameSet.contains("Address"));
@@ -135,7 +136,7 @@
if (hc == null) {
fail("the HelperContext unexpectedly null");
}
-
+
TypeHelper th = hc.getTypeHelper();
Type rootType0 = th.getType(DYNAMIC_TYPES_URI, DYNAMIC_ROOT_TYPE_0);
@@ -159,7 +160,7 @@
if (obj instanceof Property) {
propNameSet.add(((Property)obj).getName());
} else {
- fail("getInstanceProperties list contained: "+obj.toString());
+ fail("getInstanceProperties list contained: " + obj.toString());
}
}
assertTrue(propNameSet.contains("anyURI"));
@@ -214,7 +215,7 @@
if (obj instanceof Property) {
propNameSet.add(((Property)obj).getName());
} else {
- fail("getInstanceProperties list contained: "+obj.toString());
+ fail("getInstanceProperties list contained: " + obj.toString());
}
}
assertTrue(propNameSet.contains("ID"));
@@ -243,7 +244,7 @@
assertTrue(propNameSet.contains("unsignedLong"));
assertTrue(propNameSet.contains("unsignedShort"));
}
-
+
/**
* test #2 of more Schema derived datatypes
*/
@@ -275,7 +276,7 @@
if (obj instanceof Property) {
propNameSet.add(((Property)obj).getName());
} else {
- fail("getInstanceProperties list contained: "+obj.toString());
+ fail("getInstanceProperties list contained: " + obj.toString());
}
}
assertTrue(propNameSet.contains("addresses"));
Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/conversion/DateConversionTest.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/conversion/DateConversionTest.java?view=diff&rev=512241&r1=512240&r2=512241
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/conversion/DateConversionTest.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/conversion/DateConversionTest.java Tue Feb 27 04:54:57 2007
@@ -38,11 +38,10 @@
// TODO: Could convert to a paramatized test case and simplify this code a lot
/**
- * Set of tests for date and time related conversions.
- * DateConversionTest insures that the
- * DataHelper conversions accurately retain the information in the
- * specified fields (e.g. month, day or year). It also provides coverage
- * for the DataHelper API.
+ * Set of tests for date and time related conversions. DateConversionTest
+ * insures that the DataHelper conversions accurately retain the information in
+ * the specified fields (e.g. month, day or year). It also provides coverage for
+ * the DataHelper API.
*/
public class DateConversionTest {
private static Calendar test_calendar;
@@ -80,12 +79,12 @@
new TestType("toYearMonthDay", new int[] {Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH});
/**
- * Junit 4.1 will execute this once prior to test cases being executed.
- * This sets up the Calendar with current date.
+ * Junit 4.1 will execute this once prior to test cases being executed. This
+ * sets up the Calendar with current date.
*/
@BeforeClass
public static void setupCalender() {
- data_helper = CTSSuite.getTestHelper().getDataHelper();
+ data_helper = CTSSuite.getTestHelper().getDataHelper();
test_calendar = new GregorianCalendar();
test_calendar.setTime(new Date(System.currentTimeMillis()));
test_date = test_calendar.getTime();
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org