Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2015-06-17 14:29:34 +0000
committervincent lorenzo2015-06-17 16:35:23 +0000
commitf4f4c688b41e4d56955e3d0007a6d86f32dae234 (patch)
treee00fea9dd37ead838ad47c777e6de02fa854a898 /tests/junit/plugins/junit
parent375f89b099e0c28f0a46eee440873bcf3c178560 (diff)
downloadorg.eclipse.papyrus-f4f4c688b41e4d56955e3d0007a6d86f32dae234.tar.gz
org.eclipse.papyrus-f4f4c688b41e4d56955e3d0007a6d86f32dae234.tar.xz
org.eclipse.papyrus-f4f4c688b41e4d56955e3d0007a6d86f32dae234.zip
bug 470267: [Tests] The class PapyrusEditorFixture should be able to manage Tabular editors too https://bugs.eclipse.org/bugs/show_bug.cgi?id=470267
Change-Id: I11758d4975140ab63834da12a09710150e9cf35d Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr> Reviewed-on: https://git.eclipse.org/r/50259 Tested-by: Hudson CI
Diffstat (limited to 'tests/junit/plugins/junit')
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF4
-rwxr-xr-xtests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ActiveTable.java33
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java101
3 files changed, 137 insertions, 1 deletions
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF
index 44217fe01a5..0ba438bb2d9 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF
@@ -22,7 +22,9 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.e4.ui.workbench;bundle-version="1.1.0",
org.eclipse.e4.ui.model.workbench;bundle-version="1.1.0",
org.eclipse.e4.core.contexts;bundle-version="1.3.0",
- org.eclipse.papyrus.junit.framework;bundle-version="1.1.0"
+ org.eclipse.papyrus.junit.framework;bundle-version="1.1.0",
+ org.eclipse.papyrus.infra.nattable.common;bundle-version="1.1.0",
+ org.eclipse.papyrus.infra.nattable;bundle-version="1.1.0"
Export-Package: org.eclipse.papyrus.junit.matchers,
org.eclipse.papyrus.junit.utils,
org.eclipse.papyrus.junit.utils.resources,
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ActiveTable.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ActiveTable.java
new file mode 100755
index 00000000000..44d26fb35fa
--- /dev/null
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ActiveTable.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 table to activate.
+ *
+ * @see PapyrusEditorFixture
+ */
+@Target({ ElementType.METHOD, ElementType.TYPE })
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ActiveTable {
+ /**
+ * The name of the table 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 41921996135..58c941d61f2 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
@@ -83,6 +83,10 @@ 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.infra.nattable.common.editor.AbstractEMFNattableEditor;
+import org.eclipse.papyrus.infra.nattable.common.modelresource.PapyrusNattableModel;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
import org.eclipse.papyrus.infra.tools.util.TypeUtils;
import org.eclipse.papyrus.junit.utils.EditorUtils;
import org.eclipse.papyrus.junit.utils.JUnitUtils;
@@ -132,6 +136,8 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
private DiagramEditorWithFlyOutPalette activeDiagramEditor;
+ private AbstractEMFNattableEditor activeTableEditor;
+
private ModelExplorerView modelExplorer;
private Class<?> testClass;
@@ -180,6 +186,15 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
// OK, we need to open it, then
openDiagram(name);
}
+ } else {
+ ActiveTable activeTable = JUnitUtils.getAnnotation(description, ActiveTable.class);
+ if (activeTable != null) {
+ String name = activeTable.value();
+ activateTable(name);
+ if ((activeTableEditor == null) || !name.equals(getActiveTableEditor().getTable().getName())) {
+ openTable(name);
+ }
+ }
}
super.starting(description);
@@ -199,6 +214,7 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
}
}
}
+ //nothing to do for table
}
});
}
@@ -479,6 +495,10 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
return activateDiagram(editor, name);
}
+ public PapyrusEditorFixture activateTable(String name) {
+ return activateTable(editor, name);
+ }
+
public PapyrusEditorFixture activateDiagram(IMultiDiagramEditor editor, final String name) {
activate(editor);
@@ -509,8 +529,44 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
return this;
}
+ public PapyrusEditorFixture activateTable(IMultiDiagramEditor editor, final String name) {
+ activate(editor);
+
+ final ISashWindowsContainer sashContainer = AdapterUtils.adapt(editor, ISashWindowsContainer.class, null);
+ final org.eclipse.papyrus.infra.core.sasheditor.editor.IPage[] select = { null };
+
+ sashContainer.visit(new IPageVisitor() {
+
+ @Override
+ public void accept(IEditorPage page) {
+ if (name.equals(page.getPageTitle()) && (page.getIEditorPart() instanceof AbstractEMFNattableEditor)) {
+ select[0] = page;
+ setActiveTableEditor((AbstractEMFNattableEditor) page.getIEditorPart());
+ }
+ }
+
+ @Override
+ public void accept(IComponentPage page) {
+ // Pass
+ }
+ });
+
+ if (select[0] != null) {
+ sashContainer.selectPage(select[0]);
+ flushDisplayEvents();
+ }
+
+ return this;
+ }
+
private void setActiveDiagramEditor(DiagramEditorWithFlyOutPalette editor) {
activeDiagramEditor = editor;
+ activeTableEditor = null;
+ }
+
+ private void setActiveTableEditor(AbstractEMFNattableEditor editor) {
+ activeTableEditor = editor;
+ activeDiagramEditor = null;
}
public PapyrusEditorFixture activateDiagram(DiagramEditPart diagram) {
@@ -552,6 +608,10 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
return openDiagram(editor, name);
}
+ public PapyrusEditorFixture openTable(String name) {
+ return openTable(editor, name);
+ }
+
public PapyrusEditorFixture openDiagram(IMultiDiagramEditor editor, final String name) {
activate(editor);
@@ -570,6 +630,24 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
return this;
}
+ public PapyrusEditorFixture openTable(IMultiDiagramEditor editor, final String name) {
+ activate(editor);
+
+ try {
+ ModelSet modelSet = ServiceUtils.getInstance().getModelSet(editor.getServicesRegistry());
+ PapyrusNattableModel notation = (PapyrusNattableModel) modelSet.getModel(PapyrusNattableModel.MODEL_ID);
+ Table table = notation.getTable(name);
+ ServiceUtils.getInstance().getIPageManager(editor.getServicesRegistry()).openPage(table);
+ flushDisplayEvents();
+
+ activateTable(editor, name);
+ } catch (Exception e) {
+ throw new IllegalStateException("Cannot initialize test", e); //NON-NLS-1
+ }
+
+ return this;
+ }
+
public String closeDiagram() {
String result = getActiveDiagramEditor().getDiagram().getName();
closeDiagram(editor, result);
@@ -617,10 +695,33 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
return result;
}
+ public AbstractEMFNattableEditor getActiveTableEditor() {
+ AbstractEMFNattableEditor result = activeTableEditor;
+
+ if (result == null) {
+ IEditorPart activeEditor = getWorkbenchPage().getActiveEditor();
+ if (activeEditor instanceof IMultiDiagramEditor) {
+ activeEditor = ((IMultiDiagramEditor) activeEditor).getActiveEditor();
+ if (activeEditor instanceof AbstractEMFNattableEditor) {
+ result = (AbstractEMFNattableEditor) activeEditor;
+ setActiveTableEditor(result);
+ }
+ }
+ }
+
+ assertThat("No table active", result, notNullValue());
+
+ return result;
+ }
+
public DiagramEditPart getActiveDiagram() {
return getActiveDiagramEditor().getDiagramEditPart();
}
+ public INattableModelManager getActiveTableManager(){
+ return (INattableModelManager) getActiveTableEditor().getAdapter(INattableModelManager.class);
+ }
+
public DiagramEditPart getDiagram(String name) {
return getDiagram(editor, name);
}

Back to the top