Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCedric Dumoulin2014-01-14 21:28:12 +0000
committerCedric Dumoulin2014-01-27 13:57:40 +0000
commitefbaec61cbec28ce3344c136bebf63f98a799f64 (patch)
treee833cb4f5dfc19f32bff675a03b5acfff07f3d37 /tests/integration
parente5f90dd2ab2520a7886aff973ccb09abb568a1fc (diff)
downloadorg.eclipse.papyrus-efbaec61cbec28ce3344c136bebf63f98a799f64.tar.gz
org.eclipse.papyrus-efbaec61cbec28ce3344c136bebf63f98a799f64.tar.xz
org.eclipse.papyrus-efbaec61cbec28ce3344c136bebf63f98a799f64.zip
First release of integration test utilities.
Diffstat (limited to 'tests/integration')
-rw-r--r--tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/.classpath8
-rw-r--r--tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/.project28
-rw-r--r--tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/META-INF/MANIFEST.MF27
-rw-r--r--tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/about.html28
-rw-r--r--tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/build.properties8
-rw-r--r--tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/plugin.properties12
-rw-r--r--tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/Activator.java30
-rw-r--r--tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/DiagramCreationException.java82
-rw-r--r--tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/DiagramCreator.java120
-rw-r--r--tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/EditorCreationException.java81
-rw-r--r--tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/ExecutionException.java83
-rw-r--r--tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/ProgramaticPapyrusEditor.java256
-rw-r--r--tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/operationhistory/IOperationHistoryHandler.java34
-rw-r--r--tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/operationhistory/OperationHistoryHandler.java98
-rw-r--r--tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/package-info.java24
-rw-r--r--tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/test/org/eclipse/papyrus/integrationtests/editor/DiagramCreatorTest.java81
-rw-r--r--tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/test/org/eclipse/papyrus/integrationtests/editor/ProgramaticPapyrusEditorTest.java105
-rw-r--r--tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/test/org/eclipse/papyrus/integrationtests/editor/undoredo/UndoRedoAfterEditorCreationTest.java200
19 files changed, 1312 insertions, 0 deletions
diff --git a/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/.classpath b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/.classpath
new file mode 100644
index 00000000000..b04b8be8f5d
--- /dev/null
+++ b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="test"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/.project b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/.project
new file mode 100644
index 00000000000..123e0599bfc
--- /dev/null
+++ b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.integrationtests.editor</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/.settings/org.eclipse.jdt.core.prefs b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..44217f8c068
--- /dev/null
+++ b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/META-INF/MANIFEST.MF b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..f848ee13106
--- /dev/null
+++ b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/META-INF/MANIFEST.MF
@@ -0,0 +1,27 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.papyrus.integrationtests.editor
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.eclipse.papyrus.integrationtests.editor.Activator
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.core.resources,
+ org.eclipse.papyrus.infra.core,
+ org.eclipse.ui.workbench,
+ org.eclipse.ui.ide,
+ org.eclipse.emf.ecore;bundle-version="2.9.1",
+ org.junit;bundle-version="4.10.0",
+ org.eclipse.papyrus.uml.tools;bundle-version="1.0.0",
+ org.eclipse.papyrus.uml.diagram.clazz;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.gmfdiag.commands,
+ org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.0.0",
+ org.eclipse.papyrus.uml.diagram.activity;bundle-version="1.0.0",
+ org.eclipse.papyrus.uml.diagram.common;bundle-version="1.0.0",
+ org.eclipse.papyrus.uml.diagram.emftree;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.emf.diagram.common;bundle-version="1.0.0",
+ org.eclipse.core.commands;bundle-version="3.6.100",
+ org.eclipse.emf.transaction;bundle-version="1.4.0"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-Vendor: %providerName
+
diff --git a/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/about.html b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/about.html
new file mode 100644
index 00000000000..82d49bf5f81
--- /dev/null
+++ b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2007</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
diff --git a/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/build.properties b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/build.properties
new file mode 100644
index 00000000000..0c2a30a7e04
--- /dev/null
+++ b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/build.properties
@@ -0,0 +1,8 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ about.html,\
+ plugin.properties,\
+ build.properties
+src.includes = about.html
diff --git a/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/plugin.properties b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/plugin.properties
new file mode 100644
index 00000000000..4773a9eee02
--- /dev/null
+++ b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/plugin.properties
@@ -0,0 +1,12 @@
+#################################################################################
+# Copyright (c) 2013 LIFL.
+# 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:
+# Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+##################################################################################
+pluginName=Papyrus core integration tests (Incubation)
+providerName=Eclipse Modeling Project
diff --git a/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/Activator.java b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/Activator.java
new file mode 100644
index 00000000000..9ed5a9b5f54
--- /dev/null
+++ b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/Activator.java
@@ -0,0 +1,30 @@
+package org.eclipse.papyrus.integrationtests.editor;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator {
+
+ private static BundleContext context;
+
+ static BundleContext getContext() {
+ return context;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext bundleContext) throws Exception {
+ Activator.context = bundleContext;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext bundleContext) throws Exception {
+ Activator.context = null;
+ }
+
+}
diff --git a/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/DiagramCreationException.java b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/DiagramCreationException.java
new file mode 100644
index 00000000000..96629afd563
--- /dev/null
+++ b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/DiagramCreationException.java
@@ -0,0 +1,82 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.integrationtests.editor;
+
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class DiagramCreationException extends ExecutionException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor.
+ *
+ */
+ public DiagramCreationException() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ * @param cause
+ * @param enableSuppression
+ * @param writableStackTrace
+ */
+ public DiagramCreationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ * @param cause
+ */
+ public DiagramCreationException(String message, Throwable cause) {
+ super(message, cause);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ */
+ public DiagramCreationException(String message) {
+ super(message);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param cause
+ */
+ public DiagramCreationException(Throwable cause) {
+ super(cause);
+ // TODO Auto-generated constructor stub
+ }
+
+}
diff --git a/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/DiagramCreator.java b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/DiagramCreator.java
new file mode 100644
index 00000000000..9e2b1158151
--- /dev/null
+++ b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/DiagramCreator.java
@@ -0,0 +1,120 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.integrationtests.editor;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.papyrus.commands.ICreationCommand;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.IPage;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.uml.diagram.activity.CreateActivityDiagramCommand;
+import org.eclipse.papyrus.uml.diagram.clazz.CreateClassDiagramCommand;
+import org.eclipse.papyrus.uml.diagram.emftree.CreateEMFTreeDiagramHandler;
+
+
+/**
+ * This class is used to create programmatically various diagram available in Papyrus.
+ * <br>
+ * This class is designed for tests purpose. It is not intended to be used in regular editor.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class DiagramCreator {
+
+ public ProgramaticPapyrusEditor editorCreator;
+
+ /**
+ * Constructor.
+ *
+ */
+ public DiagramCreator(ProgramaticPapyrusEditor editorCreator) {
+ this.editorCreator = editorCreator;
+ }
+
+ /**
+ * Create a diagram of the requested type. Return the {@link IPage} used in {@link ISashWindowsContainer}.
+ * @param name
+ * @return
+ * @throws DiagramCreationException
+ */
+ public IPage createClassDiagram(String name) throws DiagramCreationException {
+
+ try {
+ ModelSet modelSet = editorCreator.getModelSet();
+
+ ICreationCommand command = new CreateClassDiagramCommand();
+ command.createDiagram(modelSet, null, name);
+
+ // Return the page created by the container.
+ // This should be the activePage
+ ISashWindowsContainer container = editorCreator.getServiceRegistry().getService(ISashWindowsContainer.class);
+ return container.getActiveSashWindowsPage();
+ } catch (ServiceException e) {
+ e.printStackTrace();
+ throw new DiagramCreationException(e);
+ }
+ }
+
+ /**
+ * Create a diagram of the requested type. Return the {@link IPage} used in {@link ISashWindowsContainer}.
+ * @param name
+ * @return
+ * @throws DiagramCreationException
+ */
+ public IPage createActivityDiagram(String name) throws DiagramCreationException {
+
+ try {
+ ModelSet modelSet = editorCreator.getModelSet();
+
+ ICreationCommand command = new CreateActivityDiagramCommand();
+ command.createDiagram(modelSet, null, name);
+
+ // Return the page created by the container.
+ // This should be the activePage
+ ISashWindowsContainer container = editorCreator.getServiceRegistry().getService(ISashWindowsContainer.class);
+ return container.getActiveSashWindowsPage();
+ } catch (ServiceException e) {
+ e.printStackTrace();
+ throw new DiagramCreationException(e);
+ }
+ }
+ /**
+ * Create a diagram of the requested type. Return the {@link IPage} used in {@link ISashWindowsContainer}.
+ * @param name
+ * @return
+ * @throws DiagramCreationException
+ */
+ public IPage createEmfTreeDiagram(String name) throws DiagramCreationException {
+
+ try {
+ ModelSet modelSet = editorCreator.getModelSet();
+
+ CreateEMFTreeDiagramHandler command = new CreateEMFTreeDiagramHandler();
+ command.execute(editorCreator.getServiceRegistry());
+
+ // Return the page created by the container.
+ // This should be the activePage
+ ISashWindowsContainer container = editorCreator.getServiceRegistry().getService(ISashWindowsContainer.class);
+ return container.getActiveSashWindowsPage();
+ } catch (ServiceException e) {
+ e.printStackTrace();
+ throw new DiagramCreationException(e);
+ } catch (ExecutionException e) {
+ throw new DiagramCreationException(e);
+ }
+ }
+}
diff --git a/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/EditorCreationException.java b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/EditorCreationException.java
new file mode 100644
index 00000000000..109a70f2676
--- /dev/null
+++ b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/EditorCreationException.java
@@ -0,0 +1,81 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.integrationtests.editor;
+
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class EditorCreationException extends ExecutionException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor.
+ *
+ */
+ public EditorCreationException() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param arg0
+ */
+ public EditorCreationException(String arg0) {
+ super(arg0);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param arg0
+ */
+ public EditorCreationException(Throwable arg0) {
+ super(arg0);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param arg0
+ * @param arg1
+ */
+ public EditorCreationException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param arg0
+ * @param arg1
+ * @param arg2
+ * @param arg3
+ */
+ public EditorCreationException(String arg0, Throwable arg1, boolean arg2, boolean arg3) {
+ super(arg0, arg1, arg2, arg3);
+ // TODO Auto-generated constructor stub
+ }
+
+}
diff --git a/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/ExecutionException.java b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/ExecutionException.java
new file mode 100644
index 00000000000..22d93992b82
--- /dev/null
+++ b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/ExecutionException.java
@@ -0,0 +1,83 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.integrationtests.editor;
+
+
+/**
+ * Root exception of the package.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class ExecutionException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor.
+ *
+ */
+ public ExecutionException() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ */
+ public ExecutionException(String message) {
+ super(message);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param cause
+ */
+ public ExecutionException(Throwable cause) {
+ super(cause);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ * @param cause
+ */
+ public ExecutionException(String message, Throwable cause) {
+ super(message, cause);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ * @param cause
+ * @param enableSuppression
+ * @param writableStackTrace
+ */
+ public ExecutionException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ // TODO Auto-generated constructor stub
+ }
+
+}
diff --git a/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/ProgramaticPapyrusEditor.java b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/ProgramaticPapyrusEditor.java
new file mode 100644
index 00000000000..a80da31ea8a
--- /dev/null
+++ b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/ProgramaticPapyrusEditor.java
@@ -0,0 +1,256 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.integrationtests.editor;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import org.eclipse.core.commands.operations.IOperationHistory;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.ModelsReader;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
+import org.eclipse.papyrus.uml.tools.model.UmlUtils;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
+
+
+/**
+ * This class allows to create a Papyrus Editor programatically.
+ * The creation require the name of a project and the name of the model to create.
+ * This class is for use in tests.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class ProgramaticPapyrusEditor {
+
+ protected static final String DEFAULT_PROJECT_NAME = "org.eclipse.org.infra.core.defaultproject.integration";
+ protected static final String DEFAULT_MODEL_NAME = "papyrusModelForIntegration";
+
+ /**
+ * Name of the project that will contains Model
+ */
+ protected String projectName = DEFAULT_PROJECT_NAME;
+
+ /**
+ * Name of the model to create.
+ */
+ protected String modelName = DEFAULT_MODEL_NAME;
+
+ /** The di resource set. */
+// protected ModelSet modelSet;
+
+ /** The file. */
+ protected IFile file;
+
+ /** The page. */
+ protected IWorkbenchPage page;
+
+ /** The papyrus editor. */
+ protected IMultiDiagramEditor papyrusEditor;
+
+ /** The project. */
+ protected IProject project;
+
+ /** The root. */
+ protected IWorkspaceRoot root;
+
+
+ /**
+ * Constructor.
+ *
+ * @param projectName
+ * @param modelName
+ * @throws EditorCreationException If the creation fails.
+ */
+ public ProgramaticPapyrusEditor(String projectName, String modelName) throws EditorCreationException {
+ this.projectName = projectName;
+ this.modelName = modelName;
+
+ // Create editor
+ createEditor();
+ }
+
+
+ /**
+ *
+ * Constructor.
+ * @throws EditorCreationException If the creation fails.
+ *
+ */
+ public ProgramaticPapyrusEditor() throws EditorCreationException {
+ // Create editor
+ createEditor();
+ }
+
+
+ /**
+ * Create a model suitable for Papyrus uml.
+ * Save it in the provided file.
+ * @param file
+ * @throws CoreException
+ * @throws IOException
+ */
+ protected void createModel(IFile file) throws CoreException, IOException {
+
+ // Create ModelSet and initialize it with models declared in eclipse extensions
+ ModelSet modelSet = new ModelSet();
+ ModelsReader reader = new ModelsReader();
+ reader.readModel(modelSet);
+
+ file.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor());
+ modelSet.createsModels(file);
+ // populate the model
+ UmlModel umlModel = UmlUtils.getUmlModel(modelSet);
+ umlModel.initializeEmptyModel();
+
+ // ICreationCommand command = getDiagramCommandCreation();
+ // command.createDiagram(modelSet, null, "DiagramToTest");
+ modelSet.save(new NullProgressMonitor());
+
+ }
+ /**
+ * Create a papyrus editor.
+ * @return
+ * @throws EditorCreationException
+ */
+ protected IMultiDiagramEditor createEditor() throws EditorCreationException {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ root = workspace.getRoot();
+ project = root.getProject(projectName);
+ file = project.getFile(modelName + ".di");
+
+ try {
+ //at this point, no resources have been created
+ if(!project.exists()) {
+ project.create(null);
+ }
+ if(!project.isOpen()) {
+ project.open(null);
+ }
+
+ if(file.exists()) {
+ file.delete(true, new NullProgressMonitor());
+ }
+
+ if(!file.exists()) {
+ // Create the model
+ createModel(file);
+ }
+
+ // Create the editor
+ page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
+ papyrusEditor = (IMultiDiagramEditor)page.openEditor(new FileEditorInput(file), desc.getId());
+ return papyrusEditor;
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ throw new EditorCreationException("Can't create editor", e);
+ } catch (CoreException e) {
+ throw new EditorCreationException("Can't create editor", e);
+ } catch (IOException e) {
+ throw new EditorCreationException("Can't create editor", e);
+ }
+
+ }
+
+ /**
+ * Dispose the editor.
+ */
+ public void dispose() {
+
+ if(papyrusEditor == null) {
+ return;
+ }
+
+ // Save model, to avoid popup
+ papyrusEditor.doSave(new NullProgressMonitor());
+ papyrusEditor = null;
+
+ // Dispose done from closeAllEditors ?
+// papyrusEditor.dispose();
+ page.closeAllEditors(true);
+ try {
+ project.delete(true, new NullProgressMonitor());
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ *
+ * @return
+ */
+ public IMultiDiagramEditor getEditor() {
+ return papyrusEditor;
+ }
+
+ /**
+ * Get the {@link ServicesRegistry} associated to the editor.
+ * @return The service registry.
+ */
+ public ServicesRegistry getServiceRegistry() {
+ return papyrusEditor.getServicesRegistry();
+ }
+
+
+ /**
+ * Cached value of modelSet.
+ */
+ private ModelSet modelSet;
+ public ModelSet getModelSet() throws ServiceException {
+ if(modelSet == null) {
+ modelSet = papyrusEditor.getServicesRegistry().getService(ModelSet.class);
+ }
+ return modelSet;
+ }
+
+ public void undo() throws ServiceException {
+ TransactionalEditingDomain domain = getServiceRegistry().getService(TransactionalEditingDomain.class);
+
+ if(domain.getCommandStack().canUndo()) {
+ domain.getCommandStack().undo();
+ }
+ }
+
+ public void redo() throws ServiceException {
+ TransactionalEditingDomain domain = getServiceRegistry().getService(TransactionalEditingDomain.class);
+
+ if(domain.getCommandStack().canRedo()) {
+ domain.getCommandStack().redo();
+ }
+
+ }
+
+ public IOperationHistory getIOperationHistory() {
+ return papyrusEditor.getSite().getWorkbenchWindow().getWorkbench().getOperationSupport().getOperationHistory();
+ }
+}
diff --git a/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/operationhistory/IOperationHistoryHandler.java b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/operationhistory/IOperationHistoryHandler.java
new file mode 100644
index 00000000000..09a9b6aea32
--- /dev/null
+++ b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/operationhistory/IOperationHistoryHandler.java
@@ -0,0 +1,34 @@
+package org.eclipse.papyrus.integrationtests.editor.operationhistory;
+
+import org.eclipse.papyrus.integrationtests.editor.ExecutionException;
+
+
+
+
+public interface IOperationHistoryHandler {
+
+ /**
+ *
+ * @return
+ */
+ public boolean canRedo();
+
+ /**
+ * Redo the last operation in the history.
+ * @throws ExecutionException
+ */
+ public void redo() throws ExecutionException;
+
+ /**
+ *
+ * @return
+ */
+ public boolean canUndo();
+
+ /**
+ * Redo the last operation in the history.
+ * @throws ExecutionException
+ */
+ public void undo() throws ExecutionException;
+
+}
diff --git a/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/operationhistory/OperationHistoryHandler.java b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/operationhistory/OperationHistoryHandler.java
new file mode 100644
index 00000000000..862329897fd
--- /dev/null
+++ b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/operationhistory/OperationHistoryHandler.java
@@ -0,0 +1,98 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.integrationtests.editor.operationhistory;
+
+import org.eclipse.core.commands.operations.IOperationHistory;
+import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.integrationtests.editor.ExecutionException;
+import org.eclipse.papyrus.integrationtests.editor.ProgramaticPapyrusEditor;
+
+
+/**
+ * A handler allowing to perform undo and redo through the {@link IOperationHistory}
+ *
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class OperationHistoryHandler implements IOperationHistoryHandler {
+
+ /** The papyrus editor. */
+ protected IMultiDiagramEditor papyrusEditor;
+
+ protected IOperationHistory history;
+
+ private IUndoContext papyrusContext;
+
+ /**
+ * Constructor.
+ *
+ * @param papyrusEditor
+ * @throws ServiceException
+ */
+ public OperationHistoryHandler(ProgramaticPapyrusEditor handler) throws ServiceException {
+ this.papyrusEditor = handler.getEditor();
+ history = papyrusEditor.getSite().getWorkbenchWindow().getWorkbench().getOperationSupport().getOperationHistory();
+ papyrusContext = handler.getServiceRegistry().getService(IUndoContext.class);
+ }
+
+ public IOperationHistory getIOperationHistory() {
+ return history;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public boolean canRedo() {
+ return history.canRedo(papyrusContext);
+ }
+ /**
+ * @see org.eclipse.papyrus.integrationtests.editor.operationhistory.IOperationHistoryHandler#redo()
+ *
+ * @throws ExecutionException
+ */
+ public void redo() throws ExecutionException {
+ try {
+ history.redo(papyrusContext, null, null);
+ } catch (org.eclipse.core.commands.ExecutionException e) {
+ throw new ExecutionException(e);
+ }
+ }
+
+ /**
+ *
+ * @return
+ */
+ public boolean canUndo() {
+ return history.canUndo(papyrusContext);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.integrationtests.editor.operationhistory.IOperationHistoryHandler#undo()
+ *
+ * @throws ExecutionException
+ */
+ public void undo() throws ExecutionException {
+ try {
+ history.undo(papyrusContext, null, null);
+ } catch (org.eclipse.core.commands.ExecutionException e) {
+ throw new ExecutionException(e);
+ }
+ }
+
+}
diff --git a/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/package-info.java b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/package-info.java
new file mode 100644
index 00000000000..70c1c304ef3
--- /dev/null
+++ b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/src/org/eclipse/papyrus/integrationtests/editor/package-info.java
@@ -0,0 +1,24 @@
+/*****************************************************************************
+ * Copyright (c) 2014 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+/**
+ * This package contains utility classes for integration tests.
+ * <br>
+ * Examples of usages can be found in tests: {@link org.eclipse.papyrus.integrationtests.editor.DiagramCreatorTest}, {@link org.eclipse.papyrus.integrationtests.editor.ProgramaticPapyrusEditorTest}.
+ *
+ *
+ * @author cedric dumoulin
+ *
+ */
+package org.eclipse.papyrus.integrationtests.editor; \ No newline at end of file
diff --git a/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/test/org/eclipse/papyrus/integrationtests/editor/DiagramCreatorTest.java b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/test/org/eclipse/papyrus/integrationtests/editor/DiagramCreatorTest.java
new file mode 100644
index 00000000000..8d4721d62b7
--- /dev/null
+++ b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/test/org/eclipse/papyrus/integrationtests/editor/DiagramCreatorTest.java
@@ -0,0 +1,81 @@
+package org.eclipse.papyrus.integrationtests.editor;
+
+import static org.junit.Assert.*;
+
+import org.eclipse.papyrus.infra.core.sasheditor.editor.IPage;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * Test for {@link DiagramCreator}.
+ *
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class DiagramCreatorTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ *
+ * @throws Exception
+ */
+ @Test
+ @Ignore
+ public void testCreateClassDiagram() throws Exception {
+ ProgramaticPapyrusEditor editorHandler = new ProgramaticPapyrusEditor();
+// DiagramCreator diagramCreator = new DiagramCreator(editorHandler);
+//
+// IPage createdPage = diagramCreator.createClassDiagram("newDiagram");
+//
+// assertNotNull("diagram created", createdPage);
+
+ // exit
+ editorHandler.dispose();
+ }
+
+ /**
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testCreateActivityDiagram() throws Exception {
+ ProgramaticPapyrusEditor editorHandler = new ProgramaticPapyrusEditor();
+ DiagramCreator diagramCreator = new DiagramCreator(editorHandler);
+
+ IPage createdPage = diagramCreator.createActivityDiagram("newDiagram");
+
+ assertNotNull("diagram created", createdPage);
+
+ // exit
+ editorHandler.dispose();
+ }
+
+ /**
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testCreateEMFTreeDiagram() throws Exception {
+ ProgramaticPapyrusEditor editorHandler = new ProgramaticPapyrusEditor();
+ DiagramCreator diagramCreator = new DiagramCreator(editorHandler);
+
+ IPage createdPage = diagramCreator.createEmfTreeDiagram("newDiagram");
+
+ assertNotNull("diagram created", createdPage);
+
+ // exit
+ editorHandler.dispose();
+ }
+
+
+}
diff --git a/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/test/org/eclipse/papyrus/integrationtests/editor/ProgramaticPapyrusEditorTest.java b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/test/org/eclipse/papyrus/integrationtests/editor/ProgramaticPapyrusEditorTest.java
new file mode 100644
index 00000000000..6b4595a53fc
--- /dev/null
+++ b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/test/org/eclipse/papyrus/integrationtests/editor/ProgramaticPapyrusEditorTest.java
@@ -0,0 +1,105 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.integrationtests.editor;
+
+import static org.junit.Assert.*;
+
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Test for the utility class {@link ProgramaticPapyrusEditor}
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class ProgramaticPapyrusEditorTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.integrationtests.editor.ProgramaticPapyrusEditor#createEditor()}.
+ * @throws EditorCreationException
+ */
+ @Test
+ public void testCreateEditor() throws EditorCreationException {
+ ProgramaticPapyrusEditor editorHandler = new ProgramaticPapyrusEditor();
+ IMultiDiagramEditor editor = editorHandler.getEditor();
+
+ assertNotNull("editor created", editor);
+ editorHandler.dispose();
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.integrationtests.editor.ProgramaticPapyrusEditor#dispose()}.
+ */
+ @Test
+ public void testDispose() throws EditorCreationException {
+ ProgramaticPapyrusEditor editorHandler = new ProgramaticPapyrusEditor();
+ IMultiDiagramEditor editor = editorHandler.getEditor();
+
+ assertNotNull("editor created", editor);
+ // Try to dispose
+ editorHandler.dispose();
+ assertNull("editor cleaned", editorHandler.getEditor());
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.integrationtests.editor.ProgramaticPapyrusEditor#getEditor()}.
+ */
+ @Test
+ public void testGetEditor() throws EditorCreationException {
+ ProgramaticPapyrusEditor editorHandler = new ProgramaticPapyrusEditor();
+ IMultiDiagramEditor editor = editorHandler.getEditor();
+
+ assertNotNull("editor created", editor);
+
+ editorHandler.dispose();
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.integrationtests.editor.ProgramaticPapyrusEditor#getServiceRegistry()}.
+ */
+ @Test
+ public void testGetServiceRegistry() throws EditorCreationException {
+ ProgramaticPapyrusEditor editorHandler = new ProgramaticPapyrusEditor();
+ IMultiDiagramEditor editor = editorHandler.getEditor();
+
+ assertNotNull("editor created", editor);
+
+ // Try to get the Registry
+ ServicesRegistry servicesRegistry = editorHandler.getServiceRegistry();
+ assertNotNull("registry initialized", servicesRegistry);
+
+ editorHandler.dispose();
+ }
+
+}
diff --git a/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/test/org/eclipse/papyrus/integrationtests/editor/undoredo/UndoRedoAfterEditorCreationTest.java b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/test/org/eclipse/papyrus/integrationtests/editor/undoredo/UndoRedoAfterEditorCreationTest.java
new file mode 100644
index 00000000000..ab59265efa5
--- /dev/null
+++ b/tests/integration/plugins/org.eclipse.papyrus.integrationtests.editor/test/org/eclipse/papyrus/integrationtests/editor/undoredo/UndoRedoAfterEditorCreationTest.java
@@ -0,0 +1,200 @@
+package org.eclipse.papyrus.integrationtests.editor.undoredo;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.emf.common.command.CommandStack;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.IPage;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.integrationtests.editor.DiagramCreationException;
+import org.eclipse.papyrus.integrationtests.editor.DiagramCreator;
+import org.eclipse.papyrus.integrationtests.editor.EditorCreationException;
+import org.eclipse.papyrus.integrationtests.editor.ExecutionException;
+import org.eclipse.papyrus.integrationtests.editor.ProgramaticPapyrusEditor;
+import org.eclipse.papyrus.integrationtests.editor.operationhistory.IOperationHistoryHandler;
+import org.eclipse.papyrus.integrationtests.editor.operationhistory.OperationHistoryHandler;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ *
+ * Integration tests.
+ * Check the undo/redo after nested editor creation.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class UndoRedoAfterEditorCreationTest {
+
+ /**
+ * Handler on a newly created editor
+ */
+ protected ProgramaticPapyrusEditor editorHandler;
+
+ /**
+ * A diagram creator associated to the editor.
+ * Used to create diagrams.
+ */
+ protected DiagramCreator diagramCreator;
+
+ /**
+ * Create a new editor
+ * @throws Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ editorHandler = new ProgramaticPapyrusEditor();
+ diagramCreator = new DiagramCreator(editorHandler);
+ }
+
+ /**
+ * Dispose the editor.
+ * @throws Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ editorHandler.dispose();
+ }
+
+ /**
+ * @throws DiagramCreationException
+ * @throws EditorCreationException
+ * @throws ServiceException
+ *
+ */
+ @Test
+ public void testUndoRedoUndo() throws DiagramCreationException, EditorCreationException, ServiceException {
+
+ TransactionalEditingDomain domain = editorHandler.getServiceRegistry().getService(TransactionalEditingDomain.class);
+ CommandStack cstack = domain.getCommandStack();
+
+ // Create one diagram
+ IPage createdPage = diagramCreator.createEmfTreeDiagram("newDiagram");
+ assertNotNull("diagram created", createdPage);
+ // Try to undo
+ editorHandler.undo();
+ assertNull("diagram removed", editorHandler.getEditor().getActiveEditor());
+
+ // Try to redo
+ editorHandler.redo();
+ assertNotNull("diagram exist", editorHandler.getEditor().getActiveEditor());
+
+ // Try to undo
+ editorHandler.undo();
+ assertNull("diagram removed", editorHandler.getEditor().getActiveEditor());
+
+ // Try to redo
+ editorHandler.redo();
+ assertNotNull("diagram exist", editorHandler.getEditor().getActiveEditor());
+ // Check di now
+
+ }
+
+ /**
+ * @throws ServiceException
+ * @throws ExecutionException
+ *
+ */
+ @Test
+ public void testUndoRedoUndoIOperationHistory() throws ServiceException, ExecutionException {
+
+ // Create one diagram
+ IPage createdPage = diagramCreator.createEmfTreeDiagram("newDiagram");
+ assertNotNull("diagram created", createdPage);
+
+ IOperationHistoryHandler history = new OperationHistoryHandler(editorHandler);
+
+ // Try to undo
+ assertTrue("Can undo", history.canUndo());
+ history.undo();
+ assertNull("diagram removed", editorHandler.getEditor().getActiveEditor());
+
+
+ // Try to redo
+ assertTrue("Can redo", history.canRedo());
+ history.redo();
+ assertNotNull("diagram exist", editorHandler.getEditor().getActiveEditor());
+
+ // Try to undo
+ assertTrue("Can undo", history.canUndo());
+ history.undo();
+ assertNull("diagram removed", editorHandler.getEditor().getActiveEditor());
+
+ // Try to redo
+ assertTrue("Can redo", history.canRedo());
+ history.redo();
+ assertNotNull("diagram exist", editorHandler.getEditor().getActiveEditor());
+ // Check di now
+
+ }
+
+ /**
+ * @throws ServiceException
+ * @throws ExecutionException
+ *
+ */
+ @Test
+ public void testDoubleCreateUndoUndoRedoRedoIOperationHistory() throws ServiceException, ExecutionException {
+
+ IOperationHistoryHandler history = new OperationHistoryHandler(editorHandler);
+ ISashWindowsContainer container = editorHandler.getServiceRegistry().getService(ISashWindowsContainer.class);
+
+ // Create one diagram
+ IPage createdPage = diagramCreator.createEmfTreeDiagram("newDiagram");
+ Object page1RawModel = createdPage.getRawModel();
+
+ assertNotNull("diagram created", createdPage);
+ assertNotNull("diagram created", page1RawModel);
+
+ IPage createdPage2 = diagramCreator.createEmfTreeDiagram("newDiagram");
+ Object page2RawModel = createdPage2.getRawModel();
+ assertNotNull("diagram created", createdPage);
+ assertNotNull("diagram created", page2RawModel);
+
+ // Try to undo
+ assertTrue("Can undo", history.canUndo());
+ history.undo();
+ assertNull( "diagram removed", container.lookupModelPage(page2RawModel ));
+ assertNotNull( "diagram preserved", container.lookupModelPage(page1RawModel ));
+
+
+ // Try to undo
+ assertTrue("Can undo", history.canUndo());
+ history.undo();
+ assertNull( "diagram removed", container.lookupModelPage(page2RawModel ));
+ assertNull( "diagram removed", container.lookupModelPage(page1RawModel ));
+ assertNull("no active editor", editorHandler.getEditor().getActiveEditor());
+
+ // Try to redo
+ assertTrue("Can redo", history.canRedo());
+ history.redo();
+ assertNotNull( "diagram restored", container.lookupModelPage(page1RawModel ));
+ assertNotNull("active editor set", editorHandler.getEditor().getActiveEditor());
+
+ // Try to redo
+ assertTrue("Can redo", history.canRedo());
+ history.redo();
+ assertNotNull( "diagram restored", container.lookupModelPage(page2RawModel ));
+ assertNotNull("active editor set", editorHandler.getEditor().getActiveEditor());
+
+ // Try to undo
+ assertTrue("Can undo", history.canUndo());
+ history.undo();
+ assertNull( "diagram removed", container.lookupModelPage(page2RawModel ));
+ assertNotNull( "diagram preserved", container.lookupModelPage(page1RawModel ));
+
+ // Try to redo
+ assertTrue("Can redo", history.canRedo());
+ history.redo();
+ assertNotNull( "diagram restored", container.lookupModelPage(page2RawModel ));
+ assertNotNull("active editor set", editorHandler.getEditor().getActiveEditor());
+ // Check di now
+
+ }
+
+
+}

Back to the top