Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Charles David2016-03-25 14:56:20 +0000
committerPierre-Charles David2016-04-06 15:10:45 +0000
commit3866ea64849aa14b93bf89a875d3214436dbd415 (patch)
tree84dd060915725ff0ede300d372abef0582d9d32a
parent1ef19426604aef40f86f7ca96a9f0c614ffcdbc3 (diff)
downloadorg.eclipse.sirius-3866ea64849aa14b93bf89a875d3214436dbd415.tar.gz
org.eclipse.sirius-3866ea64849aa14b93bf89a875d3214436dbd415.tar.xz
org.eclipse.sirius-3866ea64849aa14b93bf89a875d3214436dbd415.zip
[484186] Validate that variables have a non-blank name
Bug: 484186 Change-Id: Iffb4905fc54dae2217cfc23bb055028298a95e65 Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/invalidVariableNameVSM.odesign64
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/vsm/VSMValidationTest.java35
-rw-r--r--plugins/org.eclipse.sirius/plugin.xml5
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/VSMElementNameValidConstraint.java8
4 files changed, 99 insertions, 13 deletions
diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/invalidVariableNameVSM.odesign b/plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/invalidVariableNameVSM.odesign
new file mode 100644
index 0000000000..6ed75542df
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/invalidVariableNameVSM.odesign
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<description:Group xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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:description_2="http://www.eclipse.org/sirius/table/description/1.1.0" xmlns:style="http://www.eclipse.org/sirius/diagram/description/style/1.1.0" xmlns:tool="http://www.eclipse.org/sirius/description/tool/1.1.0" xmlns:tool_1="http://www.eclipse.org/sirius/diagram/description/tool/1.1.0" name="invalidVariableNameVSM" version="11.0.0.201601261200">
+ <ownedViewpoints name="invalidVariableNameVSM">
+ <ownedRepresentations xsi:type="description_1:DiagramDescription" name="diagram" domainClass="EPackage">
+ <defaultLayer name="Default">
+ <edgeMappings name="Edge" sourceMapping="//@ownedViewpoints[name='invalidVariableNameVSM']/@ownedRepresentations[name='diagram']/@defaultLayer/@containerMappings[name='class']" targetMapping="//@ownedViewpoints[name='invalidVariableNameVSM']/@ownedRepresentations[name='diagram']/@defaultLayer/@containerMappings[name='class']" targetFinderExpression="feature:eReferences">
+ <style sizeComputationExpression="2">
+ <strokeColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='gray']"/>
+ <centerLabelStyleDescription>
+ <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
+ </centerLabelStyleDescription>
+ </style>
+ </edgeMappings>
+ <containerMappings name="class" domainClass="EClass" childrenPresentation="List">
+ <subNodeMappings name="attribute" semanticCandidatesExpression="feature:eAllContents" domainClass="EAttribute">
+ <style xsi:type="style:SquareDescription">
+ <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
+ <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
+ <color xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='gray']"/>
+ </style>
+ </subNodeMappings>
+ <style xsi:type="style:FlatContainerStyleDescription" arcWidth="1" arcHeight="1" borderSizeComputationExpression="1">
+ <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
+ <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
+ <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/>
+ <foregroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='light_gray']"/>
+ </style>
+ </containerMappings>
+ <toolSections name="Tool">
+ <ownedTools xsi:type="tool:OperationAction" name="MyAction">
+ <view name="views"/>
+ <initialOperation>
+ <firstModelOperations xsi:type="tool_1:CreateView" mapping="//@ownedViewpoints[name='invalidVariableNameVSM']/@ownedRepresentations[name='diagram']/@defaultLayer/@containerMappings[name='class']" containerViewExpression="var:self" variableName="newView">
+ <subModelOperations xsi:type="tool:ChangeContext" browseExpression="var:newView"/>
+ </firstModelOperations>
+ </initialOperation>
+ </ownedTools>
+ <ownedTools xsi:type="tool:OperationAction" name="MyAction2">
+ <view name="views"/>
+ <initialOperation>
+ <firstModelOperations xsi:type="tool_1:CreateEdgeView" mapping="//@ownedViewpoints[name='invalidVariableNameVSM']/@ownedRepresentations[name='diagram']/@defaultLayer/@edgeMappings[name='Edge']" containerViewExpression="var:self" sourceExpression="var:self" targetExpression="var:self">
+ <subModelOperations xsi:type="tool:ChangeContext" browseExpression="var:createdView"/>
+ </firstModelOperations>
+ </initialOperation>
+ </ownedTools>
+ </toolSections>
+ </defaultLayer>
+ </ownedRepresentations>
+ <ownedRepresentations xsi:type="description_2:EditionTableDescription" name="table" domainClass="EClass">
+ <ownedLineMappings name="Line" domainClass="EClass"/>
+ <ownedColumnMappings name="Column" featureName="feature:eAllContents">
+ <directEdit>
+ <variables documentation="The currently edited element."/>
+ <variables name="lineSemantic" documentation="The semantic element corresponding to the line.">
+ <subVariables xsi:type="tool:AcceleoVariable"/>
+ </variables>
+ <variables name="root" documentation="The semantic element of the table."/>
+ <firstModelOperation xsi:type="tool:ChangeContext" browseExpression="var:self"/>
+ <mask mask="{0}"/>
+ </directEdit>
+ </ownedColumnMappings>
+ </ownedRepresentations>
+ </ownedViewpoints>
+</description:Group>
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/vsm/VSMValidationTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/vsm/VSMValidationTest.java
index 12ded3a2f8..6b2c91b6f6 100644
--- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/vsm/VSMValidationTest.java
+++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/vsm/VSMValidationTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2015 THALES GLOBAL SERVICES, and others.
+ * Copyright (c) 2010, 2016 THALES GLOBAL SERVICES, 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
@@ -47,6 +47,8 @@ public class VSMValidationTest extends SiriusDiagramTestCase {
private Group modelerForVariableNameValidation;
+ private Group modelerForInvalidVariableNameValidation;
+
private Group modelerForImagePathValidation;
private Group modelerForDefaultLayerValidation;
@@ -60,6 +62,7 @@ public class VSMValidationTest extends SiriusDiagramTestCase {
modelerWithDiagramExtension = (Group) ModelUtils.load(URI.createPlatformPluginURI("/org.eclipse.sirius.tests.junit/data/unit/vsm/valideVSMWithDiagramExtension.odesign", true), set);
modelerForDomainClassValidation = (Group) ModelUtils.load(URI.createPlatformPluginURI("/org.eclipse.sirius.tests.junit/data/unit/vsm/valideDomainClassVSM.odesign", true), set);
modelerForVariableNameValidation = (Group) ModelUtils.load(URI.createPlatformPluginURI("/org.eclipse.sirius.tests.junit/data/unit/vsm/valideVariableNameVSM.odesign", true), set);
+ modelerForInvalidVariableNameValidation = (Group) ModelUtils.load(URI.createPlatformPluginURI("/org.eclipse.sirius.tests.junit/data/unit/vsm/invalidVariableNameVSM.odesign", true), set);
modelerForImagePathValidation = (Group) ModelUtils.load(URI.createPlatformPluginURI("/org.eclipse.sirius.tests.junit/data/unit/vsm/validateImagePathVSM.odesign", true), set);
modelerForDefaultLayerValidation = (Group) ModelUtils.load(URI.createPlatformPluginURI("/org.eclipse.sirius.tests.junit/data/unit/vsm/validateDefaultLayerVSM.odesign", true), set);
}
@@ -182,6 +185,17 @@ public class VSMValidationTest extends SiriusDiagramTestCase {
}
/**
+ * Ensure that VSM validation detects blank (missing or empty) variable
+ * names as invalid.
+ */
+ public void testBlankVariableNameValidation() {
+ Diagnostician diagnostician = new Diagnostician();
+ Diagnostic diagnostic = diagnostician.validate(modelerForInvalidVariableNameValidation);
+ assertEquals("The VSM is not valid, it should have popup error message", Diagnostic.ERROR, diagnostic.getSeverity());
+ assertEquals("Validation should have found 2 invalid variable names", 2, diagnostic.getChildren().size());
+ }
+
+ /**
* Test VSM validation with diferent paths for images (there are valid and
* invalid paths).
*/
@@ -195,17 +209,16 @@ public class VSMValidationTest extends SiriusDiagramTestCase {
"^The image ' /org.eclipse.sirius.tests.junit/images/logo_o.png ' does not exist.$", "^The image '/test/noimage.gif' does not exist.$",
"^The path 'icon' does not correspond to an image.$", "^The image 'icon' does not exist.$", "^The path '/org.eclipse.sirius.tests.junit/plugin.xml' does not correspond to an image.$",
"^The image 'C:\\\\images\\\\image.png' does not exist.$", "^The image '/org.eclipse.sirius.tests.junit/images/notexisting.png' does not exist.$",
- "^The required feature 'decoratorPath' of 'org.eclipse.sirius.viewpoint.description.impl.SemanticBasedDecorationImpl@.*' must be set$"};
-
- assertEquals(
- "The diagnostic must contain " + expectedMessagesPatterns.length + " validation errors. Returned messages were :\n"
- + Joiner.on('\n').join(Iterables.transform(children, new Function<Diagnostic, String>() {
+ "^The required feature 'decoratorPath' of 'org.eclipse.sirius.viewpoint.description.impl.SemanticBasedDecorationImpl@.*' must be set$" };
- @Override
- public String apply(Diagnostic input) {
- return input.getMessage();
- }
- })), expectedMessagesPatterns.length, children.size());
+ assertEquals("The diagnostic must contain " + expectedMessagesPatterns.length + " validation errors. Returned messages were :\n"
+ + Joiner.on('\n').join(Iterables.transform(children, new Function<Diagnostic, String>() {
+
+ @Override
+ public String apply(Diagnostic input) {
+ return input.getMessage();
+ }
+ })), expectedMessagesPatterns.length, children.size());
for (int i = 0; i < expectedMessagesPatterns.length; i++) {
assertTrue("Unexpected validation error at position " + i, children.get(i).getMessage().matches(expectedMessagesPatterns[i]));
}
diff --git a/plugins/org.eclipse.sirius/plugin.xml b/plugins/org.eclipse.sirius/plugin.xml
index c83e235f1e..26ac9a06d8 100644
--- a/plugins/org.eclipse.sirius/plugin.xml
+++ b/plugins/org.eclipse.sirius/plugin.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<!--
- Copyright (c) 2007, 2013 THALES GLOBAL SERVICES
+ Copyright (c) 2007, 2016 THALES GLOBAL SERVICES 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
@@ -255,6 +255,9 @@
<target
class="IdentifiedElement">
</target>
+ <target
+ class="AbstractVariable">
+ </target>
</constraint>
</constraints>
</constraintProvider>
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/VSMElementNameValidConstraint.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/VSMElementNameValidConstraint.java
index 4191a6e076..38f65b1943 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/VSMElementNameValidConstraint.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/VSMElementNameValidConstraint.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014, 2015 Obeo.
+ * Copyright (c) 2014, 2016 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
@@ -17,6 +17,7 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.validation.IValidationContext;
import org.eclipse.sirius.common.tools.api.util.StringUtil;
import org.eclipse.sirius.viewpoint.Messages;
+import org.eclipse.sirius.viewpoint.description.AbstractVariable;
import org.eclipse.sirius.viewpoint.description.IdentifiedElement;
/**
@@ -35,6 +36,11 @@ public class VSMElementNameValidConstraint extends AbstractCommonToolToAppliedOn
if (StringUtil.isEmpty(elementName)) {
status = ctx.createFailureStatus(MessageFormat.format(Messages.VSMElementNameValidConstraint_invalidNameErrorMsg, getPath(target)));
}
+ } else if (target instanceof AbstractVariable) {
+ String elementName = ((AbstractVariable) target).getName();
+ if (StringUtil.isEmpty(elementName)) {
+ status = ctx.createFailureStatus(MessageFormat.format(Messages.VSMElementNameValidConstraint_invalidNameErrorMsg, getPath(target)));
+ }
}
if (status == null) {
status = ctx.createSuccessStatus();

Back to the top