use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDOSequenceTestXSD 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 test_booleanReturnFrom_add_int_Object.
/**
* Adds a new entry with the specified property index and value
* to the end of the entries.
* @param propertyIndex the index of the entry's property.
* @param value the value for the entry.
*/
public void test_booleanReturnFrom_add_int_Object() {
// int propertyIndex, 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());
int listSizeBefore = ((ListWrapper) po.get("item")).size();
assertEquals(2, listSizeBefore);
int indexToPlaceAtEnd = aSequence.size();
// object to add
DataObject item2 = (DataObject) root.get("item[2]");
assertNotNull(item2);
// get "item" property index
int propIndex = 0;
for (Iterator i = po.getInstanceProperties().iterator(); i.hasNext(); ) {
Property aProperty = (Property) i.next();
if (aProperty != null && aProperty.getName().equals("item")) {
break;
} else {
propIndex++;
}
}
// add to sequence
aSequence.add(propIndex, item2);
// 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_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);
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDOSequenceTestCS 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 SDOSequenceTestCS method testClearComplexManyReferenceByListWrapper.
public void testClearComplexManyReferenceByListWrapper() {
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);
existingList.clear();
// verify that the list has decreased on the do
int listSizeAfter = ((ListWrapper) po.get("item")).size();
assertEquals(listSizeBefore - aListToAdd.size(), listSizeAfter);
// verify that the sequence size has decreased
assertEquals(indexToPlaceAtEnd - aListToAdd.size(), aSequence.size());
// check decreased 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 test_PropertyReturnFrom_getProperty.
/**
* Returns the property for the given entry index.
* Returns <code>null</code> for mixed text entries.
* @param index the index of the entry.
*/
public void test_PropertyReturnFrom_getProperty() {
// int index) {
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;
Property property1 = po.getInstanceProperty("item");
Object property1Return = null;
try {
property1Return = aSequence.getProperty(indexToPlaceAtEnd);
} catch (IndexOutOfBoundsException e) {
exceptionThrown = true;
} finally {
assertFalse(exceptionThrown);
}
// verify property
assertNotNull(property1Return);
assertEquals(property1, property1Return);
*/
}
Aggregations