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 [2/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/SequenceTest.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/api/SequenceTest.java?view=diff&rev=512241&r1=512240&r2=512241
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/api/SequenceTest.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/api/SequenceTest.java Tue Feb 27 04:54:57 2007
@@ -23,10 +23,15 @@
import static org.junit.Assert.assertEquals;
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.Before;
+import org.junit.After;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -42,446 +47,961 @@
*/
@RunWith(Parameterized.class)
public class SequenceTest extends BaseSDOParamatizedTest {
-
public SequenceTest(DataObject testDO, String description) {
super(testDO, description);
}
/**
- * testSequenceAPI tests the methods of the Sequence API
+ * getIndex is a private method used by the SequenceTest class to accept as
+ * input a Property and return the index of that Property within the
+ * 'Sequenced' Type
*/
- @Test
- public void testSequenceAPI() {
+ private int getIndex(Property property) {
DataObject sequenceDO = testDO.getDataObject("sequencedElem");
- Property numberProp = sequenceDO.getProperty("Numbers");
- Property letterProp = sequenceDO.getProperty("Letters");
- Property invalidProp = testDO.getProperty("dateVal");
+ List properties = sequenceDO.getType().getProperties();
+ int propertyIndex = -1;
+ int i = 0;
- int numberIndex = 0, letterIndex = 0, invalidIndex, sequenceSize = 0, sequenceIndex;
+ while (i < properties.size() && propertyIndex < 0) {
+ if (((Property)properties.get(i)).equals(property))
+ propertyIndex = i;
+ i++;
+ }
- List properties = sequenceDO.getType().getProperties();
+ return propertyIndex;
+ }
+
+ /**
+ * populateSequence is called before each test. It provides a set of
+ * consistent data for the tests to work with. The expected outcome of
+ * populateSequence is a Sequence as follows: {<Letters, "A">, <Letters,
+ * "B">, <Numbers, 5>, <Letters, "C">, <Numbers, 16>}
+ */
+ @Before
+ public void populateSequence() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ if (sequenceDO.getType().isSequenced()) {
+ Sequence sequence = sequenceDO.getSequence();
+
+ if (sequence.size() > 0)
+ emptySequence();
- invalidIndex = properties.size();
+ // Add elements to the Sequence by updating the DataObject
- for (int i = 0; i < properties.size(); i++) {
- if (((Property)properties.get(i)).equals(numberProp))
- numberIndex = i;
- else if (((Property)properties.get(i)).equals(letterProp))
- letterIndex = i;
+ List letterList = sequenceDO.getList("Letters");
+ List numberList = sequenceDO.getList("Numbers");
+
+ letterList.add("A");
+ letterList.add("B");
+ numberList.add(Integer.valueOf(5));
+ letterList.add("C");
+ numberList.add(Integer.valueOf(16));
}
+ }
- /**
- * Ensure that the DataObject is sequenced as expected.
- */
+ /**
+ * emptySequence is called after each test to ensure that actions from one
+ * test do not impact the data seen by subsequent tests.
+ */
+ @After
+ public void emptySequence() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
- assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. The test case may not proceed.",
- sequenceDO.getType().isSequenced());
+ if (sequenceDO.getType().isSequenced()) {
+ Sequence sequence = sequenceDO.getSequence();
- Sequence sequence = sequenceDO.getSequence();
- boolean errorCaught;
+ while (sequence.size() > 0)
+ sequence.remove(0);
+ }
+ }
+
+ /**
+ * Verify that Sequence.getProperty(index) throws an Exception for an
+ * invalid index.
+ */
+ @Test
+ public void getPropertyInvalidIndexException() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
- assertEquals("Sequence.size() returned an unexpected value.", sequence.size(), 0);
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
- /**
- * Verify that the index specified methods throw an Exception for an
- * invalid index.
- */
+ Sequence sequence = sequenceDO.getSequence();
try {
- errorCaught = false;
- sequence.getProperty(0);
+ sequence.getProperty(5);
+ fail("Sequence.getProperty(int) should throw an Exception when an " + "invalid index is provided.");
} catch (Exception e) {
- errorCaught = true;
}
+ }
- assertTrue("Sequence.getProperty() should throw an Exception when an invalid index is given.", errorCaught);
+ /**
+ * Verify that Sequence.getValue() throws an Exception for an invalid index.
+ */
+ @Test
+ public void getValueInvalidIndexException() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
try {
- errorCaught = false;
- sequence.remove(0);
+ sequence.getValue(5);
+ fail("Sequence.getValue(int) should throw an Exception when an invalid " + "index is provided.");
} catch (Exception e) {
- errorCaught = true;
}
- assertTrue("Sequence.remove() should throw an Exception when an invalid index is given.", errorCaught);
+ }
+
+ /**
+ * Verify that Sequence.remove() throws an Exception for an invalid index.
+ */
+ @Test
+ public void removeInvalidIndexException() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
try {
- errorCaught = false;
- sequence.getValue(0);
+ sequence.remove(-1);
+ fail("Sequence.remove(int) should throw an Exception when an invalid " + "index is provided.");
} catch (Exception e) {
- errorCaught = true;
}
- assertTrue("Sequence.getValue() should throw an Exception when an invalid index is given.", errorCaught);
+
+ }
+
+ /**
+ * Verify that Sequence.setValue() throws an Exception for an invalid index.
+ */
+ @Test
+ public void setValueInvalidIndexException() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
try {
- errorCaught = false;
- sequence.setValue(0, "attempt");
+ sequence.setValue(5, "attempt");
+ fail("Sequence.setValue(int, Object) should throw an Exception when an " + "invalid index is provided.");
} catch (Exception e) {
- errorCaught = true;
}
+ }
- assertTrue("Sequence.setValue() should throw an Exception when an invalid index is given.", errorCaught);
+ /**
+ * Verify that Sequence.size() returns the expected value.
+ */
+ @Test
+ public void testSize() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
- // Add elements to the Sequence by updating the DataObject
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
- List letterList = sequenceDO.getList("Letters");
- List numberList = sequenceDO.getList("Numbers");
+ Sequence sequence = sequenceDO.getSequence();
- letterList.add("A");
- letterList.add("B");
- numberList.add(Integer.valueOf(5));
- letterList.add("C");
- numberList.add(Integer.valueOf(16));
+ assertEquals("Sequence.size() returned an unexpected value.", sequence.size(), 5);
+ }
- sequenceSize = 5;
+ /**
+ * Verify that Sequence.getProperty() returns the expected values.
+ */
+ @Test
+ public void testGetProperty() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
- // The expected arrangement of sequence is as follows
- // {<Letters, "A">, <Letters, "B">, <Numbers, 5>, <Lettes, "C">,
- // <Numbers, 16>}
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
- /**
- * Verify performance of size, getProperty, and getValue
- */
+ Sequence sequence = sequenceDO.getSequence();
- assertEquals("Sequence.size() returned an unexpected value.", sequence.size(), sequenceSize);
+ assertEquals("Sequence.getProperty() returned an unexpected Property.",
+ sequenceDO.getProperty("Letters"),
+ sequence.getProperty(1));
+ assertEquals("Sequence.getProperty() returned an unexpected Property.",
+ sequenceDO.getProperty("Numbers"),
+ sequence.getProperty(4));
+ }
- assertEquals("Sequence.getProperty() returned an unexpected Property.", sequence.getProperty(1), letterProp);
+ /**
+ * Verify that Sequence.getValue() returns the expected values.
+ */
+ @Test
+ public void testGetValue() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
- assertEquals("Sequence.getProperty() returned an unexpected Property.", sequence.getProperty(4), numberProp);
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
- assertEquals("Sequence.getValue() returned an unexpected value.", sequence.getValue(0), "A");
+ Sequence sequence = sequenceDO.getSequence();
- assertEquals("Sequence.getValue() returned an unexpected value.", sequence.getValue(2), 5);
+ assertEquals("Sequence.getValue() returned an unexpected value.", "A", sequence.getValue(0));
+ assertEquals("Sequence.getValue() returned an unexpected value.", 5, sequence.getValue(2));
+ }
- /**
- * Use setValue to modify the Sequence, then verify the outcome
- */
+ /**
+ * Use Sequence.setValue() to modify the Sequence, then verify the outcome
+ */
+ @Test
+ public void testSetValue() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
sequence.setValue(1, "F");
- // Expect: {<Letters, "A">, <Letters, "F">, <Numbers, 5>, <Lettes, "C">,
+ // {<Letters, "A">, <Letters, "F">, <Numbers, 5>, <Letters, "C">,
// <Numbers, 16>}
assertEquals("Sequence.setValue() did not have the intended effect.", sequence.getValue(1), "F");
- /**
- * Use Sequence.remove() to modify the Sequence, then verify the outcome
- */
+ List letters = sequenceDO.getList("Letters");
+ assertEquals("Sequence.setValue() had an unexpected effect on the size of " + "the List in the underlying DataObject.",
+ 3,
+ letters.size());
+ assertEquals("Sequence.setValue() did not have the expected effect on the " + "underlying DataObject.",
+ "F",
+ (String)letters.get(1));
+ }
+
+ /**
+ * Use Sequence.remove() to modify the Sequence, then verify the outcome
+ */
+ @Test
+ public void testRemove() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
sequence.remove(1);
- sequenceSize--;
- // Expect: {<Letters, "A">, <Numbers, 5>, <Lettes, "C">, <Numbers, 16>}
- assertEquals("Sequence.remove() did not decrement the size of the Sequence.", sequence.size(), sequenceSize);
+ // {<Letters, "A">, <Numbers, 5>, <Letters, "C">, <Numbers, 16>}
- assertEquals("Sequence.remove() did not shift the elements as expected.", sequence.getValue(1), 5);
+ assertEquals("Sequence.remove() did not decrement the size of the Sequence.", 4, sequence.size());
+ assertEquals("Sequence.remove() did not shift the elements as expected.", 5, sequence.getValue(1));
- // TODO: Change the following to addText when the API is changed.
+ List letters = sequenceDO.getList("Letters");
+ assertEquals("Sequence.remove() did not have the expected effect on the size " + "of the List in the underlying DataObject.",
+ 2,
+ letters.size());
+ assertEquals("Sequence.remove() did not have the expected effect on the " + "underlying DataObject.",
+ "C",
+ (String)letters.get(1));
+ }
- /**
- * Use Sequence.add() to modify the Sequence, then verify the outcome
- */
+ /**
+ * Use Sequence.addText(String) to modify the Sequence, then verify the
+ * outcome
+ */
+ @Ignore("Uncomment the call to addText(String) in this test case when the API becomes available.")
+ @Test
+ public void testAddText() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
+
+ String addString = new String("Structured text at the end.");
+ // sequence.addText(addString);
+
+ // {<Letters, "A">, <Letters, "B">, <Numbers, 5>, <Letters, "C">,
+ // <Numbers, 16>, "Structured text at the end."}
+
+ assertEquals("Sequence.add(String) did not increment the size of the Sequence.", 6, sequence.size());
+ assertEquals("Sequence.add(String) did not place the correct value at the " + "correct index.",
+ addString,
+ sequence.getValue(5));
+ assertNull("Sequence.add(String) should result in a null Property in the final index.", sequence.getProperty(5));
+ }
+
+ /**
+ * Use Sequence.addText(int, String) to modify the Sequence, then verify the
+ * outcome
+ */
+ @Ignore("Uncomment the call to addText(int, String) in this test case when the API becomes available.")
+ @Test
+ public void testAddTextWithIndex() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
- sequence.add("Structured text at the end.");
- sequenceSize++;
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
- // Expect: {<Letters, "A">, <Numbers, 5>, <Lettes, "C">, <Numbers, 16>,
- // "Structured text at the end"}
+ Sequence sequence = sequenceDO.getSequence();
- assertEquals("Sequence.add(String) did not increment the size of the Sequence.", sequence.size(), sequenceSize);
+ String addString = new String("Structured text in the middle.");
+ // sequence.addText(2, addString);
- assertEquals("Sequence.add(String) did not place the correct value at the correct index.", sequence
- .getValue(sequenceSize - 1), "Structured text at the end.");
+ // {<Letters, "A">, <Letters, "B">, "Structured text in the middle.",
+ // <Numbers, 5>, <Letters, "C">, <Numbers, 16>}
- assertNull("Sequence.add(String) should result in a null Property in the final index.", sequence
- .getProperty(sequenceSize - 1));
+ assertEquals("Sequence.addText(int, String) did not increment the size " + "of the Sequence.", 6, sequence
+ .size());
+ assertEquals("Sequence.addText(int, String) did not place the correct value " + "at the correct index.",
+ addString,
+ sequence.getValue(2));
+ assertNull("Sequence.addText(int, String) should result in a null Property " + "in the specified index.",
+ sequence.getProperty(2));
+ }
- /**
- * Use Sequence.move() to modify the Sequence, then verify the outcome
- */
+ /**
+ * Use Sequence.move() to modify the Sequence, then verify the outcome
+ */
+ @Test
+ public void testMove() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
sequence.move(1, 3);
- // Expect: {<Letters, "A">, <Numbers, 16>, <Numbers, 5>, <Lettes, "C">,
- // "Structured text at the end"}
- assertEquals("Sequence.move() had an unexpected effect on the size of the Sequence.",
- sequence.size(),
- sequenceSize);
+ // {<Letters, "A">, <Letters, "C">, <Letters, "B">, <Numbers, 5>,
+ // <Numbers, 16>}
- assertEquals("Sequence.move() did not place the expected value at the expected location.",
- sequence.getValue(1),
- 16);
+ assertEquals("Sequence.move() had an unexpected effect on the size " + "of the Sequence.", 5, sequence.size());
+ assertEquals("Sequence.move() did not place the expected value at the " + "expected location.", "C", sequence
+ .getValue(1));
+ assertEquals("Sequence.move() had an unexpected effect on the index " + "following the move-to index.",
+ "B",
+ sequence.getValue(2));
+
+ List letters = sequenceDO.getList("Letters");
+ assertEquals("Sequence.remove() did not have the expected effect on the " + "size of the List in the underlying DataObject.",
+ 3,
+ letters.size());
+ assertEquals("Sequence.remove() did not have the expected effect on the " + "underlying DataObject.",
+ "A",
+ (String)letters.get(0));
+ assertEquals("Sequence.remove() did not have the expected effect on the " + "underlying DataObject.",
+ "C",
+ (String)letters.get(1));
+ assertEquals("Sequence.remove() did not have the expected effect on the " + "underlying DataObject.",
+ "B",
+ (String)letters.get(2));
+ }
- assertEquals("Sequence.move() had an unexpected effect on the index following the move-to index.", sequence
- .getValue(2), 5);
+ /**
+ * Verify that Sequence.move() throws an Exception for an invalid to index.
+ */
+ @Test
+ public void moveInvalidToIndexException() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
- /**
- * Attempt move with an invalid index and verify the error handling.
- */
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
try {
- errorCaught = false;
- sequence.move(0, 5);
+ sequence.move(5, 0);
+ fail("Sequence.move(int, int) should throw an Exception when an " + "invalid 'to' index is provided.");
} catch (Exception e) {
- errorCaught = true;
}
- assertTrue("Sequence.move() should throw an Exception when an invalid Exception is given.", errorCaught);
+ }
+
+ /**
+ * Verify that Sequence.move() throws an Exception for an invalid from
+ * index.
+ */
+ @Test
+ public void moveInvalidFromIndexException() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
+
+ try {
+ sequence.move(0, -1);
+ fail("Sequence.move(int, int) should throw an Exception when an invalid " + "'from' index is provided.");
+ } catch (Exception e) {
+ }
+ }
+
+ /**
+ * Use Sequence.add(Property, Object) to modify the Sequence, then verify
+ * the outcome
+ */
+ @Test
+ public void testAddPropertyObject() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
- /**
- * Use Sequence.add(Property, Object) to modify the Sequence, then
- * verify the outcome
- */
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
+ Property numberProp = sequenceDO.getProperty("Numbers");
sequence.add(numberProp, Integer.valueOf(8));
- sequenceSize++;
- // Expect: {<Letters, "A">, <Numbers, 16>, <Numbers, 5>, <Lettes, "C">,
- // "Structured text at the end", <Numbers, 8>}
+ // {<Letters, "A">, <Letters, "B">, <Numbers, 5>, <Letters, "C">,
+ // <Numbers, 16>, <Numbers, 8>}
+
+ assertEquals("Sequence.add(Property, Object) did not increment the size of " + "the Sequence.", 6, sequence
+ .size());
+ assertEquals("Sequence.add(Property, Object) did not place the expected " + "value at the expected index.",
+ 8,
+ sequence.getValue(5));
+ assertEquals("Sequence.add(Property, Object) did not place the expected " + "Property at the expected index.",
+ numberProp,
+ sequence.getProperty(5));
+
+ List numbers = sequenceDO.getList("Numbers");
+
+ assertEquals("Sequence.add(Property, Object) did not have the expected " + "effect on the size of the List in the underlying DataObject.",
+ 3,
+ numbers.size());
+ assertEquals("Sequence.add(Property, Object) did not have the expected " + "effect on the underlying DataObject.",
+ 5,
+ numbers.get(0));
+ assertEquals("Sequence.add(Property, Object) did not have the expected " + "effect on the underlying DataObject.",
+ 16,
+ numbers.get(1));
+ assertEquals("Sequence.add(Property, Object) did not have the expected " + "effect on the underlying DataObject.",
+ 8,
+ numbers.get(2));
+ }
+
+ /**
+ * Attempt add(Property, Object) with an invalid Property and verify the
+ * error handling
+ */
+ @Test
+ public void addPropertyObjectInvalidProperty() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
- assertEquals("Sequence.add(Property, Object) did not increment the size of the Sequence.",
- sequence.size(),
- sequenceSize);
- assertEquals("Sequence.add(Property, Object) did not place the expected value at the expected index.", sequence
- .getValue(sequenceSize - 1), 8);
-
- assertEquals("Sequence.add(Property, Object) did not place the expected Property at the expected index.",
- sequence.getProperty(sequenceSize - 1),
- numberProp);
- assertEquals("Sequence.add(Property, Object) did not place the expected Property at the expected index.",
- sequence.getProperty(sequenceSize - 1),
- numberProp);
-
- /**
- * Attempt add(Property, Object) with an invalid Property and verify the
- * error handling
- */
-
- try {
- errorCaught = false;
- sequence.add(invalidProp, "A");
- } catch (Exception e) {
- errorCaught = true;
- }
- assertTrue("Sequence.add(Property, Object) should throw an Exception when an invalid Property is given.",
- errorCaught);
-
- /**
- * Use Sequence.add(String, Object) to modify the Sequence, then verify
- * the outcome
- */
+ Sequence sequence = sequenceDO.getSequence();
+
+ try {
+ sequence.add(testDO.getProperty("dateVal"), "A");
+ fail("Sequence.add(Property, Object) should throw an Exception when an " + "invalid Property is provided.");
+ } catch (Exception e) {
+ }
+ }
+
+ /**
+ * Attempt add(Property, Object) with an invalid Object and verify the error
+ * handling
+ */
+ @Test
+ public void addPropertyObjectInvalidObject() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
+
+ try {
+ sequence.add(sequenceDO.getProperty("Numbers"), "A");
+ fail("Sequence.add(Property, Object) should throw an Exception when an " + "invalid Object is provided.");
+ } catch (Exception e) {
+ }
+ }
+
+ /**
+ * Use Sequence.add(String, Object) to modify the Sequence, then verify the
+ * outcome
+ */
+ @Test
+ public void testAddStringObject() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
sequence.add("Letters", "K");
- sequenceSize++;
- // Expect: {<Letters, "A">, <Numbers, 16>, <Numbers, 5>, <Lettes, "C">,
- // "Structured text at the end", <Numbers, 8>, <Letters, "K">}
+ // {<Letters, "A">, <Letters, "B">, <Numbers, 5>, <Letters, "C">,
+ // <Numbers, 16>, <Letters, "K">}
- assertEquals("Sequence.add(String, Object) did not increment the size of the Sequence.",
- sequence.size(),
- sequenceSize);
+ assertEquals("Sequence.add(String, Object) did not increment the size of the " + "Sequence.", 6, sequence
+ .size());
+ assertEquals("Sequence.add(String, Object) did not place the expected value at " + "the expected index.",
+ "K",
+ sequence.getValue(5));
+ assertEquals("Sequence.add(String, Object) did not place the expected Property " + "at the expected index.",
+ sequenceDO.getProperty("Letters"),
+ sequence.getProperty(5));
+
+ List letters = sequenceDO.getList("Letters");
+ assertEquals("Sequence.add(String, Object) did not have the expected effect on " + "the size of the List in the underlying DataObject.",
+ 4,
+ letters.size());
+ assertEquals("Sequence.add(String, Object) did not have the expected effect on " + "the underlying DataObject.",
+ "A",
+ (String)letters.get(0));
+ assertEquals("Sequence.add(String, Object) did not have the expected effect on " + "the underlying DataObject.",
+ "B",
+ (String)letters.get(1));
+ assertEquals("Sequence.add(String, Object) did not have the expected effect on " + "the underlying DataObject.",
+ "C",
+ (String)letters.get(2));
+ assertEquals("Sequence.add(String, Object) did not have the expected effect on " + "the underlying DataObject.",
+ "K",
+ (String)letters.get(3));
+ }
- assertEquals("Sequence.add(String, Object) did not place the expected value at the expected index.", sequence
- .getValue(sequenceSize - 1), "K");
+ /**
+ * Attempt add(String, Object) with an invalid String and verify the error
+ * handling
+ */
+ @Test
+ public void addStringObjectInvalidString() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
- assertEquals("Sequence.add(String, Object) did not place the expected Property at the expected index.",
- sequence.getProperty(sequenceSize - 1),
- letterProp);
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
- /**
- * Attempt add(String, Object) with an invalid String and verify the
- * error handling
- */
+ Sequence sequence = sequenceDO.getSequence();
try {
- errorCaught = false;
sequence.add("NoSuchProperty", "A");
+ fail("Sequence.add(String, Object) should throw an Exception when an " + "invalid String is provided.");
} catch (Exception e) {
- errorCaught = true;
}
- assertTrue("Sequence.add(String, Object) should throw an Exception when an invalid Property is given.",
- errorCaught);
+ }
- /**
- * Attempt add(String, Object) with an invalid Object and verify the
- * error handling
- */
+ /**
+ * Attempt add(String, Object) with an invalid Object and verify the error
+ * handling
+ */
+ @Test
+ public void addStringObjectInvalidObject() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
try {
- errorCaught = false;
sequence.add("Numbers", "A");
+ fail("Sequence.add(String, Object) should throw an Exception when an " + "invalid Object is provided.");
} catch (Exception e) {
- errorCaught = true;
}
- assertTrue("Sequence.add(String, Object) should throw an Exception when an invalid Object is given.",
- errorCaught);
+ }
+
+ /**
+ * Use Sequence.add(int, Object) to modify the Sequence, then verify the
+ * outcome
+ */
+ @Test
+ public void testAddIntObject() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
- /**
- * Use Sequence.add(int, Object) to modify the Sequence, then verify the
- * outcome
- */
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
- sequence.add(numberIndex, Integer.valueOf(10));
- sequenceSize++;
+ Sequence sequence = sequenceDO.getSequence();
- // Expect: {<Letters, "A">, <Numbers, 16>, <Numbers, 5>, <Lettes, "C">,
- // "Structured text at the end", <Numbers, 8>, <Letters, "K">, <Numbers,
- // 10>}
+ sequence.add(getIndex(sequenceDO.getProperty("Numbers")), Integer.valueOf(10));
- assertEquals("Sequence.add(int, Object) did not increment the size of the Sequence.",
- sequence.size(),
- sequenceSize);
- assertEquals("Sequence.add(int, Object) did not place the expected value at the expected index.", sequence
- .getValue(sequenceSize - 1), 10);
+ // {<Letters, "A">, <Letters, "B">, <Numbers, 5>, <Letters, "C">,
+ // <Numbers, 16>, <Numbers, 10>}
- assertEquals("Sequence.add(int, Object) did not place the expected Property at the expected index.", sequence
- .getProperty(sequenceSize - 1), numberProp);
+ assertEquals("Sequence.add(Property, Object) did not increment the size of " + "the Sequence.", 6, sequence
+ .size());
+ assertEquals("Sequence.add(Property, Object) did not place the expected value " + "at the expected index.",
+ 10,
+ sequence.getValue(5));
+ assertEquals("Sequence.add(Property, Object) did not place the expected " + "Property at the expected index.",
+ sequenceDO.getProperty("Numbers"),
+ sequence.getProperty(5));
+
+ List numbers = sequenceDO.getList("Numbers");
+
+ assertEquals("Sequence.add(Property, Object) did not have the expected effect " + "on the size of the List in the underlying DataObject.",
+ 3,
+ numbers.size());
+ assertEquals("Sequence.add(Property, Object) did not have the expected effect " + "on the underlying DataObject.",
+ 5,
+ numbers.get(0));
+ assertEquals("Sequence.add(Property, Object) did not have the expected effect " + "on the underlying DataObject.",
+ 16,
+ numbers.get(1));
+ assertEquals("Sequence.add(Property, Object) did not have the expected effect " + "on the underlying DataObject.",
+ 10,
+ numbers.get(2));
+ }
- /**
- * Attempt add(int, Object) with an invalid Object and verify the error
- * handling
- */
+ /**
+ * Attempt add(int, Object) with an invalid int and verify the error
+ * handling
+ */
+ @Test
+ public void addIntObjectInvalidInt() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
+
+ List properties = sequenceDO.getType().getProperties();
+ int invalidIndex = properties.size();
try {
- errorCaught = false;
sequence.add(invalidIndex, Integer.valueOf(16));
+ fail("Sequence.add(int, Object) should throw an Exception when an " + "invalid index is provided.");
+ } catch (Exception e) {
+ }
+ }
+
+ /**
+ * Attempt add(int, Object) with an invalid Object and verify the error
+ * handling
+ */
+ @Test
+ public void addIntObjectInvalidObject() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
+
+ try {
+ sequence.add(getIndex(sequenceDO.getProperty("Letters")), 7);
+ fail("Sequence.add(int, Object) should throw an Exception when an " + "invalid Object is provided.");
+ } catch (Exception e) {
+ }
+ }
+
+ /**
+ * Use Sequence.add(int, String, Object) to modify the Sequence, then verify
+ * the outcome
+ */
+ @Test
+ public void testAddIntStringObject() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
+
+ int sequenceIndex = 0;
+
+ sequence.add(sequenceIndex, "Numbers", Integer.valueOf(10));
+
+ // {<Numbers, 10>, <Letters, "A">, <Letters, "B">, <Numbers, 5>,
+ // <Letters, "C">, <Numbers, 16>}
+
+ assertEquals("Sequence.add(int, String, Object) did not increment the size " + "of the Sequence.", 6, sequence
+ .size());
+ assertEquals("Sequence.add(int, String, Object) did not place the expected " + "value at the expected index.",
+ 10,
+ sequence.getValue(sequenceIndex));
+ assertEquals("Sequence.add(int, String, Object) did not place the expected " + "Property at the expected index.",
+ sequenceDO.getProperty("Numbers"),
+ sequence.getProperty(sequenceIndex));
+
+ List numbers = sequenceDO.getList("Numbers");
+ assertEquals("Sequence.add(int, String, Object) did not have the expected " + "effect on the size of the List in the underlying DataObject.",
+ 3,
+ numbers.size());
+ assertEquals("Sequence.add(int, String, Object) did not have the expected " + "effect on the underlying DataObject.",
+ 10,
+ (String)numbers.get(0));
+ assertEquals("Sequence.add(int, String, Object) did not have the expected " + "effect on the underlying DataObject.",
+ 5,
+ (String)numbers.get(1));
+ assertEquals("Sequence.add(int, String, Object) did not have the expected " + "effect on the underlying DataObject.",
+ 16,
+ (String)numbers.get(2));
+ }
+
+ /**
+ * Attempt add(int, String, Object) with an invalid int and verify the error
+ * handling
+ */
+ @Test
+ public void addIntStringObjectInvalidInt() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
+
+ try {
+ sequence.add(-1, "Letters", "A");
+ fail("Sequence.add(int, String, Object) should throw an Exception when " + "an invalid Sequence index is provided.");
+ } catch (Exception e) {
+ }
+ }
+
+ /**
+ * Attempt add(int, String, Object) with an invalid String and verify the
+ * error handling
+ */
+ @Test
+ public void addIntStringObjectInvalidString() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
+
+ try {
+ sequence.add(0, "Does Not Exist", "A");
+ fail("Sequence.add(int, String, Object) should throw an Exception when an " + "invalid String is provided.");
+ } catch (Exception e) {
+ }
+ }
+
+ /**
+ * Attempt add(int, String, Object) with an invalid Object and verify the
+ * error handling
+ */
+ @Test
+ public void addIntStringObjectInvalidObject() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
+
+ try {
+ sequence.add(0, "Numbers", "A");
+ fail("Sequence.add(int, String, Object) should throw an Exception when an " + "invalid Object is provided.");
+ } catch (Exception e) {
+ }
+ }
+
+ /**
+ * Use Sequence.add(int, Property, Object) to modify the Sequence, then
+ * verify the outcome
+ */
+ @Test
+ public void testAddIntPropertyObject() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
+
+ int sequenceIndex = 3;
+ sequence.add(sequenceIndex, "Letters", "K");
+
+ // {<Letters, "A">, <Letters, "B">, <Numbers, 5>, <Letters, "K">,
+ // <Letters, "C">, <Numbers, 16>}
+
+ assertEquals("Sequence.add(int, Property, Object) did not increment the " + "size of the Sequence.",
+ 6,
+ sequence.size());
+ assertEquals("Sequence.add(int, Property, Object) did not place the expected " + "value at the expected index.",
+ "K",
+ sequence.getValue(sequenceIndex));
+ assertEquals("Sequence.add(int, Property, Object) did not place the expected " + "Property at the expected index.",
+ sequenceDO.getProperty("Letters"),
+ sequence.getProperty(sequenceIndex));
+
+ List letters = sequenceDO.getList("Letters");
+ assertEquals("Sequence.add(int, Property, Object) did not have the expected " + "effect on the size of the List in the underlying DataObject.",
+ 4,
+ letters.size());
+ assertEquals("Sequence.add(int, Property, Object) did not have the expected " + "effect on the underlying DataObject.",
+ "A",
+ (String)letters.get(0));
+ assertEquals("Sequence.add(int, Property, Object) did not have the expected " + "effect on the underlying DataObject.",
+ "B",
+ (String)letters.get(1));
+ assertEquals("Sequence.add(int, Property, Object) did not have the expected " + "effect on the underlying DataObject.",
+ "K",
+ (String)letters.get(2));
+ assertEquals("Sequence.add(int, Property, Object) did not have the expected " + "effect on the underlying DataObject.",
+ "C",
+ (String)letters.get(3));
+ }
+
+ /**
+ * Attempt add(int, Property, Object) with an invalid int and verify the
+ * error handling
+ */
+ @Test
+ public void addIntPropertyObjectInvalidInt() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
+
+ try {
+ sequence.add(-1, sequenceDO.getProperty("Letters"), "A");
+ fail("Sequence.add(int, Property, Object) should throw an Exception when " + "an invalid Sequence index is provided.");
+ } catch (Exception e) {
+ }
+ }
+
+ /**
+ * Attempt add(int, Property, Object) with an invalid Property and verify
+ * the error handling
+ */
+ @Test
+ public void addIntPropertyObjectInvalidProperty() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
+
+ try {
+ sequence.add(0, testDO.getProperty("dateVal"), "A");
+ fail("Sequence.add(int, Property, Object) should throw an Exception " + "when an invalid Property is provided.");
+ } catch (Exception e) {
+ }
+ }
+
+ /**
+ * Attempt add(int, Property, Object) with an invalid Object and verify the
+ * error handling
+ */
+ @Test
+ public void addIntPropertyObjectInvalidObject() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
+
+ try {
+ sequence.add(0, sequenceDO.getProperty("Numbers"), "A");
+ fail("Sequence.add(int, Property, Object) should throw an Exception when " + "an invalid Object is provided.");
} catch (Exception e) {
- errorCaught = true;
}
+ }
+
+ /**
+ * Use Sequence.add(int, int, Object) to modify the Sequence, then verify
+ * the outcome
+ */
+ @Test
+ public void testAddIntIntObject() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
+
+ int sequenceIndex = 5;
+
+ sequence.add(sequenceIndex, "Numbers", Integer.valueOf(10));
- assertTrue("Sequence.add(int, Object) should throw an Exception when an invalid index is given.", errorCaught);
+ // {<Letters, "A">, <Letters, "B">, <Numbers, 5>, <Letters, "C">,
+ // <Numbers, 16>, <Numbers, 10>}
- /**
- * Use Sequence.add(int, String, Object) to modify the Sequence, then
- * verify the outcome TODO This section is commented out until
- * Tuscany-931 is resolved.
- */
-
- /*
- * sequenceIndex = 1; sequence.add(sequenceIndex, "Numbers",
- * Integer.valueOf(-4)); sequenceSize++; // Expect: {<Letters, "A">,
- * <Numbers, -4>, <Numbers, 16>, <Numbers, 5>, <Lettes, "C">,
- * "Structured text at the end", // <Numbers, 8>, <Letters, "K">,
- * <Numbers, 10>} if (sequence.size() != sequenceSize) throw new
- * ExpectedConditionError("Sequence.add(int, String, Object) did not
- * increment the size of the Sequence.", Integer.valueOf(sequenceSize),
- * Integer.valueOf(sequence.size())); if
- * (!(sequence.getValue(sequenceIndex).equals(Integer.valueOf(-4))))
- * throw new ExpectedConditionError("Sequence.add(int, String, Object)
- * did not place the expected value at the expected index.",
- * Integer.valueOf(-4), sequence.getValue(sequenceIndex)); if
- * (!(sequence.getProperty(sequenceIndex).equals(numberProp))) throw new
- * ExpectedConditionError("Sequence.add(int, String, Object) did not
- * place the expected Property at the expected index.", numberProp,
- * sequence.getProperty(sequenceIndex));
- */
- /**
- * Use Sequence.add(int, Property, Object) to modify the Sequence, then
- * verify the outcome TODO This section is commented out until
- * Tuscany-931 is resolved.
- */
- /*
- * sequenceIndex = 0; sequence.add(sequenceIndex, numberProp,
- * Integer.valueOf(17)); sequenceSize++; // Expect: {<Numbers, 17>,
- * <Letters, "A">, <Numbers, -4>, <Numbers, 16>, <Numbers, 5>, <Lettes,
- * "C">, "Structured text at the end", // <Numbers, 8>, <Letters, "K">,
- * <Numbers, 10>} if (sequence.size() != sequenceSize) throw new
- * ExpectedConditionError("Sequence.add(int, Property, Object) did not
- * increment the size of the Sequence.", Integer.valueOf(sequenceSize),
- * Integer.valueOf(sequence.size())); if
- * (!(sequence.getValue(sequenceIndex).equals(Integer.valueOf(17))))
- * throw new ExpectedConditionError("Sequence.add(int, Property, Object)
- * did not place the expected value at the expected index.",
- * Integer.valueOf(17), sequence.getValue(sequenceIndex)); if
- * (!(sequence.getProperty(sequenceIndex).equals(numberProp))) throw new
- * ExpectedConditionError("Sequence.add(int, Property, Object) did not
- * place the expected Property at the expected index.", numberProp,
- * sequence.getProperty(sequenceIndex));
- */
- /**
- * Use Sequence.add(int, int, Object) to modify the Sequence, then
- * verify the outcome TODO This section is commented out until
- * Tuscany-931 is resolved.
- */
- /*
- * sequenceIndex = 9; sequence.add(sequenceIndex, letterIndex, "S");
- * sequenceSize++; // Expect: {<Numbers, 17>, <Letters, "A">, <Numbers,
- * -4>, <Numbers, 16>, <Numbers, 5>, <Lettes, "C">, "Structured text at
- * the end", // <Numbers, 8>, <Letters, "K">, <Letters, "S">, <Numbers,
- * 10>} if (sequence.size() != sequenceSize) throw new
- * ExpectedConditionError("Sequence.add(int, Property, Object) did not
- * increment the size of the Sequence.", Integer.valueOf(sequenceSize),
- * Integer.valueOf(sequence.size())); if
- * (!(sequence.getValue(sequenceIndex).equals("S"))) throw new
- * ExpectedConditionError("Sequence.add(int, Property, Object) did not
- * place the expected value at the expected index.", "S",
- * sequence.getValue(sequenceIndex)); if
- * (!(sequence.getProperty(sequenceIndex).equals(letterProp))) throw new
- * ExpectedConditionError("Sequence.add(int, Property, Object) did not
- * place the expected Property at the expected index.", letterProp,
- * sequence.getProperty(sequenceIndex));
- */
-
- /**
- * Attempt Sequnce.add(int, int, Object) with an invalid Sequence index
- * and verify proper error handling.
- */
-
- try {
- errorCaught = false;
- sequence.add(sequence.size(), letterIndex, "Z");
- } catch (Exception e) {
- errorCaught = true;
- }
- assertTrue("Sequence.add(int, int, Object) should throw an Exception when an invalid Sequence index is given.",
- errorCaught);
-
- /**
- * Attempt Sequnce.add(int, int, Object) with an invalid Property index
- * and verify proper error handling.
- */
-
- sequenceIndex = 0;
- try {
- errorCaught = false;
- sequence.add(sequenceIndex, invalidIndex, "Z");
- } catch (Exception e) {
- errorCaught = true;
- }
- assertTrue("Sequence.add(int, int, Object) should throw an Exception when an invalid Property index is given.",
- errorCaught);
-
- /**
- * Attempt Sequnce.add(int, Property, Object) with an invalid Property
- * and verify proper error handling.
- */
-
- sequenceIndex = 0;
- try {
- errorCaught = false;
- sequence.add(sequenceIndex, invalidProp, "Z");
- } catch (Exception e) {
- errorCaught = true;
- }
-
- assertTrue("Sequence.add(int, int, Object) should throw an Exception when an invalid Property is given.",
- errorCaught);
-
- /**
- * Attempt Sequnce.add(int, int, Object) with an invalid Property name
- * and verify proper error handling.
- */
-
- sequenceIndex = 0;
- try {
- errorCaught = false;
- sequence.add(sequenceIndex, "notAValidProperty", "Z");
+ assertEquals("Sequence.add(int, String, Object) did not increment the size " + "of the Sequence.", 6, sequence
+ .size());
+ assertEquals("Sequence.add(int, String, Object) did not place the expected " + "value at the expected index.",
+ 10,
+ sequence.getValue(sequenceIndex));
+ assertEquals("Sequence.add(int, String, Object) did not place the expected " + "Property at the expected index.",
+ sequenceDO.getProperty("Numbers"),
+ sequence.getProperty(sequenceIndex));
+
+ List numbers = sequenceDO.getList("Numbers");
+ assertEquals("Sequence.add(int, String, Object) did not have the expected " + "effect on the size of the List in the underlying DataObject.",
+ 3,
+ numbers.size());
+ assertEquals("Sequence.add(int, String, Object) did not have the expected " + "effect on the underlying DataObject.",
+ 5,
+ (String)numbers.get(0));
+ assertEquals("Sequence.add(int, String, Object) did not have the expected " + "effect on the underlying DataObject.",
+ 16,
+ (String)numbers.get(1));
+ assertEquals("Sequence.add(int, String, Object) did not have the expected " + "effect on the underlying DataObject.",
+ 10,
+ (String)numbers.get(2));
+ }
+
+ /**
+ * Attempt add(int, int, Object) with an invalid Sequence index and verify
+ * the error handling
+ */
+ @Test
+ public void addIntIntObjectInvalidSequenceIndex() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
+
+ try {
+ sequence.add(6, getIndex(sequenceDO.getProperty("Letters")), "A");
+ fail("Sequence.add(int, int, Object) should throw an Exception when an " + "invalid Sequence index is provided.");
} catch (Exception e) {
- errorCaught = true;
}
- assertTrue("Sequence.add(int, int, Object) should throw an Exception when an invalid Property name is given.",
- errorCaught);
+ }
- // TODO: Test add(int, Object instaceof String) after add(int, String)
- // is changed to addText(int, String).
+ /**
+ * Attempt add(int, int, Object) with an invalid Property index and verify
+ * the error handling
+ */
+ @Test
+ public void addIntIntObjectInvalidPropertyIndex() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
+
+ try {
+ sequence.add(0, -1, "A");
+ fail("Sequence.add(int, int, Object) should throw an Exception when an " + "invalid Property index is provided.");
+ } catch (Exception e) {
+ }
}
+ /**
+ * Attempt add(int, int, Object) with an invalid Object and verify the error
+ * handling
+ */
+ @Test
+ public void addIntIntObjectInvalidObject() {
+ DataObject sequenceDO = testDO.getDataObject("sequencedElem");
+
+ assertTrue("The created Type 'Sequenced' has Type.isSequenced() == false. " + "The test cases may not proceed.",
+ sequenceDO.getType().isSequenced());
+
+ Sequence sequence = sequenceDO.getSequence();
+
+ try {
+ sequence.add(0, getIndex(sequenceDO.getProperty("Letters")), 8);
+ fail("Sequence.add(int, int, Object) should throw an Exception when an " + "invalid Object is provided.");
+ } catch (Exception e) {
+ }
+ }
}
Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/api/TypeHelperTest.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/api/TypeHelperTest.java?view=diff&rev=512241&r1=512240&r2=512241
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/api/TypeHelperTest.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/paramatizedTests/api/TypeHelperTest.java Tue Feb 27 04:54:57 2007
@@ -24,17 +24,20 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.util.ArrayList;
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.Type;
@@ -47,191 +50,327 @@
*/
@RunWith(Parameterized.class)
public class TypeHelperTest extends BaseSDOParamatizedTest {
-
public TypeHelperTest(DataObject testDO, String description) {
super(testDO, description);
}
/**
- * testTypeHelperAPI tests the methods in the TypeHelper API
+ * Verify the performance of TypeHelper.getType(URI, Name)
*/
@Test
- public void testTypeHelperAPI() {
+ public void getTypeByURI() {
Type testType = testDO.getType();
- TypeHelper types = HelperProvider.getTypeHelper();
- Type stringType = types.getType("commonj.sdo", "String");
- Type intType = types.getType("commonj.sdo", "Int");
- boolean errorCaught;
-
- /**
- * Verify the performance of TypeHelper.getType(URI, Name) and
- * TypeHelper.getType(Class)
- */
-
- Type returnedType = types.getType(testType.getURI(), testType.getName());
+ TypeHelper typeHelper = HelperProvider.getTypeHelper();
+ Type returnedType = typeHelper.getType(testType.getURI(), testType.getName());
assertTrue("TypeHelper.getType(URI, Name) did not return the expected Type.", ParamatizedTestUtil
.areEqualTypes(returnedType, testType));
- // TODO: should there be an else clause here ?
+ }
+
+ /**
+ * Verify the performance of TypeHelper.getType(Class)
+ */
+ @Test
+ public void getTypeByClass() {
+ Type testType = testDO.getType();
+
+ TypeHelper typeHelper = HelperProvider.getTypeHelper();
+ Type returnedType = typeHelper.getType(testType.getURI(), testType.getName());
+
if (testType.getInstanceClass() != null) {
- returnedType = types.getType(testType.getInstanceClass());
+ returnedType = typeHelper.getType(testType.getInstanceClass());
assertTrue("TypeHelper.getType(Class) did not return the expected Type.", ParamatizedTestUtil
.areEqualTypes(returnedType, testType));
}
+ }
+
+ /**
+ * Verify the proper performance of TypeHelper.getType(Class) when a non-SDO
+ * class is passed to TypeHelper.getType(Class)
+ */
+ @Test
+ public void getTypeWithNonSDOClass() {
+ TypeHelper typeHelper = HelperProvider.getTypeHelper();
+
+ assertNull("TypeHelper.getType(Class) should return null when no Type was defined for the interface Class.",
+ typeHelper.getType(TypeHelperTest.class));
+ }
+
+ /**
+ * Verify the proper performance of TypeHelper.getClass(URI, Name) when the
+ * namespace for URI does not include Name
+ */
+ @Test
+ public void getTypeByURIWithInvalidName() {
+ TypeHelper typeHelper = HelperProvider.getTypeHelper();
+
+ assertNull("TypeHelper.getType(URI, Name) should return null when no Type has the indicated Name in the URI namespace.",
+ typeHelper.getType(testDO.getType().getURI(), "UndefinedName"));
+ }
+
+ /**
+ * Verify the proper performance of TypeHelper.getClass(URI, Name) when the
+ * Name exists but not in the namespace of the URI
+ */
+ @Test
+ public void getTypeByURIWithInvalidURI() {
+ TypeHelper typeHelper = HelperProvider.getTypeHelper();
+
+ assertNull("TypeHelper.getType(URI, Name) should return null when no Type has the indicated Name in the URI namespace.",
+ typeHelper.getType("UndefinedURI", testDO.getType().getName()));
+ }
- /**
- * Verify the proper performance of TypeHelper.getType(Class) when a
- * non-SDO class is passed to TypeHelper.getType(Class)
- */
- assertNull("Types.getType(Class) should return null when no Type was defined for the interface Class.", types
- .getType(TypeHelperTest.class));
-
- /**
- * Verify the proper performance of TypeHelper.getClass(URI, Name) when
- * the namespace for URI does not include Name
- */
- assertNull("Types.getType(URI, Name) should return null when no Type has the indicated Name in the URI namespace.",
- types.getType(testDO.getType().getURI(), "UndefinedName"));
-
- /**
- * Verify the proper performance of TypeHelper.getClass(URI, Name) when
- * the Name exists but not in the namespace of the URI
- */
-
- assertNull("Types.getType(URI, Name) should return null when no Type has the indicated Name in the URI namespace.",
- types.getType("UndefinedURI", testDO.getType().getName()));
-
- /**
- * Verify the performance of TypeHelper.define(DataObject)
- */
+ /**
+ * Verify the performance of TypeHelper.define(DataObject), use
+ * DataFactory.create(URI, name) to verify
+ */
+ @Test
+ public void DefineByDataObjectCreateByURI() {
+ TypeHelper typeHelper = HelperProvider.getTypeHelper();
+ Type stringType = typeHelper.getType("commonj.sdo", "String");
DataObject defineTypeDO = CTSSuite.getTestHelper().getDataFactory().create("commonj.sdo", "Type");
defineTypeDO.set("uri", ParamatizedTestUtil.TEST_NAMESPACE);
- defineTypeDO.set("name", "DefinedType");
+ defineTypeDO.set("name", "DefinedType1");
DataObject IDProperty = defineTypeDO.createDataObject("property");
IDProperty.set("name", "ID");
IDProperty.set("type", stringType);
- Type definedType = types.define(defineTypeDO);
-
- /**
- * Attempt to create an instance of the newly defined Type.
- */
-
- DataObject result = CTSSuite.getTestHelper().getDataFactory().create(ParamatizedTestUtil.TEST_NAMESPACE, defineTypeDO.getString("name"));
+ DataObject DOProperty = defineTypeDO.createDataObject("property");
+ DOProperty.set("name", "contained");
+ DOProperty.set("type", testDO.getType());
+ Type definedType = typeHelper.define(defineTypeDO);
+
+ // Verify the Type definition by creating a DataObject of the newly
+ // defined Type via DataFactory.create(URI, name).
+
+ DataObject result =
+ CTSSuite.getTestHelper().getDataFactory().create(ParamatizedTestUtil.TEST_NAMESPACE,
+ defineTypeDO.getString("name"));
assertNotNull("CTSSuite.getTestHelper().getDataFactory() returned null", result);
- assertEquals("CTSSuite.getTestHelper().getDataFactory()e did not create a Type that could be instantiated.", result.getType()
- .getName(), "DefinedType");
+ assertEquals("CTSSuite.getTestHelper().getDataFactory()e did not create a Type that could be instantiated.",
+ result.getType().getName(),
+ "DefinedType1");
assertNotNull("CTSSuite.getTestHelper().getDataFactory() did not create a Type that could be instantiated, getProperty(ID) was null",
result.getProperty("ID"));
+ }
+
+ /**
+ * Verify the performance of TypeHelper.define(DataObject), use
+ * DataFactory.create(Type) to verify
+ */
+ @Test
+ public void DefineByDataObjectCreateByType() {
+ TypeHelper typeHelper = HelperProvider.getTypeHelper();
+ Type stringType = typeHelper.getType("commonj.sdo", "String");
+
+ DataObject defineTypeDO = CTSSuite.getTestHelper().getDataFactory().create("commonj.sdo", "Type");
+ defineTypeDO.set("uri", ParamatizedTestUtil.TEST_NAMESPACE);
+ defineTypeDO.set("name", "DefinedType2");
+ DataObject IDProperty = defineTypeDO.createDataObject("property");
+ IDProperty.set("name", "ID");
+ IDProperty.set("type", stringType);
+ DataObject DOProperty = defineTypeDO.createDataObject("property");
+ DOProperty.set("name", "contained");
+ DOProperty.set("type", testDO.getType());
+ Type definedType = typeHelper.define(defineTypeDO);
- result = CTSSuite.getTestHelper().getDataFactory().create(definedType);
+ // Verify the Type definition by creating a DataObject of the newly
+ // defined Type via DataFactory.create(Type)
+
+ DataObject result = CTSSuite.getTestHelper().getDataFactory().create(definedType);
assertNotNull("TypeHelper.define(DataObject) returned null", result);
assertEquals("TypeHelper.define(DataObject) did not create a Type that could be instantiated.", result
- .getType().getName(), "DefinedType");
+ .getType().getName(), "DefinedType2");
assertNotNull("TypeHelper.define(DataObject) did not create a Type that could be instantiated, getProperty(ID) was null",
result.getProperty("ID"));
+ }
- /**
- * Verify the performance of TypeHelper.define(List)
- */
-
- DataObject define1 = CTSSuite.getTestHelper().getDataFactory().create("commonj.sdo", "Type");
- define1.set("uri", ParamatizedTestUtil.TEST_NAMESPACE);
- define1.set("name", "Define1Type");
- DataObject firstNameProperty = define1.createDataObject("property");
+ /**
+ * Verify the performance of TypeHelper.define(List)
+ */
+ @Test
+ public void DefineByList() {
+ TypeHelper typeHelper = HelperProvider.getTypeHelper();
+ Type intType = typeHelper.getType("commonj.sdo", "Int");
+ Type stringType = typeHelper.getType("commonj.sdo", "String");
+
+ DataObject define3 = CTSSuite.getTestHelper().getDataFactory().create("commonj.sdo", "Type");
+ define3.set("uri", ParamatizedTestUtil.TEST_NAMESPACE);
+ define3.set("name", "DefinedType3");
+ DataObject firstNameProperty = define3.createDataObject("property");
firstNameProperty.set("name", "firstName");
firstNameProperty.set("type", stringType);
+ DataObject DOProperty = define3.createDataObject("property");
+ DOProperty.set("name", "contained");
+ DOProperty.set("type", testDO.getType());
- DataObject define2 = CTSSuite.getTestHelper().getDataFactory().create("commonj.sdo", "Type");
- define2.set("uri", ParamatizedTestUtil.TEST_NAMESPACE);
- define2.set("name", "Define2Type");
- DataObject lastNameProperty = define2.createDataObject("property");
+ DataObject define4 = CTSSuite.getTestHelper().getDataFactory().create("commonj.sdo", "Type");
+ define4.set("uri", ParamatizedTestUtil.TEST_NAMESPACE);
+ define4.set("name", "DefinedType4");
+ DataObject lastNameProperty = define4.createDataObject("property");
lastNameProperty.set("name", "lastName");
lastNameProperty.set("type", stringType);
+ DataObject DOProperty2 = define4.createDataObject("property");
+ DOProperty2.set("name", "contained");
+ DOProperty2.set("type", testDO.getType());
List DOList = new ArrayList();
- DOList.add(define1);
- DOList.add(define2);
+ DOList.add(define3);
+ DOList.add(define4);
+
+ List types = typeHelper.define(DOList);
- types.define(DOList);
+ assertEquals("TypeHelper.define(List) should define the same number of Types as is present in List.", 2, types
+ .size());
+ Type typeInList = (Type)types.get(0);
+ Type define4Type;
+ if (typeInList.getName().equals("DefinedType3")) {
+ typeInList = (Type)types.get(1);
+ assertEquals("TypeHelper.define(List) returned a List that did not include Types with the expected names.",
+ "DefinedType4",
+ typeInList.getName());
+ define4Type = typeInList;
+ } else {
+ define4Type = typeInList;
+ assertEquals("TypeHelper.define(List) returned a List that did not include Types with the expected names.",
+ "DefinedType4",
+ typeInList.getName());
+ typeInList = (Type)types.get(1);
+ assertEquals("TypeHelper.define(List) returned a List that did not include Types with the expected names.",
+ "DefinedType3",
+ typeInList.getName());
+ }
- result = CTSSuite.getTestHelper().getDataFactory().create(ParamatizedTestUtil.TEST_NAMESPACE, define1.getString("name"));
- assertNotNull("TypeHelper.define(List) did not create a Type that could be instantiated. result is null.",
+ // Attempt to create one of the Types using DataFactory.create(URI,
+ // name)
+
+ DataObject result =
+ CTSSuite.getTestHelper().getDataFactory().create(ParamatizedTestUtil.TEST_NAMESPACE,
+ define3.getString("name"));
+ assertNotNull("TypeHelper.define(List) did not create a Type that could be instantiated with DataFactory.create(URI, name). result is null.",
result);
- assertEquals("TypeHelper.define(List) did not create a Type that could be instantiated. getType() incorrect",
+ assertEquals("TypeHelper.define(List) did not create a Type that could be instantiated with DataFactory.create(URI, name). getType() incorrect",
result.getType().getName(),
- "Define1Type");
- assertNotNull("TypeHelper.define(List) did not create a Type that could be instantiated. firstName property returned null",
+ "DefinedType3");
+ assertNotNull("TypeHelper.define(List) did not create a Type that could be instantiated with DataFactory.create(URI, name). firstName property returned null",
result.getProperty("firstName"));
- result = CTSSuite.getTestHelper().getDataFactory().create(ParamatizedTestUtil.TEST_NAMESPACE, define2.getString("name"));
+ // Attempt to create the other type using DataFactory.create(Type)
+
+ result = CTSSuite.getTestHelper().getDataFactory().create(define4Type);
- assertNotNull("TypeHelper.define(List) did not create a Type that could be instantiated. result is null.",
+ assertNotNull("TypeHelper.define(List) did not create a Type that could be instantiated with DataFactory.create(Type). result is null.",
result);
- assertEquals("TypeHelper.define(List) did not create a Type that could be instantiated. getType() incorrect",
+ assertEquals("TypeHelper.define(List) did not create a Type that could be instantiated with DataFactory.create(Type). getType() incorrect",
result.getType().getName(),
- "Define2Type");
- assertNotNull("TypeHelper.define(List) did not create a Type that could be instantiated. lastName property returned null",
+ "DefinedType4");
+ assertNotNull("TypeHelper.define(List) did not create a Type that could be instantiated with DataFactory.create(Type). lastName property returned null",
result.getProperty("lastName"));
+ }
- // TODO: Determine what should happen when a Type is redefined (same URI
- // & Name, but different properties).
- // When this is known, uncomment the following and supply the
- // appropriate test.
- // While it's not clear to what should happen (from the spec), what is
- // happening is that there is no
- // notification of the duplication, and the originally defined Type is
- // returned by the define() in the latter instance.
-
- /*
- * DataObject define3 = CTSSuite.getTestHelper().getDataFactory().create("commonj.sdo",
- * "Type"); define3.set("uri", ParamatizedTestUtil.TEST_NAMESPACE);
- * define3.set("name", "Define2Type"); DataObject numProperty =
- * define3.createDataObject("property"); numProperty.set("name", "num");
- * numProperty.set("type",intType); definedType = types.define(define3);
- */
-
- /**
- * Attempt TypeHelper.define(List) when a member of the List is not a
- * DataObject.
- */
-
- DataObject define4 = CTSSuite.getTestHelper().getDataFactory().create("commonj.sdo", "Type");
- define4.set("uri", ParamatizedTestUtil.TEST_NAMESPACE);
- define4.set("name", "Define4Type");
- DataObject ID1Property = define4.createDataObject("property");
- ID1Property.set("name", "ID1");
- ID1Property.set("type", intType);
+ /**
+ * Verify the error handling of TypeHelper.define(List) when List contains a
+ * member that is not a DataObject
+ */
+ @Test
+ public void DefineByListInvalidListMember() {
+ TypeHelper typeHelper = HelperProvider.getTypeHelper();
+ Type intType = typeHelper.getType("commonj.sdo", "Int");
DataObject define5 = CTSSuite.getTestHelper().getDataFactory().create("commonj.sdo", "Type");
define5.set("uri", ParamatizedTestUtil.TEST_NAMESPACE);
- define5.set("name", "Define5Type");
- DataObject ID2Property = define5.createDataObject("property");
+ define5.set("name", "DefinedType5");
+ DataObject ID1Property = define5.createDataObject("property");
+ ID1Property.set("name", "ID1");
+ ID1Property.set("type", intType);
+ DataObject DOProperty = define5.createDataObject("property");
+ DOProperty.set("name", "contained");
+ DOProperty.set("type", testDO.getType());
+
+ DataObject define6 = CTSSuite.getTestHelper().getDataFactory().create("commonj.sdo", "Type");
+ define6.set("uri", ParamatizedTestUtil.TEST_NAMESPACE);
+ define6.set("name", "DefinedType6");
+ DataObject ID2Property = define6.createDataObject("property");
ID2Property.set("name", "ID2");
ID2Property.set("type", intType);
- DOList.clear();
- DOList.add(define4);
- DOList.add("A");
+ List DOList = new ArrayList();
DOList.add(define5);
+ DOList.add("A");
+ DOList.add(define6);
try {
- errorCaught = false;
- types.define(DOList);
+ typeHelper.define(DOList);
+ fail("TypeHelper.define(List) should throw an Exception when List " + "contains a member that is not a DataObject.");
} catch (Exception e) {
- errorCaught = true;
+ // Do nothing
}
- assertTrue("TypeHelper.define(List) should throw an Exception when the List contains a member " + "that is not a DataObject",
- errorCaught);
+ }
- // TODO: Determine whether the other members of the list (particularly
- // those preceeding the non DataObject) should
- // now be defined Types. Not clear in the spec what should happen. What
- // currently happens is that those members
- // before the Exception are defined, but those after (in the List) are
- // not. Because of the Exception, there is no
- // return value from define(List). This would require some involved
- // error-case checking by the user to recover from.
+ /**
+ * Verify the expected behavior of TypeHelper.define(DataObject) when a Type
+ * of the same name has already been defined differently.
+ */
+ @Test
+ public void singleRedefinitionDifferent() {
+ fail(TestHelper.INCOMPLETE_TEST_CASE_FAILURE);
+
+ TypeHelper typeHelper = HelperProvider.getTypeHelper();
+ Type intType = typeHelper.getType("commonj.sdo", "Int");
+
+ // Determine what should happen when a Type is redefined (same URI
+ // & Name, but different properties).
+ // When this is known, uncomment the following and supply the
+ // appropriate test.
+ // While it's not clear to what should happen (from the spec), what is
+ // happening is that there is no
+ // notification of the duplication, and the originally defined Type is
+ // returned by the define() in the latter instance.
+
+ DataObject defineDO = CTSSuite.getTestHelper().getDataFactory().create("commonj.sdo", "Type");
+ defineDO.set("uri", ParamatizedTestUtil.TEST_NAMESPACE);
+ defineDO.set("name", "DefineTypeAgain");
+ DataObject numProperty = defineDO.createDataObject("property");
+ numProperty.set("name", "num");
+ numProperty.set("type", intType);
+
+ Type definedType = typeHelper.define(defineDO);
+
+ DataObject defineDO2 = CTSSuite.getTestHelper().getDataFactory().create("commonj.sdo", "Type");
+ defineDO2.set("uri", ParamatizedTestUtil.TEST_NAMESPACE);
+ defineDO2.set("name", "DefineTypeAgain");
+ DataObject DOProperty = defineDO2.createDataObject("property");
+ DOProperty.set("name", "contained");
+ DOProperty.set("type", testDO.getType());
+
+ Type definedType2 = typeHelper.define(defineDO2);
+ }
+
+ /**
+ * Verify the expected behavior of TypeHelper.define(DataObject) when a Type
+ * of the same name has already been defined, but defined identically.
+ */
+ @Test
+ public void singleRedefinitionSame() {
+ fail(TestHelper.INCOMPLETE_TEST_CASE_FAILURE);
+ }
+
+ /**
+ * Verify the expected behavior of TypeHelper.define(List) when an element
+ * of the List has already been defined differently.
+ */
+ @Test
+ public void listRedefinitionDifferent() {
+ fail(TestHelper.INCOMPLETE_TEST_CASE_FAILURE);
+ }
+
+ /**
+ * Verify the expected behavior of TypeHelper.define(List) when an element
+ * of the List has already been defined identically.
+ */
+ @Test
+ public void listRedefinitionSame() {
+ fail(TestHelper.INCOMPLETE_TEST_CASE_FAILURE);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org