diff options
| author | Pierre-Charles David | 2015-02-18 15:02:39 +0000 |
|---|---|---|
| committer | Pierre-Charles David | 2015-02-18 15:02:39 +0000 |
| commit | 5fe1acb3875e04f8636fa063c144264d05d78efc (patch) | |
| tree | 42e237e65c04f53496a068fb64aa356a7b4168da | |
| parent | 2d5c3493418496e01916b59c7acca33e89ea6a2d (diff) | |
| download | org.eclipse.sirius-5fe1acb3875e04f8636fa063c144264d05d78efc.tar.gz org.eclipse.sirius-5fe1acb3875e04f8636fa063c144264d05d78efc.tar.xz org.eclipse.sirius-5fe1acb3875e04f8636fa063c144264d05d78efc.zip | |
[460014] Improve validation precision and fix test
The validation used to return only the first failing check, then only
the last one (after the previous change). Now we always check both
conditions (file extension and existence).
Bug: 460014
Change-Id: Ic5fdff000ee0d00daf31c95752688c9fc779439e
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
2 files changed, 26 insertions, 16 deletions
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 5668acaf1d..a7cd40796a 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 @@ -184,18 +184,21 @@ public class VSMValidationTest extends SiriusDiagramTestCase { // Check that there is a pop up for validation problems assertEquals("The VSM is not valid, it should have popup error message", Diagnostic.ERROR, diagnostic.getSeverity()); List<Diagnostic> children = diagnostic.getChildren(); - // test if there is 7 errors and if each one corresponds to the awaited - // one - assertEquals("The diagnostic must contain 7 elements invalidated", 7, children.size()); - assertEquals("The first error do not match the awaited one", "The path ' /org.eclipse.sirius.tests.junit/images/logo_o.png ' does not correspond to an image.", children.get(0).getMessage()); - assertEquals("The second error do not match the awaited one", "The image '/test/noimage.gif' does not exist.", children.get(1).getMessage()); - assertEquals("The third error do not match the awaited one", "The path 'icon' does not correspond to an image.", children.get(2).getMessage()); - assertEquals("The fourth error do not match the awaited one", "The path '/org.eclipse.sirius.tests.junit/plugin.xml' does not correspond to an image.", children.get(3).getMessage()); - assertEquals("The fifth error do not match the awaited one", "The image 'C:\\images\\image.png' does not exist.", children.get(4).getMessage()); - assertEquals("The sixth error do not match the awaited one", "The image '/org.eclipse.sirius.tests.junit/images/notexisting.png' does not exist.", children.get(5).getMessage()); - // partial assert because the full message references the object with by - // its toString(), so it contains the its instance id, which is variable - assertEquals("The seventh error do not match the awaited one", "The required feature 'decoratorPath' of", children.get(6).getMessage().substring(0, 39)); + String[] expectedMessagesPatterns = { + "^The path ' /org.eclipse.sirius.tests.junit/images/logo_o.png ' does not correspond to an image.$", + "^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", 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])); + } } private void addSpaceInDomainClassValue(EObject current, EAttribute attribute, int iterate) { diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/AbstractValidImageConstraint.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/AbstractValidImageConstraint.java index 5a9e68ad00..8a470d8897 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/AbstractValidImageConstraint.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/internal/validation/description/constraints/AbstractValidImageConstraint.java @@ -11,6 +11,7 @@ package org.eclipse.sirius.tools.internal.validation.description.constraints; import java.util.ArrayList; +import java.util.Collection; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; @@ -26,6 +27,8 @@ import org.eclipse.sirius.common.tools.api.resource.ImageFileFormat; import org.eclipse.sirius.common.tools.api.util.StringUtil; import org.eclipse.sirius.tools.internal.validation.AbstractConstraint; +import com.google.common.collect.Lists; + /** * Abstract Constraint to validate image references. * @@ -65,18 +68,22 @@ public abstract class AbstractValidImageConstraint extends AbstractConstraint { public abstract EAttribute[] getImagePathAttributes(); private IStatus validateImagePath(IValidationContext ctx, ResourceSet rs, String path) { - IStatus result = ctx.createSuccessStatus(); + Collection<IStatus> failures = Lists.newArrayList(); // when path is empty, success (even when a path is needed, because // there is another validation rule for that) if (!StringUtil.isEmpty(path)) { if (!validateExtension(path)) { - result = ctx.createFailureStatus(new Object[] { "The path '" + path + "' does not correspond to an image." }); + failures.add(ctx.createFailureStatus(new Object[] { "The path '" + path + "' does not correspond to an image." })); } if (!validateExistence(path, rs)) { - result = ctx.createFailureStatus(new Object[] { "The image '" + path + "' does not exist." }); + failures.add(ctx.createFailureStatus(new Object[] { "The image '" + path + "' does not exist." })); } } - return result; + if (failures.isEmpty()) { + return ctx.createSuccessStatus(); + } else { + return ConstraintStatus.createMultiStatus(ctx, failures); + } } private boolean validateExistence(String path, ResourceSet rs) { |
