Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael LANOE2015-03-30 08:35:28 +0000
committerMickael LANOE2015-04-16 09:25:03 +0000
commit7be50252db5445844767c62dc1a9899732a2c787 (patch)
treea0f625af574c89ff99109b7ea6cf0165df4e5e88
parent3db1ce03cd218f5ea76254de259a147309fb72e4 (diff)
downloadorg.eclipse.sirius-7be50252db5445844767c62dc1a9899732a2c787.tar.gz
org.eclipse.sirius-7be50252db5445844767c62dc1a9899732a2c787.tar.xz
org.eclipse.sirius-7be50252db5445844767c62dc1a9899732a2c787.zip
[458822] Add test BuildDeleteCommandTest
Add BuildDeleteCommandTest to ensure that there is no access to unwanted semantic elements during the creation of a delete command. This test use the component meta-model that logs all accesses to unwanted components. Bug: 458822 Change-Id: I83e913339ce215784cd15be4bcc4bdbf8ad9d351 Signed-off-by: Mickael LANOE <mickael.lanoe@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/data/unit/payload/component.component12
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/data/unit/payload/representations.aird55
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/diagram/AllDiagramPluginsTests.java2
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/command/BuildDeleteCommandTest.java149
5 files changed, 220 insertions, 1 deletions
diff --git a/plugins/org.eclipse.sirius.tests.junit/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.tests.junit/META-INF/MANIFEST.MF
index fa9b1e15c5..b2db29d5b6 100644
--- a/plugins/org.eclipse.sirius.tests.junit/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.sirius.tests.junit/META-INF/MANIFEST.MF
@@ -65,7 +65,8 @@ Require-Bundle: org.eclipse.sirius.tests.sample.benchmark,
org.eclipse.sdk,
org.eclipse.platform,
org.eclipse.sirius.tests.sample.component,
- org.eclipse.sirius.tests.sample.scxml
+ org.eclipse.sirius.tests.sample.scxml,
+ org.eclipse.sirius.tests.sample.component.design
Bundle-Activator: org.eclipse.sirius.tests.SiriusTestsPlugin
Eclipse-LazyStart: true
Bundle-Localization: plugin
diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/payload/component.component b/plugins/org.eclipse.sirius.tests.junit/data/unit/payload/component.component
new file mode 100644
index 0000000000..a6de647242
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/payload/component.component
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="ASCII"?>
+<component:Component xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:component="http://www.eclipse.org/sirius/sample/component" name="c">
+ <children name="c.1">
+ <children name="c.1.1">
+ <children name="c.1.1.1" payload="true">
+ <children name="c.1.1.1.1" payload="true">
+ <children name="c.1.1.1.1.1" payload="true"/>
+ </children>
+ </children>
+ </children>
+ </children>
+</component:Component>
diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/payload/representations.aird b/plugins/org.eclipse.sirius.tests.junit/data/unit/payload/representations.aird
new file mode 100644
index 0000000000..90ea609b20
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/payload/representations.aird
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<viewpoint:DAnalysis xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:component="http://www.eclipse.org/sirius/sample/component" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/diagram/description/1.1.0" xmlns:diagram="http://www.eclipse.org/sirius/diagram/1.1.0" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:style="http://www.eclipse.org/sirius/diagram/description/style/1.1.0" xmlns:viewpoint="http://www.eclipse.org/sirius/1.1.0" xsi:schemaLocation="http://www.eclipse.org/sirius/description/1.1.0 http://www.eclipse.org/sirius/1.1.0#//description http://www.eclipse.org/sirius/diagram/description/1.1.0 http://www.eclipse.org/sirius/diagram/1.1.0#//description http://www.eclipse.org/sirius/diagram/description/style/1.1.0 http://www.eclipse.org/sirius/diagram/1.1.0#//description/style" xmi:id="_fAtUsNOWEeSuFoVE4TCOJg" selectedViews="_CSfnUNOXEeSLVtmbtn12LQ" version="10.0.10.201502231700">
+ <models xmi:type="component:Component" href="component.component#/"/>
+ <ownedViews xmi:type="viewpoint:DRepresentationContainer" xmi:id="_CSfnUNOXEeSLVtmbtn12LQ" initialized="true">
+ <ownedRepresentations xmi:type="diagram:DSemanticDiagram" xmi:id="_EDuUYNOXEeSLVtmbtn12LQ" name="new Diagram">
+ <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_EDu7cNOXEeSLVtmbtn12LQ" source="DANNOTATION_CUSTOMIZATION_KEY">
+ <data xmi:type="diagram:ComputedStyleDescriptionRegistry" xmi:id="_EDu7cdOXEeSLVtmbtn12LQ"/>
+ </ownedAnnotationEntries>
+ <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_EEIkENOXEeSLVtmbtn12LQ" source="GMF_DIAGRAMS">
+ <data xmi:type="notation:Diagram" xmi:id="_EEIkEdOXEeSLVtmbtn12LQ" type="Sirius" element="_EDuUYNOXEeSLVtmbtn12LQ" measurementUnit="Pixel">
+ <children xmi:type="notation:Node" xmi:id="_GRS_MNOXEeSLVtmbtn12LQ" type="2002" element="_GQXyINOXEeSLVtmbtn12LQ">
+ <children xmi:type="notation:Node" xmi:id="_GRVbcNOXEeSLVtmbtn12LQ" type="5006"/>
+ <children xmi:type="notation:Node" xmi:id="_GRWpkNOXEeSLVtmbtn12LQ" type="7001">
+ <children xmi:type="notation:Node" xmi:id="_GszPcNOXEeSLVtmbtn12LQ" type="3008" element="_GsRrANOXEeSLVtmbtn12LQ">
+ <children xmi:type="notation:Node" xmi:id="_Gsz2gNOXEeSLVtmbtn12LQ" type="5005"/>
+ <children xmi:type="notation:Node" xmi:id="_Gs1EoNOXEeSLVtmbtn12LQ" type="7002">
+ <styles xmi:type="notation:SortingStyle" xmi:id="_Gs1EodOXEeSLVtmbtn12LQ"/>
+ <styles xmi:type="notation:FilteringStyle" xmi:id="_Gs1EotOXEeSLVtmbtn12LQ"/>
+ </children>
+ <styles xmi:type="notation:ShapeStyle" xmi:id="_GszPcdOXEeSLVtmbtn12LQ" fontName="Cantarell" fontHeight="8"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_GszPctOXEeSLVtmbtn12LQ" x="43" y="30"/>
+ </children>
+ <styles xmi:type="notation:SortingStyle" xmi:id="_GRWpkdOXEeSLVtmbtn12LQ"/>
+ <styles xmi:type="notation:FilteringStyle" xmi:id="_GRWpktOXEeSLVtmbtn12LQ"/>
+ </children>
+ <styles xmi:type="notation:ShapeStyle" xmi:id="_GRS_MdOXEeSLVtmbtn12LQ" fontName="Cantarell" fontHeight="8"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_GRS_MtOXEeSLVtmbtn12LQ" x="168" y="72"/>
+ </children>
+ <styles xmi:type="notation:DiagramStyle" xmi:id="_EEIkEtOXEeSLVtmbtn12LQ"/>
+ </data>
+ </ownedAnnotationEntries>
+ <ownedDiagramElements xmi:type="diagram:DNodeContainer" xmi:id="_GQXyINOXEeSLVtmbtn12LQ" name="c.1">
+ <target xmi:type="component:Component" href="component.component#//@children.0"/>
+ <semanticElements xmi:type="component:Component" href="component.component#//@children.0"/>
+ <ownedStyle xmi:type="diagram:FlatContainerStyle" xmi:id="_GQnpwNOXEeSLVtmbtn12LQ">
+ <description xmi:type="style:FlatContainerStyleDescription" href="platform:/plugin/org.eclipse.sirius.tests.sample.component.design/description/component.odesign#//@ownedViewpoints[name='Component']/@ownedRepresentations[name='Diagram']/@defaultLayer/@containerMappings[name='Component']/@style"/>
+ </ownedStyle>
+ <actualMapping xmi:type="description_1:ContainerMapping" href="platform:/plugin/org.eclipse.sirius.tests.sample.component.design/description/component.odesign#//@ownedViewpoints[name='Component']/@ownedRepresentations[name='Diagram']/@defaultLayer/@containerMappings[name='Component']"/>
+ <ownedDiagramElements xmi:type="diagram:DNodeContainer" xmi:id="_GsRrANOXEeSLVtmbtn12LQ" name="c.1.1">
+ <target xmi:type="component:Component" href="component.component#//@children.0/@children.0"/>
+ <semanticElements xmi:type="component:Component" href="component.component#//@children.0/@children.0"/>
+ <ownedStyle xmi:type="diagram:FlatContainerStyle" xmi:id="_JZwk8NOXEeSLVtmbtn12LQ" borderColor="239,41,41">
+ <description xmi:type="style:FlatContainerStyleDescription" href="platform:/plugin/org.eclipse.sirius.tests.sample.component.design/description/component.odesign#//@ownedViewpoints[name='Component']/@ownedRepresentations[name='Diagram']/@defaultLayer/@containerMappings[name='Component']/@conditionnalStyles.0/@style"/>
+ </ownedStyle>
+ <actualMapping xmi:type="description_1:ContainerMapping" href="platform:/plugin/org.eclipse.sirius.tests.sample.component.design/description/component.odesign#//@ownedViewpoints[name='Component']/@ownedRepresentations[name='Diagram']/@defaultLayer/@containerMappings[name='Component']"/>
+ </ownedDiagramElements>
+ </ownedDiagramElements>
+ <description xmi:type="description_1:DiagramDescription" href="platform:/plugin/org.eclipse.sirius.tests.sample.component.design/description/component.odesign#//@ownedViewpoints[name='Component']/@ownedRepresentations[name='Diagram']"/>
+ <filterVariableHistory xmi:type="diagram:FilterVariableHistory" xmi:id="_EDu7ctOXEeSLVtmbtn12LQ"/>
+ <activatedLayers xmi:type="description_1:Layer" href="platform:/plugin/org.eclipse.sirius.tests.sample.component.design/description/component.odesign#//@ownedViewpoints[name='Component']/@ownedRepresentations[name='Diagram']/@defaultLayer"/>
+ <target xmi:type="component:Component" href="component.component#/"/>
+ </ownedRepresentations>
+ <viewpoint xmi:type="description:Viewpoint" href="platform:/plugin/org.eclipse.sirius.tests.sample.component.design/description/component.odesign#//@ownedViewpoints[name='Component']"/>
+ </ownedViews>
+</viewpoint:DAnalysis>
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/diagram/AllDiagramPluginsTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/diagram/AllDiagramPluginsTests.java
index 3156ad8fa7..cb427abb01 100644
--- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/diagram/AllDiagramPluginsTests.java
+++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/diagram/AllDiagramPluginsTests.java
@@ -89,6 +89,7 @@ import org.eclipse.sirius.tests.unit.diagram.action.DeleteWithoutToolFromModelAc
import org.eclipse.sirius.tests.unit.diagram.action.EdgeOnEdgeHideRevealTest;
import org.eclipse.sirius.tests.unit.diagram.action.EntitiesDiagramHideRevealTests;
import org.eclipse.sirius.tests.unit.diagram.action.LabelHideRevealTests;
+import org.eclipse.sirius.tests.unit.diagram.command.BuildDeleteCommandTest;
import org.eclipse.sirius.tests.unit.diagram.command.DeleteViewCommandTest;
import org.eclipse.sirius.tests.unit.diagram.compute.variable.ComputeAvailableVariableLabelTest;
import org.eclipse.sirius.tests.unit.diagram.control.ControlDetectorTest;
@@ -337,6 +338,7 @@ public class AllDiagramPluginsTests {
suite.addTestSuite(DiagramUnsynchronizedRefreshTest.class);
suite.addTestSuite(UnsynchronizedMappingAndDeleteFromOutsideEditorTests.class);
suite.addTestSuite(DeleteViewCommandTest.class);
+ suite.addTestSuite(BuildDeleteCommandTest.class);
suite.addTestSuite(FileModificationValidationTest.class);
suite.addTestSuite(GMFCrossReferenceAdapterTest.class);
suite.addTestSuite(EdgeStabilityOnPortCollapsingTest.class);
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/command/BuildDeleteCommandTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/command/BuildDeleteCommandTest.java
new file mode 100644
index 0000000000..ea2e463be5
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/command/BuildDeleteCommandTest.java
@@ -0,0 +1,149 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.sirius.tests.unit.diagram.command;
+
+import org.eclipse.sirius.diagram.DDiagram;
+import org.eclipse.sirius.diagram.DNodeContainer;
+import org.eclipse.sirius.ecore.extender.business.api.accessor.ExtenderConstants;
+import org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority;
+import org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionProvider;
+import org.eclipse.sirius.ecore.extender.business.internal.permission.DefaultPermissionProvider;
+import org.eclipse.sirius.ecore.extender.business.internal.permission.PermissionService;
+import org.eclipse.sirius.ecore.extender.business.internal.permission.ReadOnlyPermissionAuthority;
+import org.eclipse.sirius.ecore.extender.business.internal.permission.descriptors.StandalonePermissionProviderDescriptor;
+import org.eclipse.sirius.tests.SiriusTestsPlugin;
+import org.eclipse.sirius.tests.sample.component.Component;
+import org.eclipse.sirius.tests.sample.component.util.PayloadMarkerAdapter;
+import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+/**
+ * Ensure that there is no unwanted access on some semantic element during the
+ * construction of the delete command.
+ *
+ * This test uses the component meta-model that logs all accesses to unwanted
+ * components.
+ *
+ * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=458822
+ *
+ * @author <a href="mailto:mickael.lanoe@obeo.fr">Mickael LANOE</a>
+ */
+public class BuildDeleteCommandTest extends SiriusDiagramTestCase {
+ private static final String MODELER_PATH = "/org.eclipse.sirius.tests.sample.component.design/description/component.odesign";//$NON-NLS-1$
+
+ private static final String PATH = "/data/unit/payload/";//$NON-NLS-1$
+
+ private static final String SEMANTIC_MODEL_PATH = "component.component";//$NON-NLS-1$
+
+ private static final String SESSION_MODEL_PATH = "representations.aird";//$NON-NLS-1$
+
+ private DDiagram componentDiagram;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ initCustomPermissionAuthority();
+
+ copyFilesToTestProject(SiriusTestsPlugin.PLUGIN_ID, PATH, SEMANTIC_MODEL_PATH, SESSION_MODEL_PATH);
+ genericSetUp(TEMPORARY_PROJECT_NAME + "/" + SEMANTIC_MODEL_PATH, MODELER_PATH, TEMPORARY_PROJECT_NAME + "/" + SESSION_MODEL_PATH);
+
+ componentDiagram = (DDiagram) getRepresentations("Diagram").iterator().next();
+ assertNotNull("Couldn't find the component diagram.", componentDiagram);
+ }
+
+ /**
+ * Test IDiagramCommandFactory.buildDeleteDiagramElement(DDiagramElement)
+ */
+ public void testBuildDeleteCommandElement() {
+ DNodeContainer container = getComponentDNodeContainer("c.1");
+
+ clearPayloadAccessLog();
+ getCommandFactory().buildDeleteDiagramElement(container);
+ assertNoPayloadAccessLog();
+ }
+
+ /**
+ * Test
+ * IDiagramCommandFactory.buildDeleteFromDiagramCommand(DDiagramElement)
+ */
+ public void testBuildDeleteFromDiagramCommand() {
+ DNodeContainer container = getComponentDNodeContainer("c.1");
+
+ clearPayloadAccessLog();
+ getCommandFactory().buildDeleteFromDiagramCommand(container);
+ assertNoPayloadAccessLog();
+ }
+
+ /**
+ * Test IDiagramCommandFactory.buildDeleteDiagram(DDiagram)
+ */
+ public void testBuildDeleteDiagram() {
+ clearPayloadAccessLog();
+ getCommandFactory().buildDeleteDiagram(componentDiagram);
+ assertNoPayloadAccessLog();
+ }
+
+ /**
+ * Clear all access logs to unwanted semantic elements registered during the
+ * test initialization.
+ */
+ private void clearPayloadAccessLog() {
+ PayloadMarkerAdapter.INSTANCE.clearAccessLog();
+ }
+
+ /**
+ * Ensure that there is no access to unwanted semantic elements.
+ */
+ private void assertNoPayloadAccessLog() {
+ assertTrue("No access for payload should be registered", PayloadMarkerAdapter.INSTANCE.getAccessLog().isEmpty());
+ }
+
+ /**
+ * Get the {@link DNodeContainer} for one component.
+ *
+ * @param componentName
+ * component name
+ * @return the container
+ */
+ private DNodeContainer getComponentDNodeContainer(final String componentName) {
+ Iterable<DNodeContainer> containers = Iterables.filter(componentDiagram.getDiagramElements(), DNodeContainer.class);
+ DNodeContainer container = Iterables.find(containers, new Predicate<DNodeContainer>() {
+ @Override
+ public boolean apply(DNodeContainer element) {
+ if (element.getTarget() instanceof Component) {
+ Component component = (Component) element.getTarget();
+ if (componentName.equals(component.getName())) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ });
+
+ assertNotNull("The DNodeContainer for the component " + componentName + " should exist", container);
+ return container;
+ }
+
+ /**
+ * Init Sirius with a {@link ReadOnlyPermissionAuthority}.
+ */
+ private void initCustomPermissionAuthority() {
+ IPermissionAuthority permissionAuthority = PermissionService.createDefaultPermissionAuthority();
+ IPermissionProvider permissionProvider = new DefaultPermissionProvider(permissionAuthority);
+ StandalonePermissionProviderDescriptor permissionProviderDescriptor = new StandalonePermissionProviderDescriptor("org.eclipse.sirius.tree.tests.forbiddenPermissionAuthorityProvider",
+ ExtenderConstants.HIGHEST_PRIORITY, permissionProvider);
+ PermissionService.addExtension(permissionProviderDescriptor);
+ }
+
+}

Back to the top