diff options
author | Christian W. Damus | 2016-04-01 14:57:42 +0000 |
---|---|---|
committer | Christian W. Damus | 2016-04-01 14:57:42 +0000 |
commit | d67195b5c708216c263eab9aafa8589ba8ce3f68 (patch) | |
tree | 3f07e160db8d025263f09bdad1077a4c48270601 | |
parent | bf7e3ae037515696ecc085738da4d58aafa4b64b (diff) | |
download | org.eclipse.papyrus-d67195b5c708216c263eab9aafa8589ba8ce3f68.tar.gz org.eclipse.papyrus-d67195b5c708216c263eab9aafa8589ba8ce3f68.tar.xz org.eclipse.papyrus-d67195b5c708216c263eab9aafa8589ba8ce3f68.zip |
Bug 468207: [StateMachine Diagram] cannot delete elements
https://bugs.eclipse.org/bugs/show_bug.cgi?id=468207
When a state machine has only one region, that region's zone annotation
is the empty string. When that region has a stereotype applied (as
it does in Papyrus-RT real-time state machines), then the region has
a stereotype-comment compartment. In that case, deletion of the
region view fails with a SIOOBE on attempt to take a substring of the
empty zone annotation value.
9 files changed, 205 insertions, 19 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/helpers/Zone.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/helpers/Zone.java index 1f17b3f2227..4e5b8d737ef 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/helpers/Zone.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/helpers/Zone.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2014 CEA LIST. + * Copyright (c) 2014, 2016 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 @@ -8,6 +8,7 @@ * * Contributors: * CEA LIST - Initial API and implementation + * Christian W. Damus - bug 468207 */ package org.eclipse.papyrus.uml.diagram.statemachine.custom.helpers; @@ -28,6 +29,8 @@ import org.eclipse.papyrus.uml.diagram.statemachine.edit.parts.RegionEditPart; import org.eclipse.papyrus.uml.diagram.statemachine.edit.parts.StateMachineEditPart; import org.eclipse.papyrus.uml.diagram.statemachine.part.UMLVisualIDRegistry; +import com.google.common.base.Strings; + /** * Helper class used to manage the encoding of a region position within a state * machine or a state. @@ -567,18 +570,20 @@ public class Zone { * @return the counterpart zone */ private static String getZoneCounterpart(String s) { - String cs = s.substring(0, s.length() - 1); - if (Zone.isRight(s)) { - return Zone.setLeft(cs); - } - if (Zone.isLeft(s)) { - return Zone.setRight(cs); - } - if (Zone.isBottom(s)) { - return Zone.setTop(cs); - } - if (Zone.isTop(s)) { - return Zone.setBottom(cs); + if (!Strings.isNullOrEmpty(s)) { + String cs = s.substring(0, s.length() - 1); + if (Zone.isRight(s)) { + return Zone.setLeft(cs); + } + if (Zone.isLeft(s)) { + return Zone.setRight(cs); + } + if (Zone.isBottom(s)) { + return Zone.setTop(cs); + } + if (Zone.isTop(s)) { + return Zone.setBottom(cs); + } } return s; } @@ -806,7 +811,7 @@ public class Zone { // get the region zone String zone = getZone(region); // get its counterpart - if (zone == null) { + if (Strings.isNullOrEmpty(zone)) { return; } String cZone = getZoneCounterpart(zone); diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/META-INF/MANIFEST.MF index d4f6240dbb6..2f51a76fd63 100644 --- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/META-INF/MANIFEST.MF +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/META-INF/MANIFEST.MF @@ -20,9 +20,9 @@ Require-Bundle: org.eclipse.ui, org.eclipse.papyrus.infra.core.sasheditor;bundle-version="1.1.4",
org.junit;bundle-version="4.10.0",
org.eclipse.papyrus.junit.framework;bundle-version="1.1.4",
- org.eclipse.gmf.tooling.runtime;bundle-version="[3.3.0,
- 4.0.0)",
- org.eclipse.papyrus.junit.utils;bundle-version="1.1.4"
+ org.eclipse.gmf.tooling.runtime;bundle-version="[3.3.0,4.0.0)",
+ org.eclipse.papyrus.junit.utils;bundle-version="1.1.4",
+ org.eclipse.papyrus.infra.services.edit;bundle-version="1.1.4"
Bundle-ActivationPolicy: lazy
Bundle-ManifestVersion: 2
Bundle-Activator: org.eclipse.papyrus.uml.diagram.statemachine.tests.Activator
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/build.properties b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/build.properties index 1b08f841b5e..c672072f1a8 100644 --- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/build.properties +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/build.properties @@ -3,5 +3,6 @@ output.. = bin/ bin.includes = META-INF/,\
.,\
about.html,\
- plugin.properties
+ plugin.properties,\
+ resources/
src.includes = about.html
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/resources/bug468207/model.di b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/resources/bug468207/model.di new file mode 100644 index 00000000000..bf9abab340f --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/resources/bug468207/model.di @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"/> diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/resources/bug468207/model.notation b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/resources/bug468207/model.notation new file mode 100644 index 00000000000..e14e655d55b --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/resources/bug468207/model.notation @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8"?> +<notation:Diagram xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:style="http://www.eclipse.org/papyrus/infra/viewpoints/policy/style" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_e2dM8PgUEeW8Us5SRbfNZA" type="PapyrusUMLStateMachineDiagram" name="SmDiagram" measurementUnit="Pixel"> + <children xmi:type="notation:Shape" xmi:id="_e2dM8fgUEeW8Us5SRbfNZA" type="2000"> + <children xmi:type="notation:DecorationNode" xmi:id="_e2dM8vgUEeW8Us5SRbfNZA" type="2001"> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_e2dM8_gUEeW8Us5SRbfNZA" width="700" height="16"/> + </children> + <children xmi:type="notation:BasicCompartment" xmi:id="_e2dM9PgUEeW8Us5SRbfNZA" type="2002"> + <children xmi:type="notation:Shape" xmi:id="_e2dM9fgUEeW8Us5SRbfNZA" type="3000"> + <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_e2dM9vgUEeW8Us5SRbfNZA" source="RegionAnnotationKey"> + <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="_e2dM9_gUEeW8Us5SRbfNZA" key="RegionZoneKey" value=""/> + </eAnnotations> + <children xmi:type="notation:BasicCompartment" xmi:id="_e2dM-PgUEeW8Us5SRbfNZA" type="3002"> + <children xmi:type="notation:Shape" xmi:id="_uy1CsPgXEeW8Us5SRbfNZA" type="8000"> + <children xmi:type="notation:DecorationNode" xmi:id="_uy1CsvgXEeW8Us5SRbfNZA" type="8001"> + <layoutConstraint xmi:type="notation:Location" xmi:id="_uy1Cs_gXEeW8Us5SRbfNZA" x="25" y="3"/> + </children> + <children xmi:type="notation:DecorationNode" xmi:id="_uy1CtPgXEeW8Us5SRbfNZA" type="8002"> + <layoutConstraint xmi:type="notation:Location" xmi:id="_uy1CtfgXEeW8Us5SRbfNZA" x="25" y="-10"/> + </children> + <element xmi:type="uml:Pseudostate" href="model.uml#_uywKMPgXEeW8Us5SRbfNZA"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_uy1CsfgXEeW8Us5SRbfNZA" x="60" y="45"/> + </children> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_e2dM-fgUEeW8Us5SRbfNZA"/> + </children> + <element xmi:type="uml:Region" href="model.uml#_e2cl4PgUEeW8Us5SRbfNZA"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_e2dM-vgUEeW8Us5SRbfNZA" width="700" height="287"/> + </children> + <children xmi:type="notation:Shape" xmi:id="_uCACsPgXEeW8Us5SRbfNZA" type="StereotypeComment"> + <styles xmi:type="notation:TitleStyle" xmi:id="_uCACsfgXEeW8Us5SRbfNZA" showTitle="true"/> + <styles xmi:type="notation:EObjectValueStyle" xmi:id="_uCACs_gXEeW8Us5SRbfNZA" name="BASE_ELEMENT"> + <eObjectValue xmi:type="uml:Region" href="model.uml#_e2cl4PgUEeW8Us5SRbfNZA"/> + </styles> + <element xsi:nil="true"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_uCACsvgXEeW8Us5SRbfNZA" x="200"/> + </children> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_e2dM-_gUEeW8Us5SRbfNZA" y="16" width="700" height="287"/> + </children> + <element xmi:type="uml:StateMachine" href="model.uml#_ejtQEPgUEeW8Us5SRbfNZA"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_e2dM_PgUEeW8Us5SRbfNZA" x="30" y="30" width="700" height="303"/> + </children> + <styles xmi:type="notation:StringValueStyle" xmi:id="_e2dM_fgUEeW8Us5SRbfNZA" name="diagram_compatibility_version" stringValue="1.1.0"/> + <styles xmi:type="notation:DiagramStyle" xmi:id="_e2dM_vgUEeW8Us5SRbfNZA"/> + <styles xmi:type="style:PapyrusViewStyle" xmi:id="_e2dM__gUEeW8Us5SRbfNZA"> + <owner xmi:type="uml:Class" href="model.uml#_djwO8PgUEeW8Us5SRbfNZA"/> + </styles> + <element xmi:type="uml:StateMachine" href="model.uml#_ejtQEPgUEeW8Us5SRbfNZA"/> + <edges xmi:type="notation:Connector" xmi:id="_uCACtPgXEeW8Us5SRbfNZA" type="StereotypeCommentLink" source="_e2dM9fgUEeW8Us5SRbfNZA" target="_uCACsPgXEeW8Us5SRbfNZA"> + <styles xmi:type="notation:FontStyle" xmi:id="_uCACtfgXEeW8Us5SRbfNZA"/> + <styles xmi:type="notation:EObjectValueStyle" xmi:id="_uCACufgXEeW8Us5SRbfNZA" name="BASE_ELEMENT"> + <eObjectValue xmi:type="uml:Region" href="model.uml#_e2cl4PgUEeW8Us5SRbfNZA"/> + </styles> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_uCACtvgXEeW8Us5SRbfNZA" points="[0, 0, 0, 0]$[0, 0, 0, 0]"/> + <sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_uCACt_gXEeW8Us5SRbfNZA"/> + <targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_uCACuPgXEeW8Us5SRbfNZA"/> + </edges> +</notation:Diagram> diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/resources/bug468207/model.uml b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/resources/bug468207/model.uml new file mode 100644 index 00000000000..86492b1ac59 --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/resources/bug468207/model.uml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xmi:XMI xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:states="http:///schemas/states/_pBeIEPgXEeW8Us5SRbfNZA/0" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xsi:schemaLocation="http:///schemas/states/_pBeIEPgXEeW8Us5SRbfNZA/0 states.profile.uml#_pBhLYfgXEeW8Us5SRbfNZA"> + <uml:Model xmi:id="_bgcTYPgUEeW8Us5SRbfNZA" name="model"> + <packagedElement xmi:type="uml:Class" xmi:id="_djwO8PgUEeW8Us5SRbfNZA" name="Class1" classifierBehavior="_ejtQEPgUEeW8Us5SRbfNZA"> + <ownedBehavior xmi:type="uml:StateMachine" xmi:id="_ejtQEPgUEeW8Us5SRbfNZA" name="StateMachine1"> + <region xmi:type="uml:Region" xmi:id="_e2cl4PgUEeW8Us5SRbfNZA" name="Region1"> + <subvertex xmi:type="uml:Pseudostate" xmi:id="_uywKMPgXEeW8Us5SRbfNZA" name="Initial1"/> + </region> + </ownedBehavior> + </packagedElement> + <profileApplication xmi:type="uml:ProfileApplication" xmi:id="_sQXtAPgXEeW8Us5SRbfNZA"> + <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_sQYUEfgXEeW8Us5SRbfNZA" source="PapyrusVersion"> + <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="_sQYUEvgXEeW8Us5SRbfNZA" key="Version" value="0.0.1"/> + <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="_sQYUE_gXEeW8Us5SRbfNZA" key="Comment" value=""/> + <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="_sQYUFPgXEeW8Us5SRbfNZA" key="Copyright" value=""/> + <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="_sQYUFfgXEeW8Us5SRbfNZA" key="Date" value="2016-04-01"/> + <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="_sQYUFvgXEeW8Us5SRbfNZA" key="Author" value=""/> + </eAnnotations> + <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_sQYUEPgXEeW8Us5SRbfNZA" source="http://www.eclipse.org/uml2/2.0.0/UML"> + <references xmi:type="ecore:EPackage" href="states.profile.uml#_pBhLYfgXEeW8Us5SRbfNZA"/> + </eAnnotations> + <appliedProfile xmi:type="uml:Profile" href="states.profile.uml#_f3edsPgXEeW8Us5SRbfNZA"/> + </profileApplication> + </uml:Model> + <states:S1 xmi:id="_uBtu0PgXEeW8Us5SRbfNZA" base_Region="_e2cl4PgUEeW8Us5SRbfNZA"/> +</xmi:XMI> diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/resources/bug468207/states.profile.uml b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/resources/bug468207/states.profile.uml new file mode 100644 index 00000000000..e669235e136 --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/resources/bug468207/states.profile.uml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<uml:Profile xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_f3edsPgXEeW8Us5SRbfNZA" name="states" metaclassReference="_lA5OkPgXEeW8Us5SRbfNZA"> + <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_pBhLYPgXEeW8Us5SRbfNZA" source="http://www.eclipse.org/uml2/2.0.0/UML"> + <contents xmi:type="ecore:EPackage" xmi:id="_pBhLYfgXEeW8Us5SRbfNZA" name="states" nsURI="http:///schemas/states/_pBeIEPgXEeW8Us5SRbfNZA/0" nsPrefix="states"> + <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_pBiZgfgXEeW8Us5SRbfNZA" source="PapyrusVersion"> + <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="_pBiZgvgXEeW8Us5SRbfNZA" key="Version" value="0.0.1"/> + <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="_pBiZg_gXEeW8Us5SRbfNZA" key="Comment" value=""/> + <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="_pBiZhPgXEeW8Us5SRbfNZA" key="Copyright" value=""/> + <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="_pBiZhfgXEeW8Us5SRbfNZA" key="Date" value="2016-04-01"/> + <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="_pBiZhvgXEeW8Us5SRbfNZA" key="Author" value=""/> + </eAnnotations> + <eClassifiers xmi:type="ecore:EClass" xmi:id="_pBhLYvgXEeW8Us5SRbfNZA" name="S1"> + <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_pBhLY_gXEeW8Us5SRbfNZA" source="http://www.eclipse.org/uml2/2.0.0/UML" references="_lsLAMPgXEeW8Us5SRbfNZA"/> + <eStructuralFeatures xmi:type="ecore:EReference" xmi:id="_pBhLZPgXEeW8Us5SRbfNZA" name="base_Region" ordered="false" lowerBound="1"> + <eType xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Region"/> + </eStructuralFeatures> + </eClassifiers> + </contents> + </eAnnotations> + <elementImport xmi:type="uml:ElementImport" xmi:id="_lA5OkPgXEeW8Us5SRbfNZA" alias="Region"> + <importedElement xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Region"/> + </elementImport> + <packagedElement xmi:type="uml:Stereotype" xmi:id="_lsLAMPgXEeW8Us5SRbfNZA" name="S1"> + <ownedAttribute xmi:type="uml:Property" xmi:id="_nPZGcPgXEeW8Us5SRbfNZA" name="base_Region" association="_nPWqMPgXEeW8Us5SRbfNZA"> + <type xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Region"/> + </ownedAttribute> + </packagedElement> + <packagedElement xmi:type="uml:Extension" xmi:id="_nPWqMPgXEeW8Us5SRbfNZA" name="E_S1_Region1" memberEnd="_nPYfYPgXEeW8Us5SRbfNZA _nPZGcPgXEeW8Us5SRbfNZA"> + <ownedEnd xmi:type="uml:ExtensionEnd" xmi:id="_nPYfYPgXEeW8Us5SRbfNZA" name="extension_S1" type="_lsLAMPgXEeW8Us5SRbfNZA" aggregation="composite" association="_nPWqMPgXEeW8Us5SRbfNZA"/> + </packagedElement> +</uml:Profile> diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/src/org/eclipse/papyrus/uml/diagram/statemachine/custom/helpers/tests/ZoneTest.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/src/org/eclipse/papyrus/uml/diagram/statemachine/custom/helpers/tests/ZoneTest.java new file mode 100644 index 00000000000..de974c094bc --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/src/org/eclipse/papyrus/uml/diagram/statemachine/custom/helpers/tests/ZoneTest.java @@ -0,0 +1,61 @@ +/***************************************************************************** + * Copyright (c) 2016 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: + * Christian W. Damus - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.diagram.statemachine.custom.helpers.tests; + +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; + +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; +import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest; +import org.eclipse.papyrus.junit.utils.rules.ActiveDiagram; +import org.eclipse.papyrus.junit.utils.rules.PapyrusEditorFixture; +import org.eclipse.papyrus.junit.utils.rules.PluginResource; +import org.eclipse.papyrus.uml.diagram.statemachine.custom.helpers.Zone; +import org.eclipse.uml2.uml.Behavior; +import org.eclipse.uml2.uml.BehavioredClassifier; +import org.junit.Rule; +import org.junit.Test; + +/** + * Regression tests for the {@link Zone} utility class. + */ +public class ZoneTest extends AbstractPapyrusTest { + @Rule + public final PapyrusEditorFixture editor = new PapyrusEditorFixture(); + + /** + * Verifies that no exception occurs to block the deletion of a diagram + * that has a region with an empty zone annotation, as occurs in + * Papyrus-RT real-time state machine diagrams. + */ + @Test + @PluginResource("resources/bug468207/model.di") + @ActiveDiagram("SmDiagram") + public void deleteDiagramWithEmptyZoneAnnotation_bug468207() { + Diagram smDiagram = editor.getActiveDiagram().getDiagramView(); + Behavior stateMachine = ((BehavioredClassifier) editor.getModel().getOwnedType("Class1")).getOwnedBehaviors().get(0); + + // Delete it, which deletes the diagram + DestroyElementRequest req = new DestroyElementRequest(editor.getEditingDomain(), stateMachine, false); + ICommand cmd = ElementEditServiceUtils.getCommandProvider(stateMachine.getContext()).getEditCommand(req); + editor.execute(cmd); + + // The diagram was successfully deleted + assertThat(smDiagram.eResource(), nullValue()); + } + +} diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/src/org/eclipse/papyrus/uml/diagram/statemachine/tests/AllTests.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/src/org/eclipse/papyrus/uml/diagram/statemachine/tests/AllTests.java index aa86ef762ce..705d1dd57dc 100644 --- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/src/org/eclipse/papyrus/uml/diagram/statemachine/tests/AllTests.java +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine.tests/src/org/eclipse/papyrus/uml/diagram/statemachine/tests/AllTests.java @@ -1,5 +1,5 @@ /*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
+ * Copyright (c) 2014, 2016 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
@@ -8,9 +8,11 @@ *
* Contributors:
* Patrick Tessier (CEA LIST) - Initial API and implementation
+ * Christian W. Damus - bug 468207
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.statemachine.tests;
+import org.eclipse.papyrus.uml.diagram.statemachine.custom.helpers.tests.ZoneTest;
import org.eclipse.papyrus.uml.diagram.statemachine.tests.canonical.AllCanonicalTests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@@ -25,6 +27,7 @@ import org.junit.runners.Suite.SuiteClasses; AllCanonicalTests.class,
// load
//LoadTests.class
+ZoneTest.class,
})
public class AllTests {
}
|