use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDOSequenceTestCS 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) {
}
boolean exceptionThrown = false;
// get back new Setting value
ListWrapper item2Value = null;
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);
*/
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class SDOCopyHelperDeepCopyTest method testUC0312DeepCopy1_nBidirectionalPropInsideCopyTreeCopiedContTreeSameAsCopyTree2ndNodeIsMany.
// bidirectional property target is cached during containment iteration
public void testUC0312DeepCopy1_nBidirectionalPropInsideCopyTreeCopiedContTreeSameAsCopyTree2ndNodeIsMany() {
// set containment so that the bidirectional target is cached
rootWorkm.setContainment(true);
// create copy of the root
SDODataObject copy = (SDODataObject) ((SDOCopyHelper) copyHelper).copy(rootUC4m, getChangeSummary());
// verify that container is null
assertNull(copy.getContainer());
// get bidirectional node from the copy root (direction 1)
ListWrapper bidirCopyViaCopyRoot = (ListWrapper) //
copy.get("rootHome/homeAddress/addressWork");
assertNotNull(bidirCopyViaCopyRoot);
// get bidirectional start node via opposite property
SDODataObject bidirCopyStart = (SDODataObject) //
copy.get("rootHome/homeAddress");
assertNotNull(bidirCopyStart);
// verify changeSummary is set on opposites
// ChangeSummary aCS2 = bidirCopyStart.getChangeSummary();
// assertNotNull(aCS2);
// get property containing opposite property link (inside copy tree)
SDOProperty bidirCopyOppositeStartProp = //
bidirCopyStart.getType().getProperty("addressWork");
assertNotNull(bidirCopyOppositeStartProp);
// Spec 8.4 "Properties that are bi-directional require type.dataType=false"
assertFalse(bidirCopyOppositeStartProp.getType().isDataType());
// get bidir property inside copy tree
SDOProperty oppositeEndProp = ((SDODataObject) //
copy.get("rootHome/homeAddress")).getType().getProperty(// .getOpposite();
"addressWork");
assertNotNull(oppositeEndProp);
// Spec 8.4 "Properties that are bi-directional require type.dataType=false"
assertFalse(oppositeEndProp.getType().isDataType());
// get opposite DO (direction 2)
SDODataObject bidirCopyViaOppositeDO = (SDODataObject) //
copy.get("rootWork/workAddress");
// assertNotNull(bidirCopyViaOppositeDO);
// verify changeSummary is set on opposites
// ChangeSummary aCS1 = bidirCopyViaOppositeDO.getChangeSummary();
// assertNotNull(aCS1);
// Constraint C3 - Spec 3.9.4
// verify there are no object pointers between source and copy (all objects are instance independent)
// ie: a' != a - or there are no references to "root" from "copy"
assertNotSame(//
rootUC4m.get("rootHome/homeAddress"), copy.get("rootHome/homeAddress"));
// verify isMany objects are distinct
ListWrapper do1 = (ListWrapper) rootUC4m.get("rootWork");
ListWrapper do2 = (ListWrapper) copy.get("rootWork");
// verify we are not just getting back empty lists for a null object lookup
assertTrue(do1.size() > 0);
assertTrue(do2.size() > 0);
// verify lists are different (shallow check)
assertNotSame(do1, do2);
// verify list elements are different (deep check)
assertNotNull(do1.get(0));
assertNotNull(do2.get(0));
assertFalse(do1.get(0) == do2.get(0));
// assertNotSame((SDODataObject)rootUC4m.get(//
// "rootHome/homeAddress/addressWork"),//
// (SDODataObject)copy.get("//" +//
// "rootHome/homeAddress/addressWork"));
// Spec 8.4 "Properties that are bi-directional require that no more than one end has containment=true"
assertFalse(areBothBidirectionalOppositePropertiesContainmentTrue(bidirCopyOppositeStartProp, bidirCopyOppositeStartProp.getOpposite()));
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class ChangeSummaryXSDTestCases method testDetachAndReSetPrice1BackToSameIndex.
// Verify that an unset followed by a (re)set of the same subtree returns tree to original state
// See SDO-225 Feb-15 2007 issue (option A - nothing in the cs, option B - track unset/reset)
public void testDetachAndReSetPrice1BackToSameIndex() {
DataObject itemsDO = rootObject.getDataObject("items");
DataObject item1DO = rootObject.getDataObject("items/item[1]");
DataObject item2DO = rootObject.getDataObject("items/item[2]");
DataObject item1ProductDO = item1DO.getDataObject("product");
DataObject item1ProductPrice1DO = item1ProductDO.getDataObject("price[1]");
DataObject item1ProductPrice2DO = item1ProductDO.getDataObject("price[2]");
DataObject item2ProductDO = item2DO.getDataObject("product");
DataObject item2ProductPrice1DO = item2ProductDO.getDataObject("price[1]");
DataObject item2ProductPrice2DO = item2ProductDO.getDataObject("price[2]");
cs.beginLogging();
item2ProductPrice1DO.detach();
assertModified(item2ProductDO, cs);
assertDetached(item2ProductPrice1DO, cs);
assertEquals(2, cs.getChangedDataObjects().size());
assertEquals(14, ((SDOChangeSummary) cs).getOldContainer().size());
assertEquals(14, ((SDOChangeSummary) cs).getOldContainmentProperty().size());
List aSettingList = cs.getOldValues(item2ProductDO);
assertTrue(aSettingList.size() > 0);
ChangeSummary.Setting containmentSetting = (ChangeSummary.Setting) aSettingList.get(0);
assertEquals("price", containmentSetting.getProperty().getName());
assertTrue(containmentSetting.getValue() instanceof List);
assertEquals(2, ((List) containmentSetting.getValue()).size());
assertEquals(true, containmentSetting.isSet());
// UNDO - reattach subtree
((ListWrapper) item2ProductDO.get("price")).add(0, item2ProductPrice1DO);
assertFalse(cs.isDeleted(item2ProductPrice1DO));
// assertUnchanged(cs.isModified(item2ProductDO)); //if we add new logic
assertFalse(cs.isModified(item2ProductDO));
assertFalse(cs.isModified(item2ProductPrice1DO));
assertEquals(0, cs.getChangedDataObjects().size());
assertEquals(14, ((SDOChangeSummary) cs).getOldContainer().size());
assertEquals(14, ((SDOChangeSummary) cs).getOldContainmentProperty().size());
// writeXML(rootObject);
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class ChangeSummaryXSDQuoteDataTestCases method testUndoWithAdditionalModifications.
/**
* Tests isModified and isDeleted states of two data objects and their
* parent after:
* 1) the data objects are detached from the parent
* 2) one data object is re-attached to the parent in the same position in
* the original list
*/
public void testUndoWithAdditionalModifications() throws Exception {
ListWrapper items = (ListWrapper) quoteDataDO.get("lineItem");
ListWrapper relatedQuoteItems = (ListWrapper) quoteDataDO.get("relatedQuoteItem");
cs.beginLogging();
DataObject item = (DataObject) items.get(0);
DataObject rqItem = (DataObject) relatedQuoteItems.get(0);
// sanity check
assertFalse(cs.isModified(quoteDataDO));
assertFalse(cs.isDeleted(item));
assertFalse(cs.isDeleted(rqItem));
// detach item and rqItem from quoteDataDO
item.detach();
rqItem.detach();
// re-add item back to the same position in quoteDataDO (undo detach)
items.add(0, item);
// after the undo op, item is not deleted, but the parent has been modified (rqItem was detached)
assertTrue(cs.isModified(quoteDataDO));
assertFalse(cs.isDeleted(item));
}
use of org.eclipse.persistence.sdo.helper.ListWrapper in project eclipselink by eclipse-ee4j.
the class ChangeSummaryXSDQuoteDataTestCases method testMultipleUndo.
/**
* Tests isModified and isDeleted states of two data objects and their
* parent after:
* 1) the data objects are detached from the parent
* 2) one data object is re-attached to the parent in the same position in
* the original list
*/
public void testMultipleUndo() throws Exception {
ListWrapper items = (ListWrapper) quoteDataDO.get("lineItem");
ListWrapper relatedQuoteItems = (ListWrapper) quoteDataDO.get("relatedQuoteItem");
cs.beginLogging();
DataObject item = (DataObject) items.get(0);
DataObject rqItem = (DataObject) relatedQuoteItems.get(0);
// sanity check
assertFalse(cs.isModified(quoteDataDO));
assertFalse(cs.isDeleted(item));
assertFalse(cs.isDeleted(rqItem));
// detach item and rqItem from quoteDataDO
item.detach();
rqItem.detach();
// re-add item back to the same position in quoteDataDO (undo detach)
items.add(0, item);
// after the undo op, item is not deleted, but the parent has been modified (rqItem was detached)
assertTrue(cs.isModified(quoteDataDO));
assertFalse(cs.isDeleted(item));
// re-add rqItem back to the same position in quoteDataDO (undo detach)
relatedQuoteItems.add(0, rqItem);
// after the undo op, rqItem is not deleted, and the parent is modified
assertFalse(cs.isModified(quoteDataDO));
assertFalse(cs.isDeleted(rqItem));
}
Aggregations