Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'tests/junit/plugins/junit')
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/Activator.java34
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/JUnitUtils.java12
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ActiveDiagram.java33
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java91
4 files changed, 157 insertions, 13 deletions
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/Activator.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/Activator.java
index 703f0b176b3..c51d331687a 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/Activator.java
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/Activator.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
+ * Copyright (c) 2012, 2015 CEA LIST, Christian W. Damus, and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,6 +9,7 @@
*
* Contributors:
* Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 433206
*
*****************************************************************************/
package org.eclipse.papyrus.junit.utils;
@@ -16,6 +17,8 @@ package org.eclipse.papyrus.junit.utils;
import org.eclipse.papyrus.infra.core.log.LogHelper;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.application.ApplicationHandle;
/**
* The activator class controls the plug-in life cycle
@@ -30,29 +33,34 @@ public class Activator extends AbstractUIPlugin {
public static LogHelper log;
+ private String runningApplicationID;
+
/**
* The constructor
*/
public Activator() {
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
- */
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
log = new LogHelper(this);
+
+ // Get the running application ID
+ ServiceReference<ApplicationHandle> appRef = context.getServiceReference(ApplicationHandle.class);
+ if (appRef != null) {
+ ApplicationHandle appHandle = context.getService(appRef);
+ if (appHandle != null) {
+ try {
+ runningApplicationID = appHandle.getApplicationDescriptor().getApplicationId();
+ } finally {
+ context.ungetService(appRef);
+ }
+ }
+ }
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
- */
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
@@ -68,4 +76,8 @@ public class Activator extends AbstractUIPlugin {
return plugin;
}
+ public String getRunningApplicationID() {
+ return (runningApplicationID == null) ? "" : runningApplicationID; //$NON-NLS-1$
+ }
+
}
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/JUnitUtils.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/JUnitUtils.java
index 17bfadc190c..0982ea9fc29 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/JUnitUtils.java
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/JUnitUtils.java
@@ -19,7 +19,7 @@ import org.junit.rules.TestRule;
import org.junit.runner.Description;
/**
- * Utilities for working with the JUnit data model.
+ * Utilities for working with the JUnit data model and execution environment.
*/
public class JUnitUtils {
@@ -113,4 +113,14 @@ public class JUnitUtils {
return result;
}
+
+ /**
+ * Queries whether the current JUnit test execution is running in the automated build environment
+ * (whether actually on the build server or not; users can run local builds on their development systems, too).
+ *
+ * @return whether the tests are running in the automated build environment
+ */
+ public static boolean isAutomatedBuildExecution() {
+ return Activator.getDefault().getRunningApplicationID().startsWith("org.eclipse.tycho."); //$NON-NLS-1$
+ }
}
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ActiveDiagram.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ActiveDiagram.java
new file mode 100644
index 00000000000..5ae3344d156
--- /dev/null
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ActiveDiagram.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2015 Christian W. Damus 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:
+ * Christian W. Damus - Initial API and implementation
+ *
+ */
+package org.eclipse.papyrus.junit.utils.rules;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+/**
+ * Annotation on a test indicating the diagram to activate.
+ *
+ * @see PapyrusEditorFixture
+ */
+@Target({ ElementType.METHOD, ElementType.TYPE })
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ActiveDiagram {
+ /**
+ * The name of the diagram to activate.
+ */
+ String value();
+}
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
index 959005b38de..fbc377f5de2 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014 CEA and others.
+ * Copyright (c) 2014, 2015 CEA, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,7 @@
*
* Contributors:
* Christian W. Damus (CEA) - Initial API and implementation
+ * Christian W. Damus - bug 433206
*
*/
package org.eclipse.papyrus.junit.utils.rules;
@@ -41,11 +42,15 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.RootEditPart;
import org.eclipse.gef.ui.palette.PaletteViewer;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IDiagramPreferenceSupport;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette;
import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
+import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.editor.PapyrusMultiDiagramEditor;
import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
@@ -59,7 +64,10 @@ import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.core.utils.AdapterUtils;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
+import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel;
import org.eclipse.papyrus.junit.utils.EditorUtils;
+import org.eclipse.papyrus.junit.utils.JUnitUtils;
import org.eclipse.papyrus.junit.utils.tests.AbstractEditorTest;
import org.eclipse.papyrus.uml.tools.model.UmlModel;
import org.eclipse.papyrus.views.modelexplorer.ModelExplorerPage;
@@ -146,6 +154,16 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
openAll(description);
+ ActiveDiagram activeDiagram = JUnitUtils.getAnnotation(description, ActiveDiagram.class);
+ if (activeDiagram != null) {
+ String name = activeDiagram.value();
+ activateDiagram(name);
+ if ((activeDiagramEditor == null) || !name.equals(getActiveDiagramEditor().getDiagram().getName())) {
+ // OK, we need to open it, then
+ openDiagram(name);
+ }
+ }
+
super.starting(description);
}
@@ -218,6 +236,7 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
Display.getDefault().syncExec(new Runnable() {
+ @Override
public void run() {
try {
editor = EditorUtils.openPapyrusEditor(modelFile);
@@ -233,6 +252,7 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
final IWorkbenchPage page = editor.getSite().getPage();
page.addPartListener(new IPartListener() {
+ @Override
public void partClosed(IWorkbenchPart part) {
editorsToClose.remove(part);
@@ -245,18 +265,22 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
}
}
+ @Override
public void partOpened(IWorkbenchPart part) {
// Pass
}
+ @Override
public void partDeactivated(IWorkbenchPart part) {
// Pass
}
+ @Override
public void partBroughtToTop(IWorkbenchPart part) {
// Pass
}
+ @Override
public void partActivated(IWorkbenchPart part) {
// Pass
}
@@ -332,6 +356,7 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
Display.getDefault().syncExec(new Runnable() {
+ @Override
public void run() {
ModelExplorerPageBookView view;
try {
@@ -426,6 +451,7 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
sashContainer.visit(new IPageVisitor() {
+ @Override
public void accept(IEditorPage page) {
if (name.equals(page.getPageTitle()) && (page.getIEditorPart() instanceof DiagramEditorWithFlyOutPalette)) {
select[0] = page;
@@ -433,6 +459,7 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
}
}
+ @Override
public void accept(IComponentPage page) {
// Pass
}
@@ -446,6 +473,54 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
return this;
}
+ public PapyrusEditorFixture openDiagram(String name) {
+ return openDiagram(editor, name);
+ }
+
+ public PapyrusEditorFixture openDiagram(IMultiDiagramEditor editor, final String name) {
+ activate(editor);
+
+ try {
+ ModelSet modelSet = ServiceUtils.getInstance().getModelSet(editor.getServicesRegistry());
+ NotationModel notation = (NotationModel) modelSet.getModel(NotationModel.MODEL_ID);
+ Diagram diagram = notation.getDiagram(name);
+ ServiceUtils.getInstance().getIPageManager(editor.getServicesRegistry()).openPage(diagram);
+ flushDisplayEvents();
+ } catch (Exception e) {
+ throw new IllegalStateException("Cannot initialize test", e);
+ }
+
+ return this;
+ }
+
+ public String closeDiagram() {
+ String result = getActiveDiagramEditor().getDiagram().getName();
+ closeDiagram(editor, result);
+ return result;
+ }
+
+ public PapyrusEditorFixture closeDiagram(String name) {
+ return closeDiagram(editor, name);
+ }
+
+ public PapyrusEditorFixture closeDiagram(IMultiDiagramEditor editor, final String name) {
+ try {
+ ModelSet modelSet = ServiceUtils.getInstance().getModelSet(editor.getServicesRegistry());
+ NotationModel notation = (NotationModel) modelSet.getModel(NotationModel.MODEL_ID);
+ Diagram diagram = notation.getDiagram(name);
+
+ // If the diagram was deleted, then so too was its page
+ if (diagram != null) {
+ ServiceUtils.getInstance().getIPageManager(editor.getServicesRegistry()).closePage(diagram);
+ flushDisplayEvents();
+ }
+ } catch (Exception e) {
+ throw new IllegalStateException("Cannot close diagram", e);
+ }
+
+ return this;
+ }
+
public DiagramEditorWithFlyOutPalette getActiveDiagramEditor() {
DiagramEditorWithFlyOutPalette result = activeDiagramEditor;
@@ -821,4 +896,18 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
return ((location != null) ? location : (relativeTo == null) ? DEFAULT_LOCATION_EDITORS : DEFAULT_LOCATION_VIEW).toModelServiceLocation();
}
}
+
+ public PreferencesHint getPreferencesHint() {
+ PreferencesHint result = PreferencesHint.USE_DEFAULTS;
+
+ if (activeDiagramEditor != null) {
+ RootEditPart rootEditPart = activeDiagramEditor.getDiagramGraphicalViewer().getRootEditPart();
+ if (rootEditPart instanceof IDiagramPreferenceSupport) {
+ result = ((IDiagramPreferenceSupport) rootEditPart).getPreferencesHint();
+ }
+ }
+
+ return result;
+ }
+
}

Back to the top