From c98ff0e6a92ae28ec7372c2bef045bf31e12fcf7 Mon Sep 17 00:00:00 2001
From: vlorenzo
Date: Fri, 24 Aug 2012 16:22:05 +0000
Subject: Share the tests for the generic table
---
.../.classpath | 7 +
.../.project | 28 +++
.../.settings/org.eclipse.jdt.core.prefs | 7 +
.../META-INF/MANIFEST.MF | 23 +++
.../build.properties | 4 +
...e.papyrus.uml.table.efacet.generic.tests.launch | 41 ++++
.../resources/model.di | 17 ++
.../resources/model.notation | 37 ++++
.../resources/model.uml | 7 +
.../uml/table/efacet/generic/tests/Activator.java | 50 +++++
.../uml/table/efacet/generic/tests/AllTests.java | 25 +++
.../features/DerivedFeatureTests.java | 211 +++++++++++++++++++++
12 files changed, 457 insertions(+)
create mode 100644 sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/.classpath
create mode 100644 sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/.project
create mode 100644 sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/.settings/org.eclipse.jdt.core.prefs
create mode 100644 sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/META-INF/MANIFEST.MF
create mode 100644 sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/build.properties
create mode 100644 sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/org.eclipse.papyrus.uml.table.efacet.generic.tests.launch
create mode 100644 sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/resources/model.di
create mode 100644 sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/resources/model.notation
create mode 100644 sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/resources/model.uml
create mode 100644 sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/src/org/eclipse/papyrus/uml/table/efacet/generic/tests/Activator.java
create mode 100644 sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/src/org/eclipse/papyrus/uml/table/efacet/generic/tests/AllTests.java
create mode 100644 sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/src/org/eclipse/papyrus/uml/table/efacet/generic/tests/synchronization/features/DerivedFeatureTests.java
diff --git a/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/.classpath b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/.classpath
new file mode 100644
index 00000000000..2d1a4302f04
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/.classpath
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/.project b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/.project
new file mode 100644
index 00000000000..631f711272d
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/.project
@@ -0,0 +1,28 @@
+
+
+ org.eclipse.papyrus.uml.table.efacet.generic.tests
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.pde.ManifestBuilder
+
+
+
+
+ org.eclipse.pde.SchemaBuilder
+
+
+
+
+
+ org.eclipse.pde.PluginNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/.settings/org.eclipse.jdt.core.prefs b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..44217f8c068
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/.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/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/META-INF/MANIFEST.MF b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..0829c9f0fb0
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/META-INF/MANIFEST.MF
@@ -0,0 +1,23 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Tests UML Generic Table (Incubation)
+Bundle-SymbolicName: org.eclipse.papyrus.uml.table.efacet.generic.tests
+Bundle-Version: 0.9.0.qualifier
+Bundle-Activator: org.eclipse.papyrus.uml.table.efacet.generic.tests.Activator
+Bundle-Vendor: Eclipse Modeling Project
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.junit;bundle-version="4.10.0",
+ org.eclipse.papyrus.uml.table.efacet.generic;bundle-version="0.9.0",
+ org.eclipse.papyrus.infra.table.efacet.common;bundle-version="0.9.0",
+ org.eclipse.papyrus.junit.utils;bundle-version="0.9.0",
+ org.eclipse.papyrus.views.modelexplorer,
+ org.eclipse.core.resources,
+ org.eclipse.uml2.uml;bundle-version="4.0.0",
+ org.eclipse.ui.navigator;bundle-version="3.5.200",
+ org.eclipse.papyrus.infra.table.efacet.metamodel;bundle-version="0.9.0",
+ org.eclipse.emf.facet.widgets.table.ui,
+ org.eclipse.emf.transaction;bundle-version="1.4.0",
+ org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.6.0"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
diff --git a/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/build.properties b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/build.properties
new file mode 100644
index 00000000000..41eb6ade2b4
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/org.eclipse.papyrus.uml.table.efacet.generic.tests.launch b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/org.eclipse.papyrus.uml.table.efacet.generic.tests.launch
new file mode 100644
index 00000000000..d7d8c26371b
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/org.eclipse.papyrus.uml.table.efacet.generic.tests.launch
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/resources/model.di b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/resources/model.di
new file mode 100644
index 00000000000..61c16241819
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/resources/model.di
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/resources/model.notation b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/resources/model.notation
new file mode 100644
index 00000000000..609aeb8e987
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/resources/model.notation
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/resources/model.uml b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/resources/model.uml
new file mode 100644
index 00000000000..6ca721ad327
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/resources/model.uml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/src/org/eclipse/papyrus/uml/table/efacet/generic/tests/Activator.java b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/src/org/eclipse/papyrus/uml/table/efacet/generic/tests/Activator.java
new file mode 100644
index 00000000000..1c06e378b0b
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/src/org/eclipse/papyrus/uml/table/efacet/generic/tests/Activator.java
@@ -0,0 +1,50 @@
+package org.eclipse.papyrus.uml.table.efacet.generic.tests;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.uml.table.efacet.generic.tests"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/src/org/eclipse/papyrus/uml/table/efacet/generic/tests/AllTests.java b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/src/org/eclipse/papyrus/uml/table/efacet/generic/tests/AllTests.java
new file mode 100644
index 00000000000..8dc4ecd6d5d
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/src/org/eclipse/papyrus/uml/table/efacet/generic/tests/AllTests.java
@@ -0,0 +1,25 @@
+/*****************************************************************************
+ * Copyright (c) 2012 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.uml.table.efacet.generic.tests;
+
+import org.eclipse.papyrus.uml.table.efacet.generic.tests.synchronization.features.DerivedFeatureTests;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+@RunWith(Suite.class)
+@SuiteClasses({ DerivedFeatureTests.class })
+public class AllTests {
+ // JUnit 4 test suite
+}
diff --git a/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/src/org/eclipse/papyrus/uml/table/efacet/generic/tests/synchronization/features/DerivedFeatureTests.java b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/src/org/eclipse/papyrus/uml/table/efacet/generic/tests/synchronization/features/DerivedFeatureTests.java
new file mode 100644
index 00000000000..54c28dc8d5d
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.uml.table.efacet.generic.tests/src/org/eclipse/papyrus/uml/table/efacet/generic/tests/synchronization/features/DerivedFeatureTests.java
@@ -0,0 +1,211 @@
+package org.eclipse.papyrus.uml.table.efacet.generic.tests.synchronization.features;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Row;
+import org.eclipse.emf.facet.widgets.table.ui.internal.exported.TableWidgetUtils;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.core.editor.CoreMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel;
+import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.FillingMode;
+import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrusTable;
+import org.eclipse.papyrus.junit.utils.EditorUtils;
+import org.eclipse.papyrus.junit.utils.GenericUtils;
+import org.eclipse.papyrus.junit.utils.HandlerUtils;
+import org.eclipse.papyrus.junit.utils.ModelExplorerUtils;
+import org.eclipse.papyrus.junit.utils.PapyrusProjectUtils;
+import org.eclipse.papyrus.junit.utils.ProjectUtils;
+import org.eclipse.papyrus.uml.table.efacet.generic.tests.Activator;
+import org.eclipse.papyrus.views.modelexplorer.ModelExplorerView;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.Port;
+import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+
+public class DerivedFeatureTests {
+
+ private static final String CREATE_GENERIC_UML_TABLE = "org.eclipse.papyrus.uml.generic.table.command.withoutdialog"; //$NON-NLS-1$
+
+ private static final String MODEL = "model"; //$NON-NLS-1$
+
+ private static ModelExplorerView modelExplorerView;
+
+ private static IProject project;
+
+ private static CoreMultiDiagramEditor papyrusEditor;
+
+ private static Class class1;
+
+ @BeforeClass
+ public static void init() throws CoreException, IOException {
+ GenericUtils.closeIntroPart();
+ GenericUtils.cleanWorkspace();
+ final IProject project = ProjectUtils.createProject("GenericTableTest"); //$NON-NLS-1$
+ PapyrusProjectUtils.copyPapyrusModel(project, Activator.getDefault().getBundle(), "/resources/", MODEL); //$NON-NLS-1$
+ final IFile file = project.getFile(MODEL + "." + SashModel.MODEL_FILE_EXTENSION); //$NON-NLS-1$
+ Assert.assertNotNull(file);
+ papyrusEditor = (CoreMultiDiagramEditor)EditorUtils.openEditor(file);
+ Assert.assertNotNull(papyrusEditor);
+ modelExplorerView = ModelExplorerUtils.openModelExplorerView();
+ final Model root = (Model)ModelExplorerUtils.getRootInModelExplorer(modelExplorerView);
+ class1 = (Class)root.getOwnedMember("Class1"); //$NON-NLS-1$
+ }
+
+ public void setSelectionInTheModelExplorer() {
+ final List selection = new ArrayList();
+ selection.add(class1);
+ modelExplorerView.setFocus();
+ ModelExplorerUtils.setSelectionInTheModelexplorer(modelExplorerView, selection);
+ }
+
+ @Test
+ public void handlerActivationTest() {
+ final IHandler handler = HandlerUtils.getActiveHandlerFor(CREATE_GENERIC_UML_TABLE);
+ Assert.assertNotNull(handler);
+ Assert.assertTrue(handler.isEnabled());
+ }
+
+ @Test
+ public void createEmptyTableTest() throws Exception {
+ setSelectionInTheModelExplorer();
+ final Command cmd = HandlerUtils.getCommand(CREATE_GENERIC_UML_TABLE);
+ HandlerUtils.executeCommand(cmd);
+ final PapyrusTable table = getCurrentTable();
+ Assert.assertNotNull(table);
+ final List elements = TableWidgetUtils.getElements(table.getTable());
+ Assert.assertTrue("The created table is not empty", elements.isEmpty());
+ }
+
+ protected PapyrusTable getCurrentTable() {
+ final PapyrusTable table = null;
+ return table;
+ }
+
+ protected TransactionalEditingDomain getEditingDomain(){
+ return null;
+ }
+
+
+ @Test
+ public void createTableWithContentsTest() throws Exception {
+ //we create a new table
+ createEmptyTableTest();
+ final PapyrusTable table = getCurrentTable();
+ final Port port1 = UMLFactory.eINSTANCE.createPort();
+ port1.setName("port1");
+ class1.getAllAttributes().add(port1);
+
+ //TODO add this port to the table
+
+ table.setFillingMode(FillingMode.CONTEXT_FEATURE);
+ //there is no feature to listen, so the content of the table should be deleted
+ Assert.assertTrue(table.getTable().getRows().isEmpty());
+ //TODO
+ final EReference ref = UMLPackage.eINSTANCE.getEncapsulatedClassifier_OwnedPort();
+ table.setContextFeature(ref);
+ //the table should now content 1 element
+ EList rows = table.getTable().getRows();
+ Assert.assertTrue(rows.size()==1);
+ Assert.assertTrue(rows.get(0).getElement()==port1);
+
+ final Port port2 = UMLFactory.eINSTANCE.createPort();
+ port2.setName("port2");
+ class1.getAllAttributes().add(port2);
+
+ rows = table.getTable().getRows();
+ Assert.assertTrue(rows.size()==2);
+ Assert.assertTrue(rows.get(0).getElement()==port1);
+ Assert.assertTrue(rows.get(1).getElement()==port2);
+ }
+
+
+ @Test
+ public void reparentElementTest() throws Exception {
+ createEmptyTableTest();
+ final PapyrusTable table = getCurrentTable();
+ final Port port1 = UMLFactory.eINSTANCE.createPort();
+ port1.setName("port1");
+ class1.getAllAttributes().add(port1);
+
+ //TODO add this port to the table
+
+ table.setFillingMode(FillingMode.CONTEXT_FEATURE);
+ //there is no feature to listen, so the content of the table should be deleted
+ Assert.assertTrue(table.getTable().getRows().isEmpty());
+ //TODO
+ final EReference ref = UMLPackage.eINSTANCE.getEncapsulatedClassifier_OwnedPort();
+ table.setContextFeature(ref);
+ //the table should now content 1 element
+ EList rows = table.getTable().getRows();
+ Assert.assertTrue(rows.size()==1);
+ Assert.assertTrue(rows.get(0).getElement()==port1);
+
+ Class class2 = UMLFactory.eINSTANCE.createClass();
+ class1.getPackage().getOwnedElements().add(class2);
+
+ //we reparent port1
+ class2.getAllAttributes().add(port1); //TODO verify if it is the best way!
+ rows = table.getTable().getRows();
+ Assert.assertTrue(rows.size()==0);
+ }
+
+ @Test
+ public void destroyElementTest() throws Exception {
+ createEmptyTableTest();
+ final PapyrusTable table = getCurrentTable();
+ final Port port1 = UMLFactory.eINSTANCE.createPort();
+ port1.setName("port1");
+ class1.getAllAttributes().add(port1);
+
+ //TODO add this port to the table
+
+ table.setFillingMode(FillingMode.CONTEXT_FEATURE);
+ //there is no feature to listen, so the content of the table should be deleted
+ Assert.assertTrue(table.getTable().getRows().isEmpty());
+ //TODO
+ final EReference ref = UMLPackage.eINSTANCE.getEncapsulatedClassifier_OwnedPort();
+ table.setContextFeature(ref);
+ //the table should now content 1 element
+ EList rows = table.getTable().getRows();
+ Assert.assertTrue(rows.size()==1);
+ Assert.assertTrue(rows.get(0).getElement()==port1);
+
+ //TODO destroy Port1
+ }
+
+ @Ignore
+ @Test
+ public void destroyTableTest() {
+//should be moved in a modelexplorer plugin
+ }
+
+ @Ignore
+ @Test
+ public void destroyTableContextTest() {
+ //should be moved in a modelexplorer plugin
+ }
+
+ @AfterClass
+ public static void closeAll() {
+ GenericUtils.closeAllEditors();
+ }
+}
--
cgit v1.2.3