Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Schnekenburger2015-10-22 09:39:50 +0000
committerRemi Schnekenburger2015-10-22 09:39:50 +0000
commit18fffdab0c2241139982028430ae8bc99e5ac65b (patch)
treea56330a053a3e635d268beede30391b0a5e4d73c /tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/edition
parent15663daecd1d3ec38284575e9a583e0e75446268 (diff)
downloadorg.eclipse.papyrus-rt-18fffdab0c2241139982028430ae8bc99e5ac65b.tar.gz
org.eclipse.papyrus-rt-18fffdab0c2241139982028430ae8bc99e5ac65b.tar.xz
org.eclipse.papyrus-rt-18fffdab0c2241139982028430ae8bc99e5ac65b.zip
469825: [UML-RT] Inconsistent default naming of UML-RT Protocol and its
internal elements https://bugs.eclipse.org/bugs/show_bug.cgi?id=469825 - Update tests framework: shared abstract class to initialize tests - Adding a failing test (@Failingtest) to check that all names are changed when renaming a protocol Change-Id: I9cbab28cd2fb1d6841d757c069e7362a018b98f2
Diffstat (limited to 'tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/edition')
-rw-r--r--tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/edition/AbstractEditionElementTest.java79
-rw-r--r--tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/edition/ProtocolEditionTests.java33
-rw-r--r--tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/edition/ProtocolRenameValidation.java73
3 files changed, 185 insertions, 0 deletions
diff --git a/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/edition/AbstractEditionElementTest.java b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/edition/AbstractEditionElementTest.java
new file mode 100644
index 000000000..a206c46c5
--- /dev/null
+++ b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/edition/AbstractEditionElementTest.java
@@ -0,0 +1,79 @@
+/*****************************************************************************
+ * 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.edition;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.papyrusrt.umlrt.core.tests.AbstractPapyrusRTCoreTest;
+import org.eclipse.papyrusrt.umlrt.core.tests.utils.IValidationRule;
+import org.eclipse.uml2.uml.Element;
+import org.junit.Assert;
+
+/**
+ * Test class for edition of UML-RT elements
+ */
+public abstract class AbstractEditionElementTest extends AbstractPapyrusRTCoreTest {
+
+ protected void runEditionTest(Element target, EStructuralFeature featureToSet, Object newValue, boolean canEdit, Class<? extends IValidationRule> validationClass) throws Exception {
+ Assert.assertTrue("Editor should not be dirty before test", !openPapyrusEditor.isDirty());
+ Command command = getEditCommand(target, featureToSet, newValue, canEdit);
+
+ // command has been tested when created. Runs the test if it is possible
+ if (command != null && canEdit) {
+ transactionalEditingDomain.getCommandStack().execute(command);
+ IValidationRule validationRule = validationClass.newInstance();
+ Object[] commandResults = command.getResult().toArray();
+ validationRule.validatePostEdition(target, commandResults);
+ transactionalEditingDomain.getCommandStack().undo();
+ validationRule.validatePostUndo(target, commandResults);
+ Assert.assertTrue("Editor should not be dirty after undo", !openPapyrusEditor.isDirty());
+ transactionalEditingDomain.getCommandStack().redo();
+ validationRule.validatePostEdition(target, commandResults);
+ transactionalEditingDomain.getCommandStack().undo();
+ validationRule.validatePostUndo(target, commandResults);
+ // assert editor is not dirty
+ Assert.assertTrue("Editor should not be dirty after undo", !openPapyrusEditor.isDirty());
+ } else {
+ if (canEdit) {
+ fail("Command is executable while it should not be");
+ }
+ }
+ }
+
+ protected Command getEditCommand(Element target, EStructuralFeature featureToSet, Object newValue, boolean canEdit) {
+ IElementEditService elementEditService = ElementEditServiceUtils.getCommandProvider(target);
+ ICommand command = elementEditService.getEditCommand(new SetRequest(target, featureToSet, newValue));
+
+ if (!canEdit) {
+ // 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;
+ }
+}
diff --git a/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/edition/ProtocolEditionTests.java b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/edition/ProtocolEditionTests.java
new file mode 100644
index 000000000..d28305887
--- /dev/null
+++ b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/edition/ProtocolEditionTests.java
@@ -0,0 +1,33 @@
+/*****************************************************************************
+ * 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.edition;
+
+import org.eclipse.papyrus.junit.framework.classification.FailingTest;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.junit.Test;
+
+/**
+ * Tests for Protocol edition
+ */
+public class ProtocolEditionTests extends AbstractEditionElementTest {
+
+ public static final Object OLD_NAME = "Protocol0";
+
+ public static final Object NEW_NAME = "newName";
+
+ @FailingTest
+ @Test
+ public void testRenameProtocol() throws Exception {
+ runEditionTest(protocol, UMLPackage.eINSTANCE.getNamedElement_Name(), NEW_NAME, true, ProtocolRenameValidation.class);
+ }
+
+}
diff --git a/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/edition/ProtocolRenameValidation.java b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/edition/ProtocolRenameValidation.java
new file mode 100644
index 000000000..084b48bc3
--- /dev/null
+++ b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/edition/ProtocolRenameValidation.java
@@ -0,0 +1,73 @@
+/*****************************************************************************
+ * 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.edition;
+
+import org.eclipse.papyrusrt.umlrt.core.tests.utils.IValidationRule;
+import org.eclipse.papyrusrt.umlrt.core.utils.ProtocolUtils;
+import org.eclipse.uml2.uml.Collaboration;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Interface;
+import org.junit.Assert;
+
+/**
+ * Validation rules for Protocol renaming
+ */
+public class ProtocolRenameValidation implements IValidationRule {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void validatePostEdition(Element targetContainer, Object[] commandResults) throws Exception {
+ Assert.assertTrue(ProtocolUtils.isProtocol(targetContainer));
+ Collaboration protocol = (Collaboration) targetContainer;
+ org.eclipse.uml2.uml.Package protocolContainer = ProtocolUtils.getProtocolContainer(protocol);
+ Assert.assertNotNull(protocolContainer);
+ Interface messageSetIn = ProtocolUtils.getMessageSetIn(protocol);
+ Assert.assertNotNull(messageSetIn);
+ Interface messageSetOut = ProtocolUtils.getMessageSetIn(protocol);
+ Assert.assertNotNull(messageSetOut);
+ Interface messageSetInOut = ProtocolUtils.getMessageSetIn(protocol);
+ Assert.assertNotNull(messageSetInOut);
+
+ Assert.assertEquals("Wrong name for Protocol after Protocol renaming", ProtocolEditionTests.NEW_NAME, protocol.getName());
+ Assert.assertEquals("Wrong name for Protocol container after Protocol renaming", ProtocolEditionTests.NEW_NAME, protocolContainer.getName());
+ Assert.assertEquals("Wrong name for MessageSet IN after Protocol renaming", ProtocolEditionTests.NEW_NAME, messageSetIn.getName());
+ Assert.assertEquals("Wrong name for MessageSet OUT after Protocol renaming", ProtocolEditionTests.NEW_NAME + "~", messageSetOut.getName());
+ Assert.assertEquals("Wrong name for MessageSet INOUT after Protocol renaming", ProtocolEditionTests.NEW_NAME + "IO", messageSetInOut.getName());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void validatePostUndo(Element targetContainer, Object[] commandResults) throws Exception {
+ // check names for Protocol, protocolContainer, message sets and links
+ Assert.assertTrue(ProtocolUtils.isProtocol(targetContainer));
+ Collaboration protocol = (Collaboration) targetContainer;
+ org.eclipse.uml2.uml.Package protocolContainer = ProtocolUtils.getProtocolContainer(protocol);
+ Assert.assertNotNull(protocolContainer);
+ Interface messageSetIn = ProtocolUtils.getMessageSetIn(protocol);
+ Assert.assertNotNull(messageSetIn);
+ Interface messageSetOut = ProtocolUtils.getMessageSetIn(protocol);
+ Assert.assertNotNull(messageSetOut);
+ Interface messageSetInOut = ProtocolUtils.getMessageSetIn(protocol);
+ Assert.assertNotNull(messageSetInOut);
+
+ Assert.assertEquals("Wrong name for Protocol after Protocol renaming", ProtocolEditionTests.OLD_NAME, protocol.getName());
+ Assert.assertEquals("Wrong name for Protocol container after Protocol renaming", ProtocolEditionTests.OLD_NAME, protocolContainer.getName());
+ Assert.assertEquals("Wrong name for MessageSet IN after Protocol renaming", ProtocolEditionTests.OLD_NAME, messageSetIn.getName());
+ Assert.assertEquals("Wrong name for MessageSet OUT after Protocol renaming", ProtocolEditionTests.OLD_NAME + "~", messageSetOut.getName());
+ Assert.assertEquals("Wrong name for MessageSet INOUT after Protocol renaming", ProtocolEditionTests.OLD_NAME + "IO", messageSetInOut.getName());
+ }
+
+}

Back to the top