Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2013-07-04 14:14:57 +0000
committervlorenzo2013-07-04 14:14:57 +0000
commitd21abdab519d4fa9cb96af3199c6f1c20380e02d (patch)
treec9a2d9555985afd40c10ba93a39379dde5b4ac60 /tests/junit/extraplugins
parenta8d70e37232d8e21f305ab3259f954f185b74db7 (diff)
downloadorg.eclipse.papyrus-d21abdab519d4fa9cb96af3199c6f1c20380e02d.tar.gz
org.eclipse.papyrus-d21abdab519d4fa9cb96af3199c6f1c20380e02d.tar.xz
org.eclipse.papyrus-d21abdab519d4fa9cb96af3199c6f1c20380e02d.zip
412072: [Table 2] Papyrus must provide tests for the table of views
https://bugs.eclipse.org/bugs/show_bug.cgi?id=412072 Generalize a correction to avoid the exception org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Widget is disposed) due to while(Display.getDefault.readAndDisplatch());
Diffstat (limited to 'tests/junit/extraplugins')
-rw-r--r--tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/DisplayUtils.java45
-rw-r--r--tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/OpenTableTest.java17
-rw-r--r--tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/TableCreationTest.java5
-rw-r--r--tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/TableCreationTest2.java9
-rw-r--r--tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/TableVerifyContents.java4
5 files changed, 54 insertions, 26 deletions
diff --git a/tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/DisplayUtils.java b/tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/DisplayUtils.java
new file mode 100644
index 00000000000..9b66d8cbe6c
--- /dev/null
+++ b/tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/DisplayUtils.java
@@ -0,0 +1,45 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.views.tests.tests;
+
+import org.eclipse.swt.widgets.Display;
+
+
+public class DisplayUtils {
+
+
+ private DisplayUtils() {
+ //to prevent instanciation
+ }
+
+ /**
+ * a safe version of the call while(Display.getDefault().readAndDispatch());
+ */
+ //FIXME move me in an upper plugin if i works fine
+ public static void safeReadAndDispatch() {
+ while(true) {
+ boolean res = true;
+ try {
+ res = Display.getDefault().readAndDispatch();
+ } catch (Exception e) {
+ //nothing to do
+ }
+ if(res == false) {
+ return;
+ }
+ }
+ }
+
+
+}
diff --git a/tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/OpenTableTest.java b/tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/OpenTableTest.java
index 9b04cb75377..9428d782cf5 100644
--- a/tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/OpenTableTest.java
+++ b/tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/OpenTableTest.java
@@ -25,7 +25,6 @@ import org.eclipse.papyrus.infra.nattable.common.editor.NatTableEditor;
import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
import org.eclipse.papyrus.junit.utils.GenericUtils;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
import org.junit.AfterClass;
import org.junit.Assert;
@@ -62,7 +61,7 @@ public class OpenTableTest extends AbstractEditorIntegrationTest {
Table requirementTable = (Table)notationResource.getContents().get(0);
TransactionalEditingDomain editingDomain = editor.getServicesRegistry().getService(TransactionalEditingDomain.class);
editingDomain.getCommandStack().execute(new GMFtoEMFCommandWrapper(new OpenDiagramCommand(editingDomain, requirementTable)));
- secureReadAndDispatch();
+ DisplayUtils.safeReadAndDispatch();
tableEditor = editor.getActiveEditor();
Assert.assertTrue(tableEditor instanceof NatTableEditor);
INattableModelManager manager = (INattableModelManager)tableEditor.getAdapter(INattableModelManager.class);
@@ -84,18 +83,4 @@ public class OpenTableTest extends AbstractEditorIntegrationTest {
GenericUtils.closeAllEditors();
}
- public static void secureReadAndDispatch() {
- while(true) {
- boolean res = true;
- try {
- res = Display.getCurrent().readAndDispatch();
- } catch (Exception e) {
- //nothing to do
- }
- if(res == false) {
- return;
- }
- }
- }
-
}
diff --git a/tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/TableCreationTest.java b/tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/TableCreationTest.java
index ea89e730d74..a9be3048bdc 100644
--- a/tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/TableCreationTest.java
+++ b/tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/TableCreationTest.java
@@ -92,7 +92,6 @@ public class TableCreationTest {
@BeforeClass
public static void init() {
try {
- GenericUtils.closeAllEditors();
initTests(Activator.getDefault().getBundle(), PROJECT_NAME, MODEL_PATH);
} catch (CoreException e) {
@@ -213,7 +212,7 @@ public class TableCreationTest {
Assert.assertTrue(managedAxis2.contains(subSubPackageTable1));
Assert.assertTrue(managedAxis2.contains(subSubPackageTable2));
- while(Display.getDefault().readAndDispatch());
+ DisplayUtils.safeReadAndDispatch();
Assert.assertEquals(managedAxis2.size(), rowAxisManager2.getTableManager().getRowElementsList().size());
Assert.assertTrue(rowAxisManager2.getTableManager().getRowElementsList().contains(subSubPackageTable1));
@@ -238,7 +237,7 @@ public class TableCreationTest {
Assert.assertNotNull(manager3);
final Table subModelTable3 = manager3.getTable();
Assert.assertEquals(AllTests.VIEWS_TABLE_ID, subModelTable3.getTableConfiguration().getType());
- while(Display.getDefault().readAndDispatch());
+ DisplayUtils.safeReadAndDispatch();
final IAxisManager rowAxisManager3 = manager3.getRowAxisManager();
final Collection<Object> managedAxis_SubPackageTable3 = rowAxisManager3.getAllManagedAxis();
Assert.assertEquals(1, managedAxis_SubPackageTable3.size());
diff --git a/tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/TableCreationTest2.java b/tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/TableCreationTest2.java
index 570189134cf..257f0f58030 100644
--- a/tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/TableCreationTest2.java
+++ b/tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/TableCreationTest2.java
@@ -100,7 +100,6 @@ public class TableCreationTest2 {
@BeforeClass
public static void init() {
try {
- GenericUtils.closeAllEditors();
initTests(Activator.getDefault().getBundle(), PROJECT_NAME, MODEL_PATH);
} catch (CoreException e) {
Activator.log.error(e);
@@ -188,11 +187,11 @@ public class TableCreationTest2 {
@Test
public void createTable2AndDestroyAnOwnedElement() throws ServiceException {
final Object result1 = ModelExplorerUtils.executeCreateNestedEditorHandlerInModelExplorer(papyrusEditor, TableCreationTest2.view, AllTests.COMMAND_ID, TableCreationTest2.rootModel, BUNDLE_ID);
- while(Display.getDefault().readAndDispatch());
+ DisplayUtils.safeReadAndDispatch();
Assert.assertTrue(result1 instanceof NatTableEditor);
final NatTableEditor editor2 = (NatTableEditor)result1;
editor2.setFocus();
- while(Display.getDefault().readAndDispatch());
+ DisplayUtils.safeReadAndDispatch();
final NattableModelManager manager2 = (NattableModelManager)editor2.getAdapter(INattableModelManager.class);
Assert.assertNotNull(manager2);
final Table table2 = manager2.getTable();
@@ -219,7 +218,7 @@ public class TableCreationTest2 {
editingDomain.getCommandStack().execute(new GMFtoEMFCommandWrapper(cmd));
- while(Display.getDefault().readAndDispatch());
+ DisplayUtils.safeReadAndDispatch();
//verify the contents of table2
managedAxis_Table1 = rowAxisManager.getAllManagedAxis();
Assert.assertEquals(3, managedAxis_Table1.size());
@@ -240,7 +239,7 @@ public class TableCreationTest2 {
Assert.assertEquals(3, pageManager.allPages().size());
IEditorPart tableEditor = papyrusEditor.getActiveEditor();
editingDomain.getCommandStack().execute(new GMFtoEMFCommandWrapper(new OpenDiagramCommand(editingDomain, table1)));
- while(Display.getDefault().readAndDispatch());
+ DisplayUtils.safeReadAndDispatch();
tableEditor = papyrusEditor.getActiveEditor();
Assert.assertTrue(tableEditor instanceof NatTableEditor);
INattableModelManager manager = (INattableModelManager)tableEditor.getAdapter(INattableModelManager.class);
diff --git a/tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/TableVerifyContents.java b/tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/TableVerifyContents.java
index 66ddd37519a..109fd82c006 100644
--- a/tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/TableVerifyContents.java
+++ b/tests/junit/extraplugins/table/org.eclipse.papyrus.infra.nattable.views.editor.tests/src/org/eclipse/papyrus/infra/nattable/views/tests/tests/TableVerifyContents.java
@@ -166,7 +166,7 @@ public class TableVerifyContents {
Assert.assertEquals(subModel, table1.getContext());
Assert.assertEquals(subModel, diagram2.getElement());
Assert.assertEquals(rootModel, diagram1.getElement());
- while(Display.getDefault().readAndDispatch());
+ DisplayUtils.safeReadAndDispatch();
}
@@ -193,7 +193,7 @@ public class TableVerifyContents {
Assert.assertNull(tableEditor);
TransactionalEditingDomain editingDomain = papyrusEditor.getServicesRegistry().getService(TransactionalEditingDomain.class);
editingDomain.getCommandStack().execute(new GMFtoEMFCommandWrapper(new OpenDiagramCommand(editingDomain, table1)));
- while(Display.getDefault().readAndDispatch());
+ DisplayUtils.safeReadAndDispatch();
tableEditor = papyrusEditor.getActiveEditor();
Assert.assertTrue(tableEditor instanceof NatTableEditor);
INattableModelManager manager = (INattableModelManager)tableEditor.getAdapter(INattableModelManager.class);

Back to the top