Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2018-04-23 07:06:31 -0400
committerEike Stepper2018-04-23 07:06:31 -0400
commit03800f7122fd19ca49170de208e97742a57047da (patch)
treea31ec908fbbb9ebb01c2faa9da67878b645ee9fb /plugins/org.eclipse.emf.cdo.tests/src
parent5f582b20c8a4602fc0cc4f554e5098aa2cc7e8c9 (diff)
downloadcdo-03800f7122fd19ca49170de208e97742a57047da.tar.gz
cdo-03800f7122fd19ca49170de208e97742a57047da.tar.xz
cdo-03800f7122fd19ca49170de208e97742a57047da.zip
[405543] An unsettable many-valued reference that is set to an empty list is unset on new transaction
https://bugs.eclipse.org/bugs/show_bug.cgi?id=405543
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.tests/src')
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/SecurityTest.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_318876_Test.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_405543_Test.java235
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_429659_Test.java8
4 files changed, 242 insertions, 9 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/SecurityTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/SecurityTest.java
index cc81b7a92f..ecd0d9c43d 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/SecurityTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/SecurityTest.java
@@ -314,13 +314,13 @@ public class SecurityTest extends AbstractCDOTest
{
if (CDOIDUtil.isNull((CDOID)revision.getContainerID()))
{
- return revision.getList(EresourcePackage.Literals.CDO_RESOURCE__CONTENTS, 0);
+ return revision.getOrCreateList(EresourcePackage.Literals.CDO_RESOURCE__CONTENTS, 0);
}
return null;
}
- return revision.getList(EresourcePackage.Literals.CDO_RESOURCE_FOLDER__NODES, 0);
+ return revision.getOrCreateList(EresourcePackage.Literals.CDO_RESOURCE_FOLDER__NODES, 0);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_318876_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_318876_Test.java
index c8c610a7ae..19f2c91125 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_318876_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_318876_Test.java
@@ -60,9 +60,6 @@ public class Bugzilla_318876_Test extends AbstractCDOTest
CDOState state = CDOUtil.getCDOObject(purchaseOrder).cdoState();
assertEquals(CDOState.INVALID_CONFLICT, state);
-
- transaction.close();
- session.close();
}
private void doSecondSession() throws CommitException
@@ -76,6 +73,5 @@ public class Bugzilla_318876_Test extends AbstractCDOTest
EcoreUtil.delete(purchaseOrder);
transaction.commit();
- session.close();
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_405543_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_405543_Test.java
new file mode 100644
index 0000000000..e284536022
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_405543_Test.java
@@ -0,0 +1,235 @@
+/*
+ * Copyright (c) 2004 - 2013 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Steve Monnier - initial API and implementation
+ * Eike Stepper - adapted for more correct test model definition
+ * Christian W. Damus (CEA) - adapted for new test model with unsettable attribute
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import static org.junit.Assert.assertNotEquals;
+
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.model3.Class1;
+import org.eclipse.emf.cdo.tests.model3.legacy.Model3Factory;
+import org.eclipse.emf.cdo.tests.model3.subpackage.Class2;
+import org.eclipse.emf.cdo.tests.model3.subpackage.legacy.SubpackageFactory;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.util.InternalEList;
+
+/**
+ * Bug 405543 - An unsettable many-valued reference that is set to an empty list is unset on new transaction.
+ *
+ * @author Steve Monnier
+ */
+public class Bugzilla_405543_Test extends AbstractCDOTest
+{
+ /**
+ * This test validates that an unset list isSet method is false.
+ */
+ public void testIsUnsetOnUnsettableReference() throws Exception
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("/res"));
+
+ Class1 element = getModel3Factory().createClass1();
+ element.setAdditionalValue("Arbitrary value to cause eSettings to be non-null");
+ assertFalse(element.isSetClass2());
+
+ resource.getContents().add(element);
+ assertFalse(element.isSetClass2());
+
+ transaction.commit();
+ assertFalse(element.isSetClass2());
+
+ // Closing/Reopening Transaction and session.
+ session.close();
+ session = openSession();
+ transaction = session.openTransaction();
+ resource = transaction.getOrCreateResource(getResourcePath("/res"));
+
+ element = (Class1)resource.getContents().get(0);
+ assertFalse(element.isSetClass2());
+
+ Class2 element2 = getModel3SubpackageFactory().createClass2();
+ element.getClass2().add(element2);
+ assertTrue(element.isSetClass2());
+
+ resource.getContents().add(element2);
+ assertTrue(element.isSetClass2());
+
+ transaction.commit();
+ assertTrue(element.isSetClass2());
+
+ // Closing/Reopening Transaction and session.
+ session.close();
+ session = openSession();
+ transaction = session.openTransaction();
+ resource = transaction.getOrCreateResource(getResourcePath("/res"));
+
+ element = (Class1)resource.getContents().get(0);
+ assertTrue(element.isSetClass2());
+
+ element.unsetClass2();
+ assertFalse(element.isSetClass2());
+
+ transaction.commit();
+ assertFalse(element.isSetClass2());
+
+ // Closing/Reopening Transaction and session.
+ session.close();
+ session = openSession();
+ transaction = session.openTransaction();
+ resource = transaction.getOrCreateResource(getResourcePath("/res"));
+
+ element = (Class1)resource.getContents().get(0);
+ assertFalse(element.isSetClass2());
+ }
+
+ /**
+ * This test validates that an empty unsettable reference isSet method is true.
+ * In this test, the reference is set before the first commit.
+ */
+ public void testIsSetOnUnsettableReference() throws Exception
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("/res"));
+
+ Class1 element = getModel3Factory().createClass1();
+ Class2 element2 = getModel3SubpackageFactory().createClass2();
+ assertFalse(element.isSetClass2());
+
+ element.getClass2().add(element2);
+ assertTrue(element.isSetClass2());
+
+ element.getClass2().remove(element2);
+ assertTrue(element.isSetClass2());
+
+ resource.getContents().add(element);
+ assertTrue(element.isSetClass2());
+
+ resource.getContents().add(element2);
+ assertTrue(element.isSetClass2());
+
+ transaction.commit();
+ assertTrue(element.isSetClass2());
+
+ // Closing/Reopening Transaction and session.
+ transaction.close();
+ session.close();
+ session = openSession();
+ transaction = session.openTransaction();
+ resource = transaction.getOrCreateResource(getResourcePath("/res"));
+ element = (Class1)resource.getContents().get(0);
+
+ // Validate that class1 reference 'class2' is still set but empty.
+ assertTrue(element.isSetClass2());
+ }
+
+ /**
+ * This test validates that an empty unsettable reference isSet method is true.
+ * In this test, the reference is set after the first commit.
+ */
+ public void testIsSetOnUnsettableReference2() throws Exception
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("/res"));
+
+ // Create an object and set is a string attribute to the empty string.
+ Class1 element = getModel3Factory().createClass1();
+ Class2 element2 = getModel3SubpackageFactory().createClass2();
+
+ resource.getContents().add(element);
+ assertFalse(element.isSetClass2());
+
+ resource.getContents().add(element2);
+ assertFalse(element.isSetClass2());
+
+ transaction.commit();
+ assertFalse(element.isSetClass2());
+
+ element.getClass2().add(element2);
+ assertTrue(element.isSetClass2());
+
+ element.getClass2().remove(element2);
+ assertTrue(element.isSetClass2());
+
+ // Commit and reopen transaction on a new session.
+ transaction.commit();
+ session.close();
+ session = openSession();
+ transaction = session.openTransaction();
+ resource = transaction.getOrCreateResource(getResourcePath("/res"));
+ element = (Class1)resource.getContents().get(0);
+
+ // Validate that class1 reference 'class2' is still set but empty.
+ assertTrue(element.isSetClass2());
+ }
+
+ public static void main(String[] args)
+ {
+ Class1 element = Model3Factory.eINSTANCE.createClass1();
+ assertFalse(element.isSetClass2());
+
+ EList<Class2> list = element.getClass2();
+ assertNotEquals(null, list);
+ assertEquals(0, list.size());
+ assertTrue(list.isEmpty());
+ assertFalse(((InternalEList.Unsettable<Class2>)list).isSet());
+
+ Object[] array1 = list.toArray();
+ assertNotEquals(null, array1);
+ assertEquals(0, array1.length);
+
+ Class2[] array2 = list.toArray(new Class2[list.size()]);
+ assertNotEquals(null, array2);
+ assertEquals(0, array2.length);
+
+ assertEquals(-1, list.indexOf(SubpackageFactory.eINSTANCE.createClass2()));
+ assertEquals(-1, list.lastIndexOf(SubpackageFactory.eINSTANCE.createClass2()));
+ assertFalse(list.remove(SubpackageFactory.eINSTANCE.createClass2()));
+ assertFalse(list.contains(SubpackageFactory.eINSTANCE.createClass2()));
+
+ try
+ {
+ list.get(0);
+ fail("IndexOutOfBoundsException expected");
+ }
+ catch (IndexOutOfBoundsException expected)
+ {
+ // SUCCESS
+ }
+
+ try
+ {
+ list.remove(0);
+ fail("IndexOutOfBoundsException expected");
+ }
+ catch (IndexOutOfBoundsException expected)
+ {
+ // SUCCESS
+ }
+
+ try
+ {
+ list.move(0, SubpackageFactory.eINSTANCE.createClass2());
+ fail("IndexOutOfBoundsException expected");
+ }
+ catch (IndexOutOfBoundsException expected)
+ {
+ // SUCCESS
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_429659_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_429659_Test.java
index 62cca5a3bd..9cddf85ec0 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_429659_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_429659_Test.java
@@ -204,10 +204,12 @@ public class Bugzilla_429659_Test extends AbstractCDOTest
assertEquals("Incorrect number of expected notifications: ", unsettable ? 2 : 1, notifications.size());
}
- private static class NotificationAsserter extends EContentAdapter
+ /**
+ * @author Eike Stepper
+ */
+ private static final class NotificationAsserter extends EContentAdapter
{
-
- private List<Notification> notifications = new ArrayList<Notification>();
+ private final List<Notification> notifications = new ArrayList<Notification>();
@Override
public void notifyChanged(Notification notification)

Back to the top