Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Schnekenburger2015-08-04 16:10:37 +0000
committerRemi Schnekenburger2015-08-04 16:10:37 +0000
commitad5ffda30df9a409e90cbcb60d3a87d5218311a7 (patch)
treeca8a0e5c4f0668e58b99914457fb349e0c23dd9d /tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse
parent4bbb2be51f267eab98a3b5fee1dc7299458d153b (diff)
downloadorg.eclipse.papyrus-rt-ad5ffda30df9a409e90cbcb60d3a87d5218311a7.tar.gz
org.eclipse.papyrus-rt-ad5ffda30df9a409e90cbcb60d3a87d5218311a7.tar.xz
org.eclipse.papyrus-rt-ad5ffda30df9a409e90cbcb60d3a87d5218311a7.zip
Small fixes:
- update name for a RTport is not working due to too restrictive advice - update wizard (move class to the wizard plugin) - create test class for connectors Change-Id: Idcf6dda9298f9171d104804356ae4d4620cff357
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/creation/CreateConnectorTests.java191
1 files changed, 191 insertions, 0 deletions
diff --git a/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/creation/CreateConnectorTests.java b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/creation/CreateConnectorTests.java
new file mode 100644
index 000000000..f8cb3ca50
--- /dev/null
+++ b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/creation/CreateConnectorTests.java
@@ -0,0 +1,191 @@
+/*****************************************************************************
+ * 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.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 class for connector creation.
+ */
+public class CreateConnectorTests 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("UMLRTConnectorTests");
+
+ // import test model
+ try {
+ copyPapyrusModel = PapyrusProjectUtils.copyPapyrusModel(createProject, Platform.getBundle("org.eclipse.papyrusrt.umlrt.core"), "/resource/", "ConnectorTestModel");
+ } 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