Author: tfmorris
Date: 2008-10-05 15:44:35-0700
New Revision: 15886
Added:
trunk/src/argouml-app/tests/org/argouml/util/ThreadHelper.java (contents, props changed)
Modified:
trunk/src/argouml-app/tests/org/argouml/uml/ui/behavior/collaborations/TestUMLAssociationRoleBaseComboBoxModel.java
trunk/src/argouml-app/tests/org/argouml/uml/ui/behavior/common_behavior/TestUMLReceptionSignalComboBoxModel.java
Log:
Issue 5433: Update tests to synchronize against combo box activities on other threads
http://argouml.tigris.org/issues/show_bug.cgi?id=5433
Modified: trunk/src/argouml-app/tests/org/argouml/uml/ui/behavior/collaborations/TestUMLAssociationRoleBaseComboBoxModel.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/tests/org/argouml/uml/ui/behavior/collaborations/TestUMLAssociationRoleBaseComboBoxModel.java?view=diff&rev=15886&p1=trunk/src/argouml-app/tests/org/argouml/uml/ui/behavior/collaborations/TestUMLAssociationRoleBaseComboBoxModel.java&p2=trunk/src/argouml-app/tests/org/argouml/uml/ui/behavior/collaborations/TestUMLAssociationRoleBaseComboBoxModel.java&r1=15885&r2=15886
==============================================================================
--- trunk/src/argouml-app/tests/org/argouml/uml/ui/behavior/collaborations/TestUMLAssociationRoleBaseComboBoxModel.java (original)
+++ trunk/src/argouml-app/tests/org/argouml/uml/ui/behavior/collaborations/TestUMLAssociationRoleBaseComboBoxModel.java 2008-10-05 15:44:35-0700
@@ -1,5 +1,5 @@
// $Id$
-// Copyright (c) 1996-2007 The Regents of the University of California. All
+// Copyright (c) 1996-2008 The Regents of the University of California. All
// Rights Reserved. Permission to use, copy, modify, and distribute this
// software and its documentation without fee, and without a written
// agreement is hereby granted, provided that the above copyright notice
@@ -24,14 +24,19 @@
package org.argouml.uml.ui.behavior.collaborations;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+
import junit.framework.TestCase;
-import org.argouml.model.InitializeModel;
import org.argouml.kernel.Project;
import org.argouml.kernel.ProjectManager;
+import org.argouml.model.InitializeModel;
import org.argouml.model.Model;
import org.argouml.profile.init.InitProfileSubsystem;
import org.argouml.ui.targetmanager.TargetEvent;
+import org.argouml.util.ThreadHelper;
/**
* @since Oct 30, 2002
@@ -83,7 +88,9 @@
Object class1 = Model.getCoreFactory().createClass();
Object class2 = Model.getCoreFactory().createClass();
Object m = Model.getModelManagementFactory().createModel();
- p.setRoot(m);
+ Collection roots = new ArrayList();
+ roots.add(m);
+ p.setRoots(roots);
Model.getCoreHelper().setNamespace(class1, m);
Model.getCoreHelper().setNamespace(class2, m);
bases = new Object[NO_ELEMENTS_IN_TEST];
@@ -111,12 +118,13 @@
new Object[] {
elem,
}));
- Model.getPump().flushModelEvents();
+ ThreadHelper.synchronize();
}
/*
* @see junit.framework.TestCase#tearDown()
*/
+ @Override
protected void tearDown() throws Exception {
super.tearDown();
Model.getUmlFactory().delete(elem);
@@ -140,55 +148,83 @@
/**
* Test setting the Base.
- */
- public void testSetBase() {
+ *
+ * @throws InterruptedException if interrupted while synchronizing
+ * @throws InvocationTargetException should never happen indicates a problem
+ * with the test itself
+ */
+ public void testSetBase() throws InterruptedException,
+ InvocationTargetException {
+
Model.getCollaborationsHelper().setBase(elem, bases[0]);
- Model.getPump().flushModelEvents();
+ ThreadHelper.synchronize();
assertTrue(model.getSelectedItem() == bases[0]);
}
/**
* Test setting the Base.
- */
- public void testChangeBase() {
+ *
+ * @throws InterruptedException if interrupted while synchronizing
+ * @throws InvocationTargetException should never happen indicates a problem
+ * with the test itself
+ */
+ public void testChangeBase() throws InterruptedException,
+ InvocationTargetException {
+
Model.getCollaborationsHelper().setBase(elem, bases[0]);
- Model.getPump().flushModelEvents();
+ ThreadHelper.synchronize();
Model.getCollaborationsHelper().setBase(elem, bases[1]);
- Model.getPump().flushModelEvents();
+ ThreadHelper.synchronize();
assertTrue(model.getSelectedItem() == bases[1]);
}
/**
* Test deleting selected Base.
- */
- public void testDeleteBase() {
+ *
+ * @throws InterruptedException if interrupted while synchronizing
+ * @throws InvocationTargetException should never happen indicates a problem
+ * with the test itself
+ */
+ public void testDeleteBase() throws InterruptedException,
+ InvocationTargetException {
+
Model.getCollaborationsHelper().setBase(elem, bases[1]);
Model.getUmlFactory().delete(bases[1]);
- Model.getPump().flushModelEvents();
+ ThreadHelper.synchronize();
assertNull(model.getSelectedItem());
}
/**
* Test setting the Base to null.
- */
- public void testSetBaseToNull() {
+ *
+ * @throws InterruptedException if interrupted while synchronizing
+ * @throws InvocationTargetException should never happen indicates a problem
+ * with the test itself
+ */
+ public void testSetBaseToNull() throws InterruptedException,
+ InvocationTargetException {
+
Model.getCollaborationsHelper().setBase(elem, bases[0]);
Model.getCollaborationsHelper().setBase(elem, null);
- Model.getPump().flushModelEvents();
+ ThreadHelper.synchronize();
assertNull(model.getSelectedItem());
}
/**
* Test removing the Base.
+ *
+ * @throws InterruptedException if interrupted while synchronizing
+ * @throws InvocationTargetException should never happen indicates a problem
+ * with the test itself
*/
- public void testRemoveBase() {
+ public void testRemoveBase() throws InterruptedException,
+ InvocationTargetException {
Model.getUmlFactory().delete(bases[NO_ELEMENTS_IN_TEST - 1]);
// One can only delete a assoc by changing target,
// so let's simulate that:
/* TODO: Get rid of this! */
changeTarget();
- // there is one extra element since removal of the base is allowed.
- Model.getPump().flushModelEvents();
+ ThreadHelper.synchronize();
assertEquals(NO_ELEMENTS_IN_TEST + 1 - 1, model.getSize());
assertTrue(!model.contains(bases[NO_ELEMENTS_IN_TEST - 1]));
}
@@ -199,5 +235,6 @@
model.targetSet(new TargetEvent(this, TargetEvent.TARGET_SET,
new Object[] {dummy}, new Object[] {elem}));
}
+
}
Modified: trunk/src/argouml-app/tests/org/argouml/uml/ui/behavior/common_behavior/TestUMLReceptionSignalComboBoxModel.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/tests/org/argouml/uml/ui/behavior/common_behavior/TestUMLReceptionSignalComboBoxModel.java?view=diff&rev=15886&p1=trunk/src/argouml-app/tests/org/argouml/uml/ui/behavior/common_behavior/TestUMLReceptionSignalComboBoxModel.java&p2=trunk/src/argouml-app/tests/org/argouml/uml/ui/behavior/common_behavior/TestUMLReceptionSignalComboBoxModel.java&r1=15885&r2=15886
==============================================================================
--- trunk/src/argouml-app/tests/org/argouml/uml/ui/behavior/common_behavior/TestUMLReceptionSignalComboBoxModel.java (original)
+++ trunk/src/argouml-app/tests/org/argouml/uml/ui/behavior/common_behavior/TestUMLReceptionSignalComboBoxModel.java 2008-10-05 15:44:35-0700
@@ -1,5 +1,5 @@
// $Id$
-// Copyright (c) 1996-2007 The Regents of the University of California. All
+// Copyright (c) 1996-2008 The Regents of the University of California. All
// Rights Reserved. Permission to use, copy, modify, and distribute this
// software and its documentation without fee, and without a written
// agreement is hereby granted, provided that the above copyright notice
@@ -24,14 +24,19 @@
package org.argouml.uml.ui.behavior.common_behavior;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+
import junit.framework.TestCase;
-import org.argouml.model.InitializeModel;
import org.argouml.kernel.Project;
import org.argouml.kernel.ProjectManager;
+import org.argouml.model.InitializeModel;
import org.argouml.model.Model;
import org.argouml.profile.init.InitProfileSubsystem;
import org.argouml.ui.targetmanager.TargetEvent;
+import org.argouml.util.ThreadHelper;
/**
* @since Nov 2, 2002
@@ -72,6 +77,7 @@
/*
* @see junit.framework.TestCase#setUp()
*/
+ @Override
protected void setUp() throws Exception {
super.setUp();
InitializeModel.initializeDefault();
@@ -80,7 +86,9 @@
elem = Model.getCommonBehaviorFactory().createReception();
signals = new Object[NO_OF_ELEMENTS];
Object m = Model.getModelManagementFactory().createModel();
- p.setRoot(m);
+ Collection roots = new ArrayList();
+ roots.add(m);
+ p.setRoots(roots);
Model.getCoreHelper().setNamespace(elem, m);
for (int i = 0; i < NO_OF_ELEMENTS; i++) {
signals[i] = Model.getCommonBehaviorFactory().createSignal();
@@ -89,12 +97,13 @@
model = new UMLReceptionSignalComboBoxModel();
model.targetSet(new TargetEvent(this, "set", new Object[0],
new Object[] {elem}));
- Model.getPump().flushModelEvents();
+ ThreadHelper.synchronize();
}
/*
* @see junit.framework.TestCase#tearDown()
*/
+ @Override
protected void tearDown() throws Exception {
super.tearDown();
Model.getUmlFactory().delete(elem);
@@ -116,27 +125,42 @@
/**
* Test setSignal().
+ *
+ * @throws InvocationTargetException test failure
+ * @throws InterruptedException test failure
*/
- public void testSetSignal() {
+ public void testSetSignal() throws InterruptedException,
+ InvocationTargetException {
+
Model.getCommonBehaviorHelper().setSignal(elem, signals[0]);
- Model.getPump().flushModelEvents();
+ ThreadHelper.synchronize();
// One can only do this by changing target,
// so let's simulate that:
+ Object dummy = Model.getCommonBehaviorFactory().createReception();
model.targetSet(new TargetEvent(this,
TargetEvent.TARGET_SET,
- new Object[0],
- new Object[] {
- elem,
- }));
+ new Object[] {elem},
+ new Object[] {dummy})
+ );
+ model.targetSet(new TargetEvent(this,
+ TargetEvent.TARGET_SET,
+ new Object[] {dummy},
+ new Object[] {elem}));
+ ThreadHelper.synchronize();
assertTrue(model.getSelectedItem() == signals[0]);
}
/**
* Test removing signals.
- */
- public void testRemoveSignal() {
+ *
+ * @throws InvocationTargetException test failure
+ * @throws InterruptedException test failure
+ */
+ public void testRemoveSignal() throws InterruptedException,
+ InvocationTargetException {
+
Model.getUmlFactory().delete(signals[NO_OF_ELEMENTS - 1]);
- Model.getPump().flushModelEvents();
+ ThreadHelper.synchronize();
assertEquals(NO_OF_ELEMENTS - 1, model.getSize());
assertTrue(!model.contains(signals[NO_OF_ELEMENTS - 1]));
}
Added: trunk/src/argouml-app/tests/org/argouml/util/ThreadHelper.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/tests/org/argouml/util/ThreadHelper.java?view=auto&rev=15886
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/tests/org/argouml/util/ThreadHelper.java 2008-10-05 15:44:35-0700
@@ -0,0 +1,63 @@
+// $Id$
+// Copyright (c) 2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.util;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.swing.SwingUtilities;
+
+import org.argouml.model.Model;
+
+/**
+ * Helper methods for tests which need to deal with threads. Not intended for
+ * use in applications.
+ *
+ * @author Tom Morris <[email protected]>
+ */
+public class ThreadHelper {
+
+ /**
+ * Wait for all events to be delivered on the MDR event thread and on the
+ * AWT/Swing event thread.
+ *
+ * @throws InterruptedException if we were interrupted while waiting for the
+ * AWT thread to sync
+ * @throws InvocationTargetException should never happen. Indicates an
+ * internal error.
+ */
+ public static void synchronize() throws InterruptedException,
+ InvocationTargetException {
+
+ // Wait for all Model subsystem events to be delivered
+ Model.getPump().flushModelEvents();
+
+ // Wait for all AWT events to be dispatched and processed
+ Runnable doWorkRunnable = new Runnable() {
+ public void run() {
+ }
+ };
+ SwingUtilities.invokeAndWait(doWorkRunnable);
+ }
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.