diff options
author | Christian W. Damus | 2014-07-25 12:59:18 +0000 |
---|---|---|
committer | Christian W. Damus | 2014-07-25 12:59:27 +0000 |
commit | 76ce2af562505666a2bf0220437ed4a25e4fa9ad (patch) | |
tree | 0a2c354352b743614aec68566177fae1859da425 | |
parent | 715756de4c89da6e17cc10a0d92fa9aa6b8c19e3 (diff) | |
download | org.eclipse.papyrus-76ce2af562505666a2bf0220437ed4a25e4fa9ad.tar.gz org.eclipse.papyrus-76ce2af562505666a2bf0220437ed4a25e4fa9ad.tar.xz org.eclipse.papyrus-76ce2af562505666a2bf0220437ed4a25e4fa9ad.zip |
440284: [Tests] Sequence diagram tests run very slowly
https://bugs.eclipse.org/bugs/show_bug.cgi?id=440284
The creation of the diagram for one of the Sequence Diagram suites requires the Outline View, so show it just during the test set-up.
-rw-r--r-- | tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/HideViewRule.java (renamed from tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/HideViewRule.java) | 2 | ||||
-rw-r--r-- | tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/RuleUtil.java | 132 | ||||
-rw-r--r-- | tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ShowViewRule.java | 72 | ||||
-rw-r--r-- | tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/AllTests.java | 1 | ||||
-rw-r--r-- | tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/pro20130916/Fixbug_LifelineManagement_417365.java | 14 |
5 files changed, 218 insertions, 3 deletions
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/HideViewRule.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/HideViewRule.java index fac564ea26a..66830a5159b 100644 --- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/HideViewRule.java +++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/HideViewRule.java @@ -11,7 +11,7 @@ * *****************************************************************************/ -package org.eclipse.papyrus.uml.diagram.sequence.tests; +package org.eclipse.papyrus.junit.utils.rules; import static org.junit.Assert.fail; diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/RuleUtil.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/RuleUtil.java new file mode 100644 index 00000000000..8ff16363b7c --- /dev/null +++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/RuleUtil.java @@ -0,0 +1,132 @@ +/***************************************************************************** + * Copyright (c) 2014 CEA LIST 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: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.junit.utils.rules; + +import static org.junit.Assert.fail; + +import java.util.concurrent.Callable; + +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + + +/** + * Utilities for working with JUnit {@linkplain TestRule rules}. + */ +public class RuleUtil { + + private RuleUtil() { + super(); + } + + /** + * Ad hoc invocation of an operation wrapped in the start/finish behaviour of a JUnit rule. + * + * @param run + * the operation to run + * @param rule + * the rule to wrap it in + * + * @throws Exception + * on any exception thrown by the runnable or the rule + */ + public static void runWith(Runnable run, TestRule rule) throws Exception { + callWith(call(run), rule); + } + + /** + * Safe ad hoc invocation of an operation wrapped in the start/finish behaviour of a JUnit rule. + * Fails JUnitishly on any exception in the callable or the rule. + * + * @param run + * the operation to run + * @param rule + * the rule to wrap it in + */ + public static void safeRunWith(Runnable run, TestRule rule) throws Exception { + safeCallWith(call(run), rule); + } + + static Callable<?> call(final Runnable run) { + return new Callable<Void>() { + + public Void call() throws Exception { + run.run(); + return null; + } + }; + } + + /** + * Ad hoc invocation of a callable wrapped in the start/finish behaviour of a JUnit rule. + * + * @param callable + * the callable to execute + * @param rule + * the rule to wrap it in + * + * @throws Exception + * on any exception thrown by the callable or the rule + */ + public static <V> V callWith(Callable<V> callable, TestRule rule) throws Exception { + class CallableStatement extends Statement { + + final Callable<V> callable; + + V result; + + CallableStatement(Callable<V> callable) { + this.callable = callable; + } + + @Override + public void evaluate() throws Throwable { + result = callable.call(); + } + } + + try { + CallableStatement statement = new CallableStatement(callable); + rule.apply(statement, Description.EMPTY).evaluate(); + return statement.result; + } catch (Throwable t) { + if(t instanceof Exception) { + throw (Exception)t; + } else { + throw (Error)t; + } + } + } + + /** + * Safe ad hoc invocation of a callable wrapped in the start/finish behaviour of a JUnit rule. + * Fails JUnitishly on any exception in the callable or the rule. + * + * @param callable + * the callable to execute + * @param rule + * the rule to wrap it in + */ + public static <V> V safeCallWith(Callable<V> callable, TestRule rule) { + try { + return callWith(callable, rule); + } catch (Exception e) { + e.printStackTrace(); + fail("Failed to invoke callable with rule: " + e.getLocalizedMessage()); + return null; // Unreachable + } + } + +} diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ShowViewRule.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ShowViewRule.java new file mode 100644 index 00000000000..0459c73a971 --- /dev/null +++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ShowViewRule.java @@ -0,0 +1,72 @@ +/***************************************************************************** + * Copyright (c) 2014 CEA LIST 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: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.junit.utils.rules; + +import static org.junit.Assert.fail; + +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; + + +/** + * A rule that ensures a view is showing for the duration of a test. + */ +public class ShowViewRule extends TestWatcher { + + private final String viewID; + + private IViewPart view; + + public ShowViewRule(String viewID) { + super(); + + this.viewID = viewID; + } + + @Override + protected void starting(Description description) { + IWorkbench bench = PlatformUI.getWorkbench(); + IWorkbenchWindow window = bench.getActiveWorkbenchWindow(); + if(window == null) { + window = bench.getWorkbenchWindows()[0]; + } + + IWorkbenchPage page = window.getActivePage(); + view = page.findView(viewID); + + if(view == null) { + try { + view = page.showView(viewID); + } catch (PartInitException e) { + fail(String.format("Failed to show view %s: %s", viewID, e.getLocalizedMessage())); + } + } + } + + @Override + protected void finished(Description description) { + if(view != null) { + // Hide it again, because we showed it in the first place + view.getSite().getPage().hideView(view); + } + + view = null; + } +} diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/AllTests.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/AllTests.java index c43c862d8d8..48feac10d73 100644 --- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/AllTests.java +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/AllTests.java @@ -14,6 +14,7 @@ *****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.tests;
+import org.eclipse.papyrus.junit.utils.rules.HideViewRule;
import org.eclipse.papyrus.uml.diagram.sequence.tests.bug.BugTests;
import org.eclipse.papyrus.uml.diagram.sequence.tests.bug.BugTests2;
import org.eclipse.papyrus.uml.diagram.sequence.tests.bug.m7.BugTest_m7;
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/pro20130916/Fixbug_LifelineManagement_417365.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/pro20130916/Fixbug_LifelineManagement_417365.java index 9a8332bf3f6..ecedbecc926 100644 --- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/pro20130916/Fixbug_LifelineManagement_417365.java +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/pro20130916/Fixbug_LifelineManagement_417365.java @@ -1,7 +1,6 @@ /*****************************************************************************
* Copyright (c) 2013, 2014 Soyatec, CEA, 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
@@ -10,6 +9,7 @@ * Contributors:
* Soyatec - Initial API and implementation
* Christian W. Damus (CEA) - fix lost message so that it doesn't get bent out of shape
+ * Christian W. Damus (CEA) - bug 440284
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.tests.bug.pro20130916;
@@ -31,6 +31,8 @@ import org.eclipse.gmf.runtime.diagram.core.commands.SetPropertyCommand; import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.papyrus.junit.utils.classification.InvalidTest;
+import org.eclipse.papyrus.junit.utils.rules.RuleUtil;
+import org.eclipse.papyrus.junit.utils.rules.ShowViewRule;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.AbstractExecutionSpecificationEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.AbstractMessageEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentCombinedFragmentCompartmentEditPart;
@@ -95,7 +97,15 @@ public class Fixbug_LifelineManagement_417365 extends BaseStereotypesTest { @Override
public void setUp() throws Exception {
super.setUp();
- prepareDiagram();
+
+ // Show the outline view while we're creating the diagram, because it seems to be necessary to create
+ // a properly horizontal message6 from a gate to lifeline4
+ RuleUtil.runWith(new Runnable() {
+
+ public void run() {
+ prepareDiagram();
+ }
+ }, new ShowViewRule("org.eclipse.ui.views.ContentOutline"));
}
/**
|