use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDOSequenceTestCS method test_addAll_complexMany.
/**
* Sets the entry at a specified index to the new value.
* @param index the index of the entry.
* @param value the new value for the entry.
*/
public void test_addAll_complexMany() {
// int index, Object value) {
defineAndLoadRoot(false, false);
SDOSequence aSequence = getSequence(root, PO_SEQUENCE_PATH, PO_SEQUENCE_SIZE);
DataObject po = (DataObject) root.get(PO_SEQUENCE_PATH);
int treeSizeBeforeAdd = preOrderTraversalDataObjectList(po).size();
assertEquals(PO_TREE_SIZE, treeSizeBeforeAdd);
assertEquals(PO_SEQUENCE_SIZE, aSequence.size());
ListWrapper existingList = (ListWrapper) po.get("item");
int listSizeBefore = existingList.size();
assertEquals(2, listSizeBefore);
int sequenceSizeBefore = aSequence.size();
int indexToPlaceAtEnd = aSequence.size() - 1;
// object to replace
DataObject item2 = (DataObject) root.get("item[2]");
assertNotNull(item2);
// object to add
DataObject item3 = (DataObject) root.get("item[1]");
assertNotNull(item3);
// add to sequence
// TODO: TEST setting a many property using an item instead of a List of items
// add the item to the current list
// add list of items to existing list
List<DataObject> aListToAdd = new ArrayList<DataObject>();
aListToAdd.add(item3);
// add to the end of the list
existingList.addAll(aListToAdd);
// verify that the list has increased on the do
int listSizeAfter = ((ListWrapper) po.get("item")).size();
assertEquals(listSizeBefore + aListToAdd.size(), listSizeAfter);
// verify that the sequence size has increased
assertEquals(sequenceSizeBefore + aListToAdd.size(), aSequence.size());
// get back new Setting value
SDODataObject item2Value = (SDODataObject) aSequence.getValue(aSequence.size() - 1);
assertNotNull(item2Value);
assertEquals(item2Value, aListToAdd.get(0));
assertNotNull(aSequence.getProperty(indexToPlaceAtEnd));
// check increased size of sequence
assertEquals(PO_SEQUENCE_TREE_SIZE + 1, aSequence.size());
// verify that DataObject has changed
int treeSizeAfterAdd = preOrderTraversalDataObjectList(po).size();
assertEquals(treeSizeBeforeAdd + 1, treeSizeAfterAdd);
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDOSequenceTestCS method testAddComplexManyByListWrapperAddPropertyOnExistingList.
public void testAddComplexManyByListWrapperAddPropertyOnExistingList() {
defineAndLoadRoot(false, false);
SDOSequence aSequence = getSequence(root, PO_SEQUENCE_PATH, PO_SEQUENCE_SIZE);
DataObject po = (DataObject) root.get(PO_SEQUENCE_PATH);
int treeSizeBeforeAdd = preOrderTraversalDataObjectList(po).size();
assertEquals(PO_TREE_SIZE, treeSizeBeforeAdd);
assertEquals(PO_SEQUENCE_SIZE, aSequence.size());
ListWrapper existingList = (ListWrapper) po.get("item");
int listSizeBefore = existingList.size();
assertEquals(2, listSizeBefore);
int indexToPlaceAtEnd = aSequence.size();
// object to add
DataObject item3 = (DataObject) root.get("item[1]");
assertNotNull(item3);
Property itemProperty = po.getInstanceProperty("item");
// add list of items to existing list
List<DataObject> aListToAdd = new ArrayList<DataObject>();
aListToAdd.add(item3);
aListToAdd.add(item3);
for (Iterator<DataObject> i = aListToAdd.iterator(); i.hasNext(); ) {
// add to the end of the list
existingList.add(i.next());
}
// verify that the list has increased on the do
int listSizeAfter = ((ListWrapper) po.get("item")).size();
assertEquals(listSizeBefore + aListToAdd.size(), listSizeAfter);
// verify that the sequence size has increased
assertEquals(indexToPlaceAtEnd + aListToAdd.size(), aSequence.size());
// get back new Setting value
SDODataObject item2Value = (SDODataObject) aSequence.getValue(indexToPlaceAtEnd + aListToAdd.size() - 1);
assertNotNull(item2Value);
assertEquals(item2Value, aListToAdd.get(0));
assertNotNull(aSequence.getProperty(indexToPlaceAtEnd));
// check increased size of sequence
assertEquals(PO_SEQUENCE_TREE_SIZE + aListToAdd.size(), aSequence.size());
// verify that DataObject has changed
int treeSizeAfterAdd = preOrderTraversalDataObjectList(po).size();
assertEquals(treeSizeBeforeAdd + aListToAdd.size(), treeSizeAfterAdd);
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDOSequenceTestCS method testAddAllDuplicatesComplexManyByListWrapperAddAllPropertyOnExistingList.
/*
public void testRemove1StOccurrenceComplexManyNonContainmentByListWrapperAddAllPropertyOnExistingList() {
defineAndLoadRoot(false, false);
SDOSequence aSequence = getSequence(root, PO_SEQUENCE_PATH, PO_SEQUENCE_SIZE);
DataObject po = (DataObject)root.get(PO_SEQUENCE_PATH);
int treeSizeBeforeAdd = preOrderTraversalDataObjectList(po).size();
assertEquals(PO_TREE_SIZE, treeSizeBeforeAdd);
assertEquals(PO_SEQUENCE_SIZE, aSequence.size());
ListWrapper existingList = (ListWrapper)po.get("item");
int listSizeBefore = existingList.size();
assertEquals(2, listSizeBefore);
int indexToPlaceAtEnd = aSequence.size();
// object to add
DataObject item3 = (DataObject)root.get("item[3]");
assertNotNull(item3);
Property itemProperty = po.getInstanceProperty("item");
// add list of items to existing list
List<DataObject> aListToAdd = new ArrayList<DataObject>();
aListToAdd.add(item3);
// add to the end of the list
existingList.addAll(aListToAdd);
// verify that the list has increased on the do
int listSizeAfter = ((ListWrapper)po.get("item")).size();
assertEquals(listSizeBefore + aListToAdd.size(), listSizeAfter);
// verify that the sequence size has increased
assertEquals(indexToPlaceAtEnd + aListToAdd.size(), aSequence.size());
// get back new Setting value
SDODataObject item2Value = (SDODataObject)aSequence.getValue(indexToPlaceAtEnd + aListToAdd.size() - 1);
assertNotNull(item2Value);
assertEquals(item2Value, aListToAdd.get(0));
assertNotNull(aSequence.getProperty(indexToPlaceAtEnd));
// check increased size of sequence
assertEquals(PO_SEQUENCE_TREE_SIZE + aListToAdd.size(), aSequence.size());
// verify that DataObject has changed
int treeSizeAfterAdd = preOrderTraversalDataObjectList(po).size();
assertEquals(treeSizeBeforeAdd + aListToAdd.size(), treeSizeAfterAdd);
// get sequence object that will be removed
SDOSetting aSetting5 = (SDOSetting)aSequence.getSettings().get(5);
SDOSetting aSetting6 = (SDOSetting)aSequence.getSettings().get(6);
// remove the first occurrence of the duplicated items in the sequence
existingList.remove(1);
// check size
assertEquals(indexToPlaceAtEnd, aSequence.size());
// verify that the correct index in the sequence was removed based on the listWrapper index
//assertEquals(aSetting6, aSequence.getSettings().get(5)); // 6 shifted into 5's place
//assertFalse(aSetting5 == aSequence.getSettings().get(5)); // 5 is gone
assertTrue(aSetting5 == aSequence.getSettings().get(5)); // 5 is still there
}
public void testRemove2ndOccurrenceComplexManyNonContainmentByListWrapperAddAllPropertyOnExistingList() {
defineAndLoadRoot(false, false);
SDOSequence aSequence = getSequence(root, PO_SEQUENCE_PATH, PO_SEQUENCE_SIZE);
DataObject po = (DataObject)root.get(PO_SEQUENCE_PATH);
int treeSizeBeforeAdd = preOrderTraversalDataObjectList(po).size();
assertEquals(PO_TREE_SIZE, treeSizeBeforeAdd);
assertEquals(PO_SEQUENCE_SIZE, aSequence.size());
ListWrapper existingList = (ListWrapper)po.get("item");
int listSizeBefore = existingList.size();
assertEquals(2, listSizeBefore);
int indexToPlaceAtEnd = aSequence.size();
// object to add
DataObject item3 = (DataObject)root.get("item[3]");
assertNotNull(item3);
Property itemProperty = po.getInstanceProperty("item");
// add list of items to existing list
List<DataObject> aListToAdd = new ArrayList<DataObject>();
aListToAdd.add(item3);
// add to the end of the list
existingList.addAll(aListToAdd);
// verify that the list has increased on the do
int listSizeAfter = ((ListWrapper)po.get("item")).size();
assertEquals(listSizeBefore + aListToAdd.size(), listSizeAfter);
// verify that the sequence size has increased
assertEquals(indexToPlaceAtEnd + aListToAdd.size(), aSequence.size());
// get back new Setting value
SDODataObject item2Value = (SDODataObject)aSequence.getValue(indexToPlaceAtEnd + aListToAdd.size() - 1);
assertNotNull(item2Value);
assertEquals(item2Value, aListToAdd.get(0));
assertNotNull(aSequence.getProperty(indexToPlaceAtEnd));
// check increased size of sequence
assertEquals(PO_SEQUENCE_TREE_SIZE + aListToAdd.size(), aSequence.size());
// verify that DataObject has changed
int treeSizeAfterAdd = preOrderTraversalDataObjectList(po).size();
assertEquals(treeSizeBeforeAdd + aListToAdd.size(), treeSizeAfterAdd);
// get sequence object that will be removed
SDOSetting aSetting5 = (SDOSetting)aSequence.getSettings().get(5);
SDOSetting aSetting6 = (SDOSetting)aSequence.getSettings().get(6);
// remove the first occurrence of the duplicated items in the sequence
existingList.remove(2);
// check size
assertEquals(indexToPlaceAtEnd, aSequence.size());
// verify that the correct index in the sequence was removed based on the listWrapper index
assertEquals(aSetting5, aSequence.getSettings().get(5)); // 6 shifted into 5's place
assertFalse(aSetting6 == aSequence.getSettings().get(5)); // 5 is gone
}*/
// TODO: Verify that existing duplicates will be removed before the new list is added - addAll same as set
public void testAddAllDuplicatesComplexManyByListWrapperAddAllPropertyOnExistingList() {
defineAndLoadRoot(false, false);
SDOSequence aSequence = getSequence(root, "/", 5);
int treeSizeBeforeAdd = preOrderTraversalDataObjectList(root).size();
assertEquals(10, treeSizeBeforeAdd);
assertEquals(5, aSequence.size());
ListWrapper existingList = (ListWrapper) root.get("item");
int listSizeBefore = existingList.size();
assertEquals(3, listSizeBefore);
int indexToPlaceAtEnd = aSequence.size();
// object to add
DataObject item3 = (DataObject) root.get("item[3]");
assertNotNull(item3);
Property itemProperty = root.getInstanceProperty("item");
// add list of items to existing list
List<DataObject> aListToAdd = new ArrayList<DataObject>();
aListToAdd.add(item3);
aListToAdd.add(item3);
aListToAdd.add(item3);
// add to the end of the list
existingList.addAll(aListToAdd);
// verify that the list has increased on the do
int listSizeAfter = ((ListWrapper) root.get("item")).size();
// TODO: We should not be removing the existing item?
int newItems = aListToAdd.size() - 3;
// assertEquals(listSizeBefore + aListToAdd.size(), listSizeAfter);
assertEquals(listSizeBefore + newItems, listSizeAfter);
// verify that the sequence size has increased
assertEquals(indexToPlaceAtEnd + newItems, aSequence.size());
// get back new Setting value
SDODataObject item2Value = (SDODataObject) aSequence.getValue(indexToPlaceAtEnd + newItems - 1);
assertNotNull(item2Value);
assertEquals(item2Value, aListToAdd.get(0));
assertNotNull(aSequence.getProperty(indexToPlaceAtEnd - 1));
// check increased size of sequence
assertEquals(indexToPlaceAtEnd + newItems, aSequence.size());
// verify that DataObject has changed
int treeSizeAfterAdd = preOrderTraversalDataObjectList(root).size();
assertEquals(treeSizeBeforeAdd + newItems, treeSizeAfterAdd);
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDOSequenceTestCS method testAddSimpleManyByDataObjectSetPropertyWithListOnExistingList.
public void testAddSimpleManyByDataObjectSetPropertyWithListOnExistingList() {
defineAndLoadRoot(false, false);
SDOSequence aSequence = getSequence(root, PO_SEQUENCE_PATH, PO_SEQUENCE_SIZE);
DataObject po = (DataObject) root.get(PO_SEQUENCE_PATH);
int treeSizeBeforeAdd = preOrderTraversalDataObjectList(po).size();
assertEquals(PO_TREE_SIZE, treeSizeBeforeAdd);
assertEquals(PO_SEQUENCE_SIZE, aSequence.size());
int listSizeBefore = ((ListWrapper) po.get("comment")).size();
assertEquals(PO_COMMENT_LIST_SIZE, listSizeBefore);
int indexToPlaceAtEnd = aSequence.size();
Property commentProperty = po.getInstanceProperty("comment");
// add list of items to sequence
List<String> aListToAdd = new ArrayList<String>();
aListToAdd.add("comment 2");
aListToAdd.add("comment 3");
aSequence.add(indexToPlaceAtEnd, commentProperty, aListToAdd);
// get back new Setting value
String comment2Value = (String) aSequence.getValue(indexToPlaceAtEnd);
assertNotNull(comment2Value);
assertEquals(comment2Value, aListToAdd.get(0));
assertNotNull(aSequence.getProperty(indexToPlaceAtEnd));
// check increased size of sequence for simple type
assertEquals(PO_SEQUENCE_TREE_SIZE + aListToAdd.size(), aSequence.size());
// verify that the list has increased
int listSizeAfter = ((ListWrapper) po.get("comment")).size();
assertEquals(listSizeBefore + aListToAdd.size(), listSizeAfter);
// verify that DataObject has changed but not the # of dataObjects
int treeSizeAfterAdd = preOrderTraversalDataObjectList(po).size();
assertEquals(treeSizeBeforeAdd + 0, treeSizeAfterAdd);
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDOSequenceTestCS method testAddComplexManyByDataObjectSetPropertyWithSingleItemOnExistingList.
public void testAddComplexManyByDataObjectSetPropertyWithSingleItemOnExistingList() {
defineAndLoadRoot(false, false);
SDOSequence aSequence = getSequence(root, PO_SEQUENCE_PATH, PO_SEQUENCE_SIZE);
DataObject po = (DataObject) root.get(PO_SEQUENCE_PATH);
int treeSizeBeforeAdd = preOrderTraversalDataObjectList(po).size();
assertEquals(PO_TREE_SIZE, treeSizeBeforeAdd);
assertEquals(PO_SEQUENCE_SIZE, aSequence.size());
int listSizeBefore = ((ListWrapper) po.get("item")).size();
assertEquals(2, listSizeBefore);
int indexToPlaceAtEnd = aSequence.size();
// object to add
DataObject item3 = (DataObject) root.get("item[3]");
assertNotNull(item3);
Property itemProperty = po.getInstanceProperty("item");
// add to sequence
aSequence.add(indexToPlaceAtEnd, itemProperty, item3);
// get back new Setting value
// ListWrapper item2Value = (ListWrapper)aSequence.getValue(indexToPlaceAtEnd);
SDODataObject item2Value = (SDODataObject) aSequence.getValue(indexToPlaceAtEnd);
assertNotNull(item2Value);
assertNotNull(aSequence.getProperty(indexToPlaceAtEnd));
// check increased size of sequence
assertEquals(PO_SEQUENCE_TREE_SIZE + 1, aSequence.size());
// verify that the list has increased
int listSizeAfter = ((ListWrapper) po.get("item")).size();
assertEquals(listSizeBefore + 1, listSizeAfter);
// verify that DataObject has changed
int treeSizeAfterAdd = preOrderTraversalDataObjectList(po).size();
assertEquals(treeSizeBeforeAdd + 1, treeSizeAfterAdd);
}
Aggregations