use of org.eclipse.persistence.sdo.SDOSequence in project eclipselink by eclipse-ee4j.
the class SDOSequenceTestXSD method testMoveToCopyAlsoRemovesSequenceSettingOnOriginal.
/**
* Purpose:
* Test that the sequence on a move is updated on both the source and target objects
*/
public void testMoveToCopyAlsoRemovesSequenceSettingOnOriginal() {
// make a source object
defineAndLoadRoot(false, false);
SDOSequence aSequence = getSequence(root, PO_SEQUENCE_PATH, PO_SEQUENCE_SIZE);
DataObject poDO = (DataObject) root.get(PO_SEQUENCE_PATH);
assertNotNull(poDO);
DataObject shipToDO = (DataObject) poDO.get("shipTo");
assertNotNull(shipToDO);
// make a copy so that we can move between trees
DataObject rootCopy = copyHelper.copy(root);
// check sequence was copied
SDOSequence aPOSequenceCopy = getSequence(rootCopy, PO_SEQUENCE_PATH, PO_SEQUENCE_SIZE);
assertNotNull(aPOSequenceCopy);
int sequenceCopySizeBeforeDelete = aPOSequenceCopy.size();
// delete shipTo on target
DataObject poDOCopy = (DataObject) rootCopy.get(PO_SEQUENCE_PATH);
assertNotNull(poDO);
SDODataObject shipToCopy = (SDODataObject) poDOCopy.get("shipTo");
assertNotNull(shipToCopy);
shipToCopy.delete();
// verify that the sequence on the copy has been adjusted
int sequenceCopySizeAfterDelete = aPOSequenceCopy.size();
assertEquals(sequenceCopySizeBeforeDelete - 1, sequenceCopySizeAfterDelete);
// verify that the object was deleted on the copy in prep for a move from the root to this copy
assertNull(rootCopy.get(PO_SEQUENCE_PATH + "/shipTo"));
// get shipTo sequence
int shipToSequenceIndex = getNthSequenceIndexFor(aSequence, "shipTo");
assertTrue(shipToSequenceIndex > -1);
DataObject shipToObjectFromSetting = (DataObject) aSequence.getValue(shipToSequenceIndex);
assertNotNull(shipToObjectFromSetting);
assertTrue(shipToObjectFromSetting == shipToDO);
// move shipTo from root to copyRoot
int sequenceSizeBeforeMove = aSequence.size();
int sequenceCopySizeBeforeMove = aPOSequenceCopy.size();
poDOCopy.set("shipTo", shipToDO);
// verify that the sequence on the copy has been increased and on the original has been decreased
int sequenceCopySizeAfterMove = aPOSequenceCopy.size();
int sequenceSizeAfterMove = aSequence.size();
assertEquals(sequenceCopySizeBeforeMove + 1, sequenceCopySizeAfterMove);
assertEquals(sequenceSizeBeforeMove - 1, sequenceSizeAfterMove);
// verify that the object was deleted on the copy in prep for a move from the root to this copy
assertNull(root.get(PO_SEQUENCE_PATH + "/shipTo"));
}
use of org.eclipse.persistence.sdo.SDOSequence 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.SDOSequence 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.SDOSequence in project eclipselink by eclipse-ee4j.
the class SDOSequenceTestXSD method testMoveIndexBothOutOfBoundsHigh.
public void testMoveIndexBothOutOfBoundsHigh() {
defineAndLoadRoot(false, false);
DataObject po = (DataObject) root.get(PO_SEQUENCE_PATH);
assertNotNull(po);
assertTrue(po.getType().isSequenced());
SDOSequence aSequence = (SDOSequence) po.getSequence();
// move 2 sequenced objects
Property beforeMoveProp1 = aSequence.getProperty(1);
assertNotNull(beforeMoveProp1);
boolean exceptionThrown = false;
try {
aSequence.move(101, 99);
} catch (SDOException e) {
// catch error
assertEquals(SDOException.INVALID_INDEX, e.getErrorCode());
exceptionThrown = true;
}
Property afterMoveProp1 = aSequence.getProperty(1);
// verify the move did not take place
assertTrue(beforeMoveProp1 == afterMoveProp1);
assertTrue(exceptionThrown);
}
use of org.eclipse.persistence.sdo.SDOSequence 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));
*/
}
Aggregations