Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Schnekenburger2015-06-19 18:16:07 +0000
committerRemi Schnekenburger2015-06-19 18:16:07 +0000
commit89d033dd6469f667b7580cb2290030d31bbcd299 (patch)
treee986fe35dd739288abf2e375d622d57a1800358c /tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse
parent2358ef2187e37c577bbefc424ef9d9f93b367a9c (diff)
downloadorg.eclipse.papyrus-rt-89d033dd6469f667b7580cb2290030d31bbcd299.tar.gz
org.eclipse.papyrus-rt-89d033dd6469f667b7580cb2290030d31bbcd299.tar.xz
org.eclipse.papyrus-rt-89d033dd6469f667b7580cb2290030d31bbcd299.zip
Adding a test project for umlrt.core plugin
Diffstat (limited to 'tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse')
-rw-r--r--tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/AllTests.java26
-rw-r--r--tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/creation/CreateElementTest.java196
2 files changed, 222 insertions, 0 deletions
diff --git a/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/AllTests.java b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/AllTests.java
new file mode 100644
index 000000000..d7454ca4e
--- /dev/null
+++ b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/AllTests.java
@@ -0,0 +1,26 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * CEA LIST - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrusrt.umlrt.core.tests;
+
+import org.eclipse.papyrusrt.umlrt.core.tests.creation.CreateElementTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+/**
+ * All Tests suite class for this plugin
+ */
+@RunWith(Suite.class)
+@SuiteClasses({ CreateElementTest.class })
+public class AllTests {
+
+}
diff --git a/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/creation/CreateElementTest.java b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/creation/CreateElementTest.java
new file mode 100644
index 000000000..bd30393f0
--- /dev/null
+++ b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/creation/CreateElementTest.java
@@ -0,0 +1,196 @@
+/*****************************************************************************
+ * Copyright (c) 2013, 2015 CEA LIST, 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 434993
+ * Christian W. Damus - bug 468071
+ *
+ *****************************************************************************/
+package org.eclipse.papyrusrt.umlrt.core.tests.creation;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.ModelUtils;
+import org.eclipse.papyrus.infra.core.resource.NotFoundException;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.elementtypesconfigurations.registries.ElementTypeSetConfigurationRegistry;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest;
+import org.eclipse.papyrus.junit.utils.PapyrusProjectUtils;
+import org.eclipse.papyrus.junit.utils.rules.HouseKeeper;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
+import org.eclipse.papyrus.uml.tools.model.UmlUtils;
+import org.eclipse.papyrusrt.umlrt.core.types.UMLRTElementTypesEnumerator;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.uml2.uml.Model;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+/**
+ * Test creation of UML elements (Creation / Undo / redo)
+ */
+public class CreateElementTest extends AbstractPapyrusTest {
+
+ @ClassRule
+ public static final HouseKeeper.Static houseKeeper = new HouseKeeper.Static();
+
+ private static IProject createProject;
+
+ private static IFile copyPapyrusModel;
+
+ private static IMultiDiagramEditor openPapyrusEditor;
+
+ private static ModelSet modelset;
+
+ private static UmlModel umlIModel;
+
+ private static Model rootModel;
+
+ private static TransactionalEditingDomain transactionalEditingDomain;
+
+ /**
+ * Init test class
+ */
+ @BeforeClass
+ public static void initCreateElementTest() throws Exception {
+
+ // create Project
+ createProject = houseKeeper.createProject("UMLRTCoreTests");
+
+ // import test model
+ try {
+ copyPapyrusModel = PapyrusProjectUtils.copyPapyrusModel(createProject, Platform.getBundle("org.eclipse.papyrusrt.umlrt.core"), "/resource/", "TestModel");
+ } catch (CoreException e) {
+ fail(e.getMessage());
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+
+ // open project
+ openPapyrusEditor = houseKeeper.openPapyrusEditor(copyPapyrusModel);
+
+ transactionalEditingDomain = openPapyrusEditor.getAdapter(TransactionalEditingDomain.class);
+ assertTrue("Impossible to init editing domain", transactionalEditingDomain instanceof TransactionalEditingDomain);
+
+ // retrieve UML model from this editor
+ try {
+ modelset = ModelUtils.getModelSetChecked(openPapyrusEditor.getServicesRegistry());
+ umlIModel = UmlUtils.getUmlModel(modelset);
+ rootModel = (Model) umlIModel.lookupRoot();
+ } catch (ServiceException e) {
+ fail(e.getMessage());
+ } catch (NotFoundException e) {
+ fail(e.getMessage());
+ } catch (ClassCastException e) {
+ fail(e.getMessage());
+ }
+ try {
+ initExistingElements();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ // force load of the element type registry. Will need to load in in UI thread because of some advice in communication diag: see org.eclipse.gmf.tooling.runtime.providers.DiagramElementTypeImages
+ Display.getDefault().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ ElementTypeSetConfigurationRegistry registry = ElementTypeSetConfigurationRegistry.getInstance();
+ Assert.assertNotNull("registry should not be null after init", registry);
+ Assert.assertNotNull("element type should not be null", UMLRTElementTypesEnumerator.CAPSULE);
+ }
+ });
+ }
+
+ /**
+ * Init fields corresponding to element in the test model
+ */
+ private static void initExistingElements() throws Exception {
+ // existing test activity
+ // testActivity = (Activity) rootModel.getOwnedMember("TestActivity");
+ // testClass = (Class) rootModel.getOwnedMember("TestClass");
+ // testActivityWithNode = (Activity) rootModel.getOwnedMember("TestActivityWithNode");
+ // testClassWithOperation = (Class) rootModel.getOwnedMember("TestClassWithOperation");
+ // testOperation = testClassWithOperation.getOwnedOperation("foo", null, null);
+ }
+
+
+
+ @Test
+ public void testCreateCapsuleInModel() throws Exception {
+ runCreationTest(rootModel, UMLRTElementTypesEnumerator.CAPSULE, true);
+ }
+
+ protected void runCreationTest(EObject owner, IHintedType hintedType, boolean canCreate) throws Exception {
+ Assert.assertTrue("Editor should not be dirty before test", !openPapyrusEditor.isDirty());
+ Command command = getCreateChildCommand(owner, hintedType, canCreate);
+
+ // command has been tested when created. Runs the test if it is possible
+ if (command != null && canCreate) {
+ transactionalEditingDomain.getCommandStack().execute(command);
+ transactionalEditingDomain.getCommandStack().undo();
+ Assert.assertTrue("Editor should not be dirty after undo", !openPapyrusEditor.isDirty());
+ transactionalEditingDomain.getCommandStack().redo();
+ transactionalEditingDomain.getCommandStack().undo();
+ // assert editor is not dirty
+ Assert.assertTrue("Editor should not be dirty after undo", !openPapyrusEditor.isDirty());
+ }
+
+ }
+
+ /**
+ * Creates the element in the givesn owner element, undo and redo the action
+ *
+ * @param owner
+ * owner of the new element
+ * @param hintedType
+ * type of the new element
+ * @param canCreate
+ * <code>true</code> if new element can be created in the specified owner
+ */
+ protected Command getCreateChildCommand(EObject owner, IHintedType hintedType, boolean canCreate) throws Exception {
+ IElementEditService elementEditService = ElementEditServiceUtils.getCommandProvider(owner);
+ ICommand command = elementEditService.getEditCommand(new CreateElementRequest(owner, hintedType));
+
+ if (!canCreate) {
+ // command should not be executable: either it should be null or it should be not executable
+ if (command != null && command.canExecute()) {
+ fail("Creation command is executable but it was expected as not executable");
+ }
+ } else {
+ // command should be executable in this case
+ assertNotNull("Command should not be null", command);
+ assertTrue("Command should be executable", command.canExecute());
+ // command is executable, and it was expected to => run the creation
+ Command emfCommand = new org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper(command);
+ return emfCommand;
+ }
+ return null;
+ }
+
+}

Back to the top