Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Schnekenburger2017-03-03 16:06:21 +0000
committerGerrit Code Review @ Eclipse.org2017-03-06 09:50:13 +0000
commit6f52c4c920bfec9e4984d471e0e3ca4c9d601080 (patch)
treeb04383a9a786d6696d20e8af7de9b2abd3cdccf8 /tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse
parentfdb01cf1128261822d80c814ccc2215dd5118911 (diff)
downloadorg.eclipse.papyrus-rt-6f52c4c920bfec9e4984d471e0e3ca4c9d601080.tar.gz
org.eclipse.papyrus-rt-6f52c4c920bfec9e4984d471e0e3ca4c9d601080.tar.xz
org.eclipse.papyrus-rt-6f52c4c920bfec9e4984d471e0e3ca4c9d601080.zip
Bug 494284: [Tooling] Create a UML-RT Transition using the tool palette
in a state machine diagram https://bugs.eclipse.org/bugs/show_bug.cgi?id=494284 - Delete entry/exit pseudo states that do not have any outgoings/incomings when the last transition is deleted - adding JUnit tests Change-Id: Ied4f42464fe5e610bae4893bc69843be1c68a230 Signed-off-by: Remi Schnekenburger <rschnekenburger@eclipsesource.com>
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/AbstractPapyrusRTCoreTest.java152
-rw-r--r--tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/deletion/DeleteElementTest.java90
-rw-r--r--tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/deletion/DeleteTransitionsTest.java237
3 files changed, 385 insertions, 94 deletions
diff --git a/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/AbstractPapyrusRTCoreTest.java b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/AbstractPapyrusRTCoreTest.java
index b379bd616..bb821410d 100644
--- a/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/AbstractPapyrusRTCoreTest.java
+++ b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/AbstractPapyrusRTCoreTest.java
@@ -12,26 +12,43 @@
*****************************************************************************/
package org.eclipse.papyrusrt.umlrt.core.tests;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.RollbackException;
+import org.eclipse.emf.transaction.Transaction;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.impl.InternalTransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.GetEditContextRequest;
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.services.edit.internal.context.TypeContext;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.papyrus.infra.services.edit.utils.IRequestCacheEntries;
import org.eclipse.papyrus.infra.types.core.registries.ElementTypeSetConfigurationRegistry;
import org.eclipse.papyrus.infra.ui.editor.IMultiDiagramEditor;
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.diagram.statemachine.providers.UMLElementTypes;
import org.eclipse.papyrus.uml.tools.model.UmlModel;
import org.eclipse.papyrus.uml.tools.model.UmlUtils;
import org.eclipse.papyrusrt.junit.rules.ElementTypesRule;
@@ -141,8 +158,29 @@ public abstract class AbstractPapyrusRTCoreTest extends AbstractPapyrusTest {
protected static Transition transition;
+ protected static State composite1;
+
+ protected static State composite2;
+
+ protected static Pseudostate composite1_exit1;
+ protected static Pseudostate composite1_exit2;
+ protected static Pseudostate composite1_exit3;
+ protected static Pseudostate composite1_exit4;
+
+ protected static Pseudostate composite2_entry1;
+ protected static Pseudostate composite2_entry2;
+ protected static Pseudostate composite2_entry3;
+ protected static Pseudostate composite2_entry4;
+
+ protected static Transition t1;
+ protected static Transition t2;
+ protected static Transition t3;
+ protected static Transition t4;
+
+ protected static Transition t5;
+
/**
- * Init test class
+ * Init test class.
*/
@BeforeClass
public static void initCreateElementTest() throws Exception {
@@ -165,9 +203,6 @@ public abstract class AbstractPapyrusRTCoreTest extends AbstractPapyrusTest {
public void run() {
// force loading of the state machine plugin, but in UI thread, as the element types require some UI...
ElementTypeSetConfigurationRegistry registry = ElementTypeSetConfigurationRegistry.getInstance();
- System.err.println(registry.getElementTypeSetConfigurations());
- System.err.println(UMLElementTypes.Region_Shape);
-
}
});
@@ -295,5 +330,112 @@ public abstract class AbstractPapyrusRTCoreTest extends AbstractPapyrusTest {
Assert.assertNotNull(emptyCompositeStateRegion);
initialPseudoState = region.getSubvertices().stream().filter(Pseudostate.class::isInstance).map(Pseudostate.class::cast).filter(p -> p.getKind() == PseudostateKind.INITIAL_LITERAL).findFirst().get();
+
+ composite1 = compositeStateRegion.getOwnedMember("composite1") instanceof State ? (State) compositeStateRegion.getOwnedMember("composite1") : null;
+ Assert.assertNotNull(composite1);
+
+ composite2 = compositeStateRegion.getOwnedMember("composite2") instanceof State ? (State) compositeStateRegion.getOwnedMember("composite2") : null;
+ Assert.assertNotNull(composite2);
+
+ composite1_exit1 = composite1.getConnectionPoint("exit1");
+ Assert.assertNotNull(composite1_exit1);
+ composite1_exit2 = composite1.getConnectionPoint("exit2");
+ Assert.assertNotNull(composite1_exit2);
+ composite1_exit3 = composite1.getConnectionPoint("exit3");
+ Assert.assertNotNull(composite1_exit3);
+ composite1_exit4 = composite1.getConnectionPoint("exit4");
+ Assert.assertNotNull(composite1_exit4);
+ composite2_entry1 = composite2.getConnectionPoint("entry1");
+ Assert.assertNotNull(composite2_entry1);
+ composite2_entry2 = composite2.getConnectionPoint("entry2");
+ Assert.assertNotNull(composite2_entry2);
+ composite2_entry3 = composite2.getConnectionPoint("entry3");
+ Assert.assertNotNull(composite2_entry3);
+ composite2_entry4 = composite2.getConnectionPoint("entry4");
+ Assert.assertNotNull(composite2_entry4);
+
+ t1 = composite1_exit1.getOutgoing("t1");
+ assertNotNull(t1);
+ t2 = composite1_exit2.getOutgoing("t2");
+ assertNotNull(t2);
+ t3 = composite1_exit3.getOutgoing("t3");
+ assertNotNull(t3);
+ t4 = composite1_exit4.getOutgoing("t4");
+ assertNotNull(t4);
+
+ t5 = compositeStateRegion.getTransition("t5");
+ assertNotNull(t5);
}
+
+ /**
+ * Deletes the element in the given owner element, undo and redo the action.
+ *
+ * @param elementToDestroy
+ * the element to delete
+ * @param canCreate
+ * <code>true</code> if new element can be created in the
+ * specified owner
+ */
+ protected Command getDeleteChildCommand(EObject elementToDestroy, boolean confirmationRequired) throws Exception {
+ GetEditContextRequest editContextRequest = new GetEditContextRequest(transactionalEditingDomain, new DestroyElementRequest(transactionalEditingDomain, elementToDestroy, confirmationRequired), elementToDestroy);
+
+ editContextRequest.setParameter(IRequestCacheEntries.Cache_Maps, new HashMap<>());
+ editContextRequest.setEditContext(elementToDestroy);
+ try {
+ editContextRequest.setClientContext(TypeContext.getContext());
+ } catch (ServiceException e) {
+ Assert.fail(e.getMessage());
+ }
+
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(elementToDestroy);
+ if (provider == null) {
+ Assert.fail("Impossible to get the editing domain provider");
+ }
+
+ EObject target = elementToDestroy;
+ Object result = null;
+ final ICommand getEditContextCommand = provider.getEditCommand(editContextRequest);
+ if (getEditContextCommand != null) {
+ IStatus status = null;
+ try {
+ // this command could run in an unprotected transaction, it is not supposed to modify the model
+ InternalTransactionalEditingDomain domain = (InternalTransactionalEditingDomain) transactionalEditingDomain;
+ Map<String, Object> options = new HashMap<>();
+ options.put(Transaction.OPTION_NO_NOTIFICATIONS, true);
+ options.put(Transaction.OPTION_NO_VALIDATION, true);
+ options.put(Transaction.OPTION_NO_TRIGGERS, true);
+ Transaction transaction = domain.startTransaction(false, options);
+ try {
+ status = getEditContextCommand.execute(null, null);
+ } finally {
+ transaction.commit();
+ }
+ } catch (InterruptedException e) {
+ Assert.fail(e.getMessage());
+ } catch (ExecutionException e) {
+ Assert.fail(e.getMessage());
+ } catch (RollbackException e) {
+ Assert.fail(e.getMessage());
+ }
+ if (!(status == null || !status.isOK())) {
+ result = getEditContextCommand.getCommandResult().getReturnValue();
+ }
+ if (result instanceof EObject) {
+ target = (EObject) result;
+ }
+ }
+
+ provider = ElementEditServiceUtils.getCommandProvider(target);
+ if (provider == null) {
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ ICommand deleteGMFCommand = provider.getEditCommand(new DestroyElementRequest(transactionalEditingDomain, target, confirmationRequired));
+ assertNotNull("Command should not be null", deleteGMFCommand);
+ assertTrue("Command should be executable", deleteGMFCommand.canExecute());
+ // command is executable, and it was expected to => run the creation
+ Command emfCommand = new org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper(deleteGMFCommand);
+ return emfCommand;
+ }
+
}
diff --git a/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/deletion/DeleteElementTest.java b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/deletion/DeleteElementTest.java
index 3c50bd3c9..d4e69a2f3 100644
--- a/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/deletion/DeleteElementTest.java
+++ b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/deletion/DeleteElementTest.java
@@ -16,28 +16,11 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.command.UnexecutableCommand;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.RollbackException;
-import org.eclipse.emf.transaction.Transaction;
-import org.eclipse.emf.transaction.impl.InternalTransactionalEditingDomain;
-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.commands.CreateElementCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.GetEditContextRequest;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.services.edit.internal.context.TypeContext;
-import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
-import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
-import org.eclipse.papyrus.infra.services.edit.utils.IRequestCacheEntries;
import org.eclipse.papyrusrt.umlrt.core.tests.AbstractPapyrusRTCoreTest;
import org.eclipse.papyrusrt.umlrt.core.tests.utils.IDeleteValidationRule;
import org.eclipse.papyrusrt.umlrt.core.types.UMLRTElementTypesEnumerator;
@@ -75,7 +58,7 @@ public class DeleteElementTest extends AbstractPapyrusRTCoreTest {
Command commandDelete = getDeleteChildCommand(deletedElement, false);
if (commandDelete != null && commandDelete.canExecute()) {
transactionalEditingDomain.getCommandStack().execute(commandDelete);
-
+
IDeleteValidationRule validationRule = validationClass.newInstance();
Object[] commandResults = commandDelete.getResult().toArray();
// the element should not be in the model
@@ -125,75 +108,4 @@ public class DeleteElementTest extends AbstractPapyrusRTCoreTest {
return command;
}
- /**
- * Deletes the element in the given owner element, undo and redo the action
- *
- * @param elementToDestroy
- * the element to delete
- * @param canCreate
- * <code>true</code> if new element can be created in the
- * specified owner
- */
- protected Command getDeleteChildCommand(EObject elementToDestroy, boolean confirmationRequired) throws Exception {
- GetEditContextRequest editContextRequest = new GetEditContextRequest(transactionalEditingDomain, new DestroyElementRequest(transactionalEditingDomain, elementToDestroy, confirmationRequired), elementToDestroy);
-
- editContextRequest.setParameter(IRequestCacheEntries.Cache_Maps, new HashMap<Object, Object>());
- editContextRequest.setEditContext(elementToDestroy);
- try {
- editContextRequest.setClientContext(TypeContext.getContext());
- } catch (ServiceException e) {
- Assert.fail(e.getMessage());
- }
-
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(elementToDestroy);
- if (provider == null) {
- Assert.fail("Impossible to get the editing domain provider");
- }
-
- EObject target = elementToDestroy;
- Object result = null;
- final ICommand getEditContextCommand = provider.getEditCommand(editContextRequest);
- if (getEditContextCommand != null) {
- IStatus status = null;
- try {
- // this command could run in an unprotected transaction, it is not supposed to modify the model
- InternalTransactionalEditingDomain domain = (InternalTransactionalEditingDomain) transactionalEditingDomain;
- Map<String, Object> options = new HashMap<String, Object>();
- options.put(Transaction.OPTION_NO_NOTIFICATIONS, true);
- options.put(Transaction.OPTION_NO_VALIDATION, true);
- options.put(Transaction.OPTION_NO_TRIGGERS, true);
- Transaction transaction = domain.startTransaction(false, options);
- try {
- status = getEditContextCommand.execute(null, null);
- } finally {
- transaction.commit();
- }
- } catch (InterruptedException e) {
- Assert.fail(e.getMessage());
- } catch (ExecutionException e) {
- Assert.fail(e.getMessage());
- } catch (RollbackException e) {
- Assert.fail(e.getMessage());
- }
- if (!(status == null || !status.isOK())) {
- result = getEditContextCommand.getCommandResult().getReturnValue();
- }
- if (result instanceof EObject) {
- target = (EObject) result;
- }
- }
-
- provider = ElementEditServiceUtils.getCommandProvider(target);
- if (provider == null) {
- return UnexecutableCommand.INSTANCE;
- }
-
- ICommand deleteGMFCommand = provider.getEditCommand(new DestroyElementRequest(transactionalEditingDomain, target, confirmationRequired));
- assertNotNull("Command should not be null", deleteGMFCommand);
- assertTrue("Command should be executable", deleteGMFCommand.canExecute());
- // command is executable, and it was expected to => run the creation
- Command emfCommand = new org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper(deleteGMFCommand);
- return emfCommand;
- }
-
}
diff --git a/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/deletion/DeleteTransitionsTest.java b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/deletion/DeleteTransitionsTest.java
new file mode 100644
index 000000000..ef93bd2fb
--- /dev/null
+++ b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/deletion/DeleteTransitionsTest.java
@@ -0,0 +1,237 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrusrt.umlrt.core.tests.deletion;
+
+import static org.eclipse.papyrus.junit.matchers.MoreMatchers.isEmpty;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.papyrusrt.umlrt.core.tests.AbstractPapyrusRTCoreTest;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Pseudostate;
+import org.eclipse.uml2.uml.PseudostateKind;
+import org.eclipse.uml2.uml.Region;
+import org.eclipse.uml2.uml.State;
+import org.eclipse.uml2.uml.Transition;
+import org.eclipse.uml2.uml.Vertex;
+import org.junit.Test;
+
+/**
+ * Test class for deletion of transitions. It mainly checks the deletion of entry/exit ends if the they become useless.
+ */
+public class DeleteTransitionsTest extends AbstractPapyrusRTCoreTest {
+
+ /**
+ * Constructor.
+ */
+ public DeleteTransitionsTest() {
+ super();
+ }
+
+ @Test
+ public void deleteTransitionWithPseudostates_bothEmpty() throws Exception {
+ deleteTransition(t1);
+ }
+
+ @Test
+ public void deleteTransitionWithPseudostates_targetEmpty() throws Exception {
+ deleteTransition(t2);
+ }
+
+
+ @Test
+ public void deleteTransitionWithPseudostates_sourceEmpty() throws Exception {
+ deleteTransition(t3);
+ }
+
+
+ @Test
+ public void deleteTransitionWithPseudostates_noneEmpty() throws Exception {
+ deleteTransition(t4);
+ }
+
+
+ @Test
+ public void deleteTransitionWithStates() throws Exception {
+ deleteTransition(t5);
+ }
+
+ /**
+ * @param t1
+ * @throws Exception
+ */
+ protected void deleteTransition(Transition deletedElement) throws Exception {
+ Command commandDelete = getDeleteChildCommand(deletedElement, false);
+ if (commandDelete != null && commandDelete.canExecute()) {
+ DeleteTransitionValidationRules validationRule = new DeleteTransitionValidationRules(deletedElement);
+ transactionalEditingDomain.getCommandStack().execute(commandDelete);
+
+ // the element should not be in the model
+ validationRule.validatePostEdition();
+
+ // undo the delete command
+ transactionalEditingDomain.getCommandStack().undo();
+ // the element should be in the model
+ validationRule.validatePostUndo();
+
+ // redo the delete command
+ transactionalEditingDomain.getCommandStack().redo();
+ // the element should not be in the model
+ validationRule.validatePostEdition();
+
+ // undo the delete command
+ transactionalEditingDomain.getCommandStack().undo();
+ // the element should be in the model
+ validationRule.validatePostUndo();
+
+ } else {
+ fail("Delete Command should be executable");
+ }
+ }
+
+ /**
+ *
+ */
+ private static boolean shouldDelete(Element end, Transition transition) {
+ if (!(end instanceof Pseudostate)) {
+ return false;
+ }
+
+ PseudostateKind kind = ((Pseudostate) end).getKind();
+ if (!(kind.equals(PseudostateKind.ENTRY_POINT_LITERAL) || kind.equals(PseudostateKind.EXIT_POINT_LITERAL))) {
+ return false;
+ }
+ // check there are no other transition outgoing or incoming except transition to delete
+ if (((Pseudostate) end).getOutgoings().stream().filter(t -> !t.equals(transition)).findAny().isPresent()) {
+ return false;
+ }
+ if (((Pseudostate) end).getIncomings().stream().filter(t -> !t.equals(transition)).findAny().isPresent()) {
+ return false;
+ }
+ return true;
+ }
+
+ //
+ // inner types
+ //
+
+ protected static class DeleteTransitionValidationRules {
+
+ private Transition transition;
+ private Vertex source;
+ private boolean shouldDeleteSource;
+ private Vertex target;
+ private boolean shouldDeleteTarget;
+ private ArrayList<Transition> sourceOutgoings;
+ private ArrayList<Transition> sourceIncomings;
+ private ArrayList<Transition> targetOutgoings;
+ private ArrayList<Transition> targetIncomings;
+ private Region region;
+ private Element originalSourceOwner;
+ private Element originalTargetOwner;
+
+ /**
+ * Constructor.
+ *
+ * @param deletedElement
+ * @throws Exception
+ */
+ public DeleteTransitionValidationRules(Transition deletedElement) throws Exception {
+ this.transition = deletedElement;
+ this.region = transition.getContainer();
+ this.source = transition.getSource();
+ this.originalSourceOwner = getOwner(source);
+ this.sourceOutgoings = new ArrayList<>(source.getOutgoings());
+ this.sourceIncomings = new ArrayList<>(source.getIncomings());
+ this.shouldDeleteSource = shouldDelete(source, deletedElement);
+
+ this.target = transition.getTarget();
+ this.originalTargetOwner = getOwner(target);
+ this.targetOutgoings = new ArrayList<>(target.getOutgoings());
+ this.targetIncomings = new ArrayList<>(target.getIncomings());
+ this.shouldDeleteTarget = shouldDelete(target, deletedElement);
+
+ }
+
+ public void validatePostEdition() throws Exception {
+ assertThat(transition.getContainer(), nullValue());
+ assertThat(transition.getSource(), nullValue());
+ assertThat(transition.getTarget(), nullValue());
+
+ if (shouldDeleteSource) {
+ assertThat(source.getOwner(), nullValue());
+ assertThat(source.getIncomings(), isEmpty());
+ assertThat(source.getOutgoings(), isEmpty());
+ } else {
+ // ensure the target is unchanged, expect for the deleted transition
+ List<Transition> expectedOutgoings = new ArrayList<>(sourceOutgoings);
+ expectedOutgoings.remove(transition);
+ assertThat(source.getOutgoings(), equalTo(expectedOutgoings));
+ List<Transition> expectedIncomings = new ArrayList<>(sourceIncomings);
+ expectedIncomings.remove(transition);
+ assertThat(source.getIncomings(), equalTo(expectedIncomings));
+ }
+
+ if (shouldDeleteTarget) {
+ assertThat(target.getOwner(), nullValue());
+ assertThat(target.getIncomings(), isEmpty());
+ assertThat(target.getOutgoings(), isEmpty());
+ } else {
+ // ensure the target is unchanged, expect for the deleted transition
+ List<Transition> expectedOutgoings = new ArrayList<>(targetOutgoings);
+ expectedOutgoings.remove(transition);
+ assertThat(target.getOutgoings(), equalTo(expectedOutgoings));
+ List<Transition> expectedIncomings = new ArrayList<>(targetIncomings);
+ expectedIncomings.remove(transition);
+ assertThat(target.getIncomings(), equalTo(expectedIncomings));
+ }
+ }
+
+ public void validatePostUndo() throws Exception {
+ assertThat(transition.getContainer(), equalTo(region));
+ assertThat(transition.getSource(), equalTo(source));
+ assertThat(transition.getTarget(), equalTo(target));
+
+ // check initial values
+ assertThat(source.getOwner(), equalTo(originalSourceOwner));
+ assertThat(source.getIncomings(), equalTo(sourceIncomings));
+ assertThat(source.getOutgoings(), equalTo(sourceOutgoings));
+
+ assertThat(target.getOwner(), equalTo(originalTargetOwner));
+ assertThat(target.getIncomings(), equalTo(targetIncomings));
+ assertThat(target.getOutgoings(), equalTo(targetOutgoings));
+ }
+ }
+
+ /**
+ * @param source
+ * @return
+ * @throws Exception
+ */
+ protected static Element getOwner(Vertex source) throws Exception {
+ if (source instanceof State) {
+ return ((State) source).getContainer();
+ }
+ if (source instanceof Pseudostate) {
+ return ((Pseudostate) source).getState() != null ? ((Pseudostate) source).getState() : ((Pseudostate) source).getContainer();
+ }
+ throw new Exception("unexpected");
+ }
+}

Back to the top