use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDOSequenceTestXSD method test_voidReturnFrom_add_int_Property_Object_propertyIsAttribute.
public void test_voidReturnFrom_add_int_Property_Object_propertyIsAttribute() {
// int index, Property property, Object value) {
defineAndLoadRoot(false, false);
// detach shipTo
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);
Property orderDateProperty = po.getInstanceProperty("orderDate");
// add to sequence
try {
aSequence.add(indexToPlaceAtEnd, orderDateProperty, "1999-10-19");
} catch (Exception e) {
}
// get back new Setting value
ListWrapper item2Value = null;
boolean exceptionThrown = false;
try {
item2Value = (ListWrapper) aSequence.getValue(indexToPlaceAtEnd);
} catch (SDOException e) {
assertEquals(SDOException.INVALID_INDEX, e.getErrorCode());
exceptionThrown = true;
}
assertNull(item2Value);
assertTrue(exceptionThrown);
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDOSequenceTestXSD method testRemoveAllComplexManyViaListWrapper.
public void testRemoveAllComplexManyViaListWrapper() {
defineAndLoadRoot(false, false);
SDOSequence aSequence = getSequence(root, "/", 5);
int sequenceSizeBefore = aSequence.size();
DataObject itemDO1 = (DataObject) root.get("item[1]");
// after removal the items list indexes on the dataObject will shift down, get item[2] for later comparison
DataObject itemDO2 = (DataObject) root.get("item[2]");
assertNotNull(itemDO1);
assertNotNull(itemDO2);
assertFalse(itemDO1 == itemDO2);
// DataObject po = (DataObject)root.get(PO_SEQUENCE_PATH);
ListWrapper existingList = (ListWrapper) root.get("item");
int listSizeBefore = existingList.size();
assertEquals(3, listSizeBefore);
// get item from sequence
int item2SequenceIndex = getNthSequenceIndexFor(aSequence, "item", 2);
assertTrue(item2SequenceIndex > -1);
DataObject itemObjectFromSetting = (DataObject) aSequence.getValue(item2SequenceIndex);
assertNotNull(itemObjectFromSetting);
assertTrue(itemObjectFromSetting == itemDO2);
// create a list of items to remove
List<DataObject> listToRemove = new ArrayList<DataObject>();
for (Iterator<DataObject> i = existingList.iterator(); i.hasNext(); ) {
listToRemove.add(i.next());
}
int sizeListToRemove = listToRemove.size();
// remove entire list
existingList.removeAll(listToRemove);
assertEquals(sequenceSizeBefore - sizeListToRemove, aSequence.size());
assertEquals(listSizeBefore - sizeListToRemove, existingList.size());
// are we removed on the DataObject?
// DataObject item1ObjectFromAfterRemove = (DataObject)root.get(PO_SEQUENCE_PATH + "/item[1]");
// TODO: verify delete or dont delete after a sequence.remove
// assertTrue(item1ObjectFromAfterRemove == itemDO1);
// assertFalse(item1ObjectFromAfterRemove == itemDO2);
assertEquals(0, existingList.size());
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDOSequenceTestXSD method test_getProperty_whereIndexIsOutOfBounds.
public void test_getProperty_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.getProperty(-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 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 SDOSequenceTestXSD method test_voidReturnFrom_add_int_Property_Object_outofbounds.
public void test_voidReturnFrom_add_int_Property_Object_outofbounds() {
// int index, Property property, Object value) {
defineAndLoadRoot(false, false);
// detach shipTo
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);
Property itemProperty = po.getInstanceProperty("item");
// add to sequence
try {
aSequence.add(-1, itemProperty, item2);
} catch (Exception e) {
}
// get back new Setting value
ListWrapper item2Value = null;
boolean exceptionThrown = false;
try {
item2Value = (ListWrapper) aSequence.getValue(indexToPlaceAtEnd);
} catch (SDOException e) {
assertEquals(SDOException.INVALID_INDEX, e.getErrorCode());
exceptionThrown = true;
}
assertNull(item2Value);
assertTrue(exceptionThrown);
/* assertNotNull(aSequence.getProperty(indexToPlaceAtEnd));
// check increased size of sequence didnt happen
assertEquals(PO_SEQUENCE_SIZE, aSequence.size());
// verify that the list has not increased
int listSizeAfter = ((ListWrapper)po.get("item")).size();
assertEquals(listSizeBefore, listSizeAfter);
// verify that DataObject has not changed
int treeSizeAfterAdd = preOrderTraversalDataObjectList(po).size();
assertEquals(treeSizeBeforeAdd, treeSizeAfterAdd);
*/
}
Aggregations