use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDOSequenceTestXSD method testAddComplexManyByDataObjectSetPropertyWithListOnExistingList.
public void testAddComplexManyByDataObjectSetPropertyWithListOnExistingList() {
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[1]");
assertNotNull(item3);
Property itemProperty = po.getInstanceProperty("item");
// add list of items to sequence
List<DataObject> aListToAdd = new ArrayList<DataObject>();
aListToAdd.add(item3);
aSequence.add(indexToPlaceAtEnd, itemProperty, aListToAdd);
// get back new Setting value
SDODataObject item2Value = (SDODataObject) aSequence.getValue(indexToPlaceAtEnd);
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 the list has increased
int listSizeAfter = ((ListWrapper) po.get("item")).size();
assertEquals(listSizeBefore + aListToAdd.size(), listSizeAfter);
// 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 SDOSequenceTestXSD method testAddAllComplexManyByListWrapperAddAllPropertyOnExistingList.
/*
// Purpose is to verify that a remove(item) for duplicates removes the first occurrence of that item.
public void testRemove1stOccurrenceSimpleManyByListWrapperAddAllPropertyOnExistingList() {
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("comment");
int listSizeBefore = existingList.size();
assertEquals(PO_COMMENT_LIST_SIZE, listSizeBefore);
int indexToPlaceAtEnd = aSequence.size();
Property commentProperty = po.getInstanceProperty("comment");
// add list of items to existing list
List<String> aListToAdd = new ArrayList<String>();
aListToAdd.add(PO_COMMENT_VALUE1);
aListToAdd.add(PO_COMMENT_VALUE1);
aListToAdd.add(PO_COMMENT_VALUE1);
// add to the end of the list
existingList.addAll(aListToAdd);
// verify that the list has increased on the do
int listSizeAfter = ((ListWrapper)po.get("comment")).size();
// TODO: We should not be removing the existing item?
int newItems = aListToAdd.size();
//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
String comment2Value = (String)aSequence.getValue(indexToPlaceAtEnd + newItems - 1);
assertNotNull(comment2Value);
assertEquals(comment2Value, 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(po).size();
// but dataObject node list is the same
assertEquals(treeSizeBeforeAdd, treeSizeAfterAdd);
// get sequence object that will be removed
SDOSetting aSetting7 = (SDOSetting)aSequence.getSettings().get(7);
SDOSetting aSetting8 = (SDOSetting)aSequence.getSettings().get(8);
SDOSetting aSetting9 = (SDOSetting)aSequence.getSettings().get(9);
// remove the first occurrence of the duplicated items in the sequence
int aSequenceSizeBeforeRemove = aSequence.size();
existingList.remove("comment 1");
// check size
assertEquals(aSequenceSizeBeforeRemove - 1, aSequence.size());
// verify that the correct index in the sequence was removed based on the listWrapper index
assertEquals(aSetting8, aSequence.getSettings().get(7)); // 6 shifted into 5's place
assertEquals(aSetting9, aSequence.getSettings().get(8)); // 6 shifted into 5's place
assertFalse(aSetting7 == aSequence.getSettings().get(7)); // 5 is gone
assertFalse(aSetting7 == aSequence.getSettings().get(8)); // 5 is gone
//assertFalse(aSetting7 == aSequence.getSettings().get(9)); // 5 is gone
}
*/
public void testAddAllComplexManyByListWrapperAddAllPropertyOnExistingList() {
defineAndLoadRoot(false, false);
SDOSequence aSequence = getSequence(root, "/", 5);
// DataObject po = (DataObject)root.get(PO_SEQUENCE_PATH);
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[1]");
assertNotNull(item3);
Property itemProperty = root.getInstanceProperty("item");
// add list of items to existing list
List<DataObject> aListToAdd = new ArrayList<DataObject>();
DataObject item4 = dataFactory.create(typeHelper.getType(URINAME, ITEM_TYPENAME));
item4.set("itemID", 4);
item4.set("name", "item4-DF");
DataObject item5 = dataFactory.create(typeHelper.getType(URINAME, ITEM_TYPENAME));
item5.set("itemID", 5);
item5.set("name", "item5-DF");
aListToAdd.add(item4);
aListToAdd.add(item5);
// 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();
assertEquals(listSizeBefore + aListToAdd.size(), listSizeAfter);
// verify that the sequence size has increased
assertEquals(indexToPlaceAtEnd + aListToAdd.size(), aSequence.size());
// get back new Setting value
for (int i = 0; i < aListToAdd.size(); i++) {
SDODataObject itemValue = (SDODataObject) aSequence.getValue(indexToPlaceAtEnd + i);
assertNotNull(itemValue);
assertEquals(itemValue, aListToAdd.get(i));
assertNotNull(aSequence.getProperty(indexToPlaceAtEnd + i));
}
// check increased size of sequence
assertEquals(5 + aListToAdd.size(), aSequence.size());
// verify that DataObject has changed
int treeSizeAfterAdd = preOrderTraversalDataObjectList(root).size();
assertEquals(treeSizeBeforeAdd + aListToAdd.size(), treeSizeAfterAdd);
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDOSequenceTestXSD method testRemoveLastOccurrenceComplexManyByListWrapperAddAllPropertyOnExistingList.
/*
// TODO: Verify that existing duplicates will be removed before the new list is added - addAll same as set
public void testRemove2ndOccurrenceSimpleManyByListWrapperAddAllPropertyOnExistingList() {
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("comment");
int listSizeBefore = existingList.size();
assertEquals(PO_COMMENT_LIST_SIZE, listSizeBefore);
int indexToPlaceAtEnd = aSequence.size();
Property commentProperty = po.getInstanceProperty("comment");
// add list of items to existing list
List<String> aListToAdd = new ArrayList<String>();
aListToAdd.add(PO_COMMENT_VALUE1);
aListToAdd.add(PO_COMMENT_VALUE1);
aListToAdd.add(PO_COMMENT_VALUE1);
// add to the end of the list
existingList.addAll(aListToAdd);
// verify that the list has increased on the do
int listSizeAfter = ((ListWrapper)po.get("comment")).size();
// TODO: We should not be removing the existing item?
int newItems = aListToAdd.size();
//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
String comment2Value = (String)aSequence.getValue(indexToPlaceAtEnd + newItems - 1);
assertNotNull(comment2Value);
assertEquals(comment2Value, 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(po).size();
// but dataObject node list is the same
assertEquals(treeSizeBeforeAdd, treeSizeAfterAdd);
// get sequence object that will be removed
SDOSetting aSetting7 = (SDOSetting)aSequence.getSettings().get(7);
SDOSetting aSetting8 = (SDOSetting)aSequence.getSettings().get(8);
SDOSetting aSetting9 = (SDOSetting)aSequence.getSettings().get(9);
// remove the first occurrence of the duplicated items in the sequence
int aSequenceSizeBeforeRemove = aSequence.size();
existingList.remove(2);
// check size
assertEquals(aSequenceSizeBeforeRemove - 1, aSequence.size());
// verify that the correct index in the sequence was removed based on the listWrapper index
assertEquals(aSetting8, aSequence.getSettings().get(7)); // 6 shifted into 5's place
assertEquals(aSetting9, aSequence.getSettings().get(8)); // 6 shifted into 5's place
assertFalse(aSetting7 == aSequence.getSettings().get(7)); // 5 is gone
assertFalse(aSetting7 == aSequence.getSettings().get(8)); // 5 is gone
//assertFalse(aSetting7 == aSequence.getSettings().get(9)); // 5 is gone
}
*/
// TODO: Verify that existing duplicates will be removed before the new list is added - addAll same as set
public void testRemoveLastOccurrenceComplexManyByListWrapperAddAllPropertyOnExistingList() {
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 by 1
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));
// the following is no longer valid after we refactored addAll(do list) to not add duplicates
/* assertNotNull(aSequence.getProperty(indexToPlaceAtEnd));
// check increased size of sequence
assertEquals(indexToPlaceAtEnd + newItems, aSequence.size());
// verify that DataObject has changed
int treeSizeAfterAdd = preOrderTraversalDataObjectList(root).size();
assertEquals(treeSizeBeforeAdd + newItems, treeSizeAfterAdd);
// get sequence object that will be removed
SDOSetting aSetting4 = (SDOSetting)aSequence.getSettings().get(4);
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
int aSequenceSizeBeforeRemove = aSequence.size();
existingList.remove(existingList.size() - 1);
// check size
assertEquals(aSequenceSizeBeforeRemove -1, aSequence.size());
// verify that the correct index in the sequence was removed based on the listWrapper index
assertEquals(aSetting4, aSequence.getSettings().get(4));
assertEquals(aSetting5, aSequence.getSettings().get(5));
assertFalse(aSetting6 == aSequence.getSettings().get(5));
*/
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDOSequenceTestXSD method test_getValue_whereIndexIsOutOfBounds.
public void test_getValue_whereIndexIsOutOfBounds() {
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() - 1;
// object to replace
DataObject item2 = (DataObject) root.get("item[2]");
assertNotNull(item2);
/*
// add the item to the current list
ListWrapper existingList = (ListWrapper)aSequence.getValue(indexToPlaceAtEnd);
assertNotNull(existingList);
existingList.add(item2);
boolean exceptionThrown = false;
try {
aSequence.getValue(-1);
} catch (IndexOutOfBoundsException e) {
exceptionThrown = true;
} finally {
assertTrue(exceptionThrown);
}
*/
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDOSequenceTestXSD 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);
}
Aggregations