diff options
| author | Mickael LANOE | 2014-12-03 16:47:58 +0000 |
|---|---|---|
| committer | Florian Barbin | 2015-01-21 09:38:43 +0000 |
| commit | cf0d769405404e5448f8f052f8d6f1da2ee34b1a (patch) | |
| tree | 1a37ac6c9f2226637792f25b9f63f84154c3b968 | |
| parent | 9fc74dc332f848fa83deb684f13af1e174891b43 (diff) | |
| download | org.eclipse.sirius-cf0d769405404e5448f8f052f8d6f1da2ee34b1a.tar.gz org.eclipse.sirius-cf0d769405404e5448f8f052f8d6f1da2ee34b1a.tar.xz org.eclipse.sirius-cf0d769405404e5448f8f052f8d6f1da2ee34b1a.zip | |
[441642] Validate the diagram root element DDiagram
The validation is now applied to the diagram root element DDiagram.
Update INFO/WARNING/ERROR constraints registered in
org.eclipse.sirius.diagram/plugin.xml to add the target DDiagram.
Disable the validation decorator in SiriusValidationDecoratorProvider
for the DDiagram to avoid graphical conflict with other elements.
Update the DiagramValidationTest to check this new validation.
Bug: 441642
Change-Id: Ic50c682ebde7083ede25a30632cef94a611c9685
Signed-off-by: Mickael LANOE <mickael.lanoe@obeo.fr>
5 files changed, 172 insertions, 64 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/providers/SiriusValidationDecoratorProvider.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/providers/SiriusValidationDecoratorProvider.java index a54eebf72e..dcfe0559b3 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/providers/SiriusValidationDecoratorProvider.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/providers/SiriusValidationDecoratorProvider.java @@ -37,6 +37,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditDomain; import org.eclipse.gmf.runtime.diagram.ui.services.decorator.AbstractDecorator; import org.eclipse.gmf.runtime.diagram.ui.services.decorator.CreateDecoratorsOperation; +import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration; import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecorator; import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider; import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget; @@ -82,6 +83,7 @@ public class SiriusValidationDecoratorProvider extends AbstractProvider implemen /** * @was-generated */ + @Override public void createDecorators(IDecoratorTarget decoratorTarget) { EditPart editPart = (EditPart) decoratorTarget.getAdapter(EditPart.class); if (editPart instanceof GraphicalEditPart || editPart instanceof AbstractConnectionEditPart) { @@ -105,6 +107,7 @@ public class SiriusValidationDecoratorProvider extends AbstractProvider implemen /** * @was-generated */ + @Override public boolean provides(IOperation operation) { if (!(operation instanceof CreateDecoratorsOperation)) { return false; @@ -132,10 +135,12 @@ public class SiriusValidationDecoratorProvider extends AbstractProvider implemen final Diagram fdiagram = diagram; PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + @Override public void run() { try { TransactionUtil.getEditingDomain(fdiagram).runExclusive(new Runnable() { + @Override public void run() { for (Iterator it = decorators.iterator(); it.hasNext();) { IDecorator decorator = (IDecorator) it.next(); @@ -169,6 +174,7 @@ public class SiriusValidationDecoratorProvider extends AbstractProvider implemen final View view = (View) getDecoratorTarget().getAdapter(View.class); TransactionUtil.getEditingDomain(view).runExclusive(new Runnable() { + @Override public void run() { StatusDecorator.this.viewId = view != null ? SiriusGMFHelper.getViewId(view) : null; } @@ -181,6 +187,7 @@ public class SiriusValidationDecoratorProvider extends AbstractProvider implemen /** * @not-generated */ + @Override public void refresh() { removeDecoration(); View view = (View) getDecoratorTarget().getAdapter(View.class); @@ -248,14 +255,25 @@ public class SiriusValidationDecoratorProvider extends AbstractProvider implemen // add decoration if (editPart instanceof org.eclipse.gef.GraphicalEditPart) { - if (view instanceof Edge) { - setDecoration(getDecoratorTarget().addConnectionDecoration(getImage(severity), 50, true)); + IDecoration decoration = null; + + if (view instanceof Diagram) { + // There is not yet defined decorator for a diagram + } else if (view instanceof Edge) { + decoration = getDecoratorTarget().addConnectionDecoration(getImage(severity), 50, true); } else { int margin = -1; margin = MapModeUtil.getMapMode(((org.eclipse.gef.GraphicalEditPart) editPart).getFigure()).DPtoLP(margin); - setDecoration(getDecoratorTarget().addShapeDecoration(getImage(severity), IDecoratorTarget.Direction.NORTH_EAST, margin, true)); + decoration = getDecoratorTarget().addShapeDecoration(getImage(severity), IDecoratorTarget.Direction.NORTH_EAST, margin, true); + } + + if (decoration != null) { + setDecoration(decoration); + + // getDecaration() returns a {@link Decoration} instead of a + // {@link IDecoration} + getDecoration().setToolTip(toolTip); } - getDecoration().setToolTip(toolTip); } } @@ -280,6 +298,7 @@ public class SiriusValidationDecoratorProvider extends AbstractProvider implemen /** * @was-generated */ + @Override public void activate() { if (viewId == null) { return; @@ -312,6 +331,7 @@ public class SiriusValidationDecoratorProvider extends AbstractProvider implemen /** * @was-generated */ + @Override public void deactivate() { if (viewId == null) { return; @@ -356,36 +376,42 @@ public class SiriusValidationDecoratorProvider extends AbstractProvider implemen /** * @was-generated */ + @Override public void handleFileRenamed(IFile oldFile, IFile file) { } /** * @was-generated */ + @Override public void handleFileMoved(IFile oldFile, IFile file) { } /** * @was-generated */ + @Override public void handleFileDeleted(IFile file) { } /** * @was-generated */ + @Override public void handleFileChanged(IFile file) { } /** * @was-generated */ + @Override public void handleMarkerAdded(IMarker marker) { if (marker.getAttribute(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, null) != null) { handleMarkerChanged(marker); } } + @Override public void handleMarkerDeleted(IMarker marker, Map attributes) { if (attributes != null) { String viewId = (String) attributes.get(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID); @@ -396,6 +422,7 @@ public class SiriusValidationDecoratorProvider extends AbstractProvider implemen /** * @was-generated */ + @Override public void handleMarkerChanged(IMarker marker) { if (!MARKER_TYPE.equals(getType(marker))) { return; diff --git a/plugins/org.eclipse.sirius.diagram/plugin.xml b/plugins/org.eclipse.sirius.diagram/plugin.xml index c83c54edd0..ecc721e0c1 100644 --- a/plugins/org.eclipse.sirius.diagram/plugin.xml +++ b/plugins/org.eclipse.sirius.diagram/plugin.xml @@ -318,7 +318,8 @@ <message> <![CDATA[{0}]]> </message> - <target class="DDiagramElement"/> + <target class="DDiagramElement"/> + <target class="DDiagram"/> </constraint> <constraint lang="Java" @@ -333,7 +334,8 @@ <message> <![CDATA[{0}]]> </message> - <target class="DDiagramElement"/> + <target class="DDiagramElement"/> + <target class="DDiagram"/> </constraint> <constraint lang="Java" @@ -348,7 +350,8 @@ <message> <![CDATA[{0}]]> </message> - <target class="DDiagramElement"/> + <target class="DDiagramElement"/> + <target class="DDiagram"/> </constraint> </constraints> </constraintProvider> diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/api/validation/constraint/AbstractDDiagramConstraint.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/api/validation/constraint/AbstractDDiagramConstraint.java index 15d1dec2ab..cd984aa751 100644 --- a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/api/validation/constraint/AbstractDDiagramConstraint.java +++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/api/validation/constraint/AbstractDDiagramConstraint.java @@ -51,17 +51,20 @@ import org.eclipse.sirius.viewpoint.description.validation.ViewValidationRule; public abstract class AbstractDDiagramConstraint extends AbstractModelConstraint { @Override public IStatus validate(final IValidationContext ctx) { - final EObject objetTeste = ctx.getTarget(); + final EObject objectToValidate = ctx.getTarget(); final EMFEventType typeEvenement = ctx.getEventType(); - if (typeEvenement == EMFEventType.NULL && (objetTeste instanceof DDiagramElement)) { - final Collection<ValidationRule> failures = getFailingRules((DDiagramElement) objetTeste); + if (typeEvenement == EMFEventType.NULL) { + final Collection<ValidationRule> failures = getFailingRules(objectToValidate); if (failures.size() > 0) { final MultiStatus parentStatus = new MultiStatus(SiriusPlugin.ID, getHighestStatusCode(failures), "Validation issues", null); for (ValidationRule failedRule : failures) { - EObject target = objetTeste; - if (failedRule instanceof SemanticValidationRule) { - target = ((DDiagramElement) objetTeste).getTarget(); + EObject target = objectToValidate; + + // Change the target for SemanticValidationRule + if (failedRule instanceof SemanticValidationRule && objectToValidate instanceof DSemanticDecorator) { + target = ((DSemanticDecorator) objectToValidate).getTarget(); } + final ConstraintStatus emfStatus = (ConstraintStatus) ctx.createFailureStatus(new Object[] { failedRule.getMessage(target) }); parentStatus.add(new RuleWrappingStatus(emfStatus, failedRule)); } @@ -97,50 +100,61 @@ public abstract class AbstractDDiagramConstraint extends AbstractModelConstraint /** * - * @param objetTeste + * @param objectToValidate * object we are testing. * @return the first {@link ValidationRule} conform to isValid() which * fails. */ - private Collection<ValidationRule> getFailingRules(final DDiagramElement objetTeste) { + private Collection<ValidationRule> getFailingRules(final EObject objectToValidate) { final Collection<ValidationRule> failingRules = new ArrayList<ValidationRule>(); - final DDiagram diagram = objetTeste.getParentDiagram(); + + // Get the DDiagram + DDiagram diagram = null; + if (objectToValidate instanceof DDiagram) { + diagram = (DDiagram) objectToValidate; + } else if (objectToValidate instanceof DDiagramElement) { + diagram = ((DDiagramElement) objectToValidate).getParentDiagram(); + } + if (diagram != null) { /* * If some rules are manually activated, then we'll pick in these * ones, otherwhise we'll use all the rules. */ if (diagram.getActivatedRules().size() > 0) { - failingRules.addAll(getFaillingRulesFromCollection(objetTeste, diagram.getActivatedRules().iterator())); + failingRules.addAll(getFaillingRulesFromCollection(objectToValidate, diagram.getActivatedRules().iterator())); } else if (diagram.getDescription() != null) { final DiagramDescription desc = diagram.getDescription(); final ValidationSet validationSet = desc.getValidationSet(); if (validationSet != null) { - failingRules.addAll(getFaillingRulesFromCollection(objetTeste, validationSet.getAllRules().iterator())); + failingRules.addAll(getFaillingRulesFromCollection(objectToValidate, validationSet.getAllRules().iterator())); } } - failingRules.addAll(checkRulesFromActivatedViewpoints(objetTeste, diagram)); + failingRules.addAll(checkRulesFromActivatedViewpoints(objectToValidate, diagram)); } + return failingRules; } - private Collection<ValidationRule> checkRulesFromActivatedViewpoints(final DDiagramElement objetTeste, final DDiagram diagram) { - final EObject semantic = objetTeste.getTarget(); - final ValidationRule firstFailingRule = null; - final Session session = SessionManager.INSTANCE.getSession(semantic); - if (session != null) { - final Iterator<Viewpoint> it = session.getSelectedViewpoints(false).iterator(); - while (it.hasNext() && firstFailingRule == null) { - final Viewpoint vp = it.next(); - if (vp.getValidationSet() != null) { - return getFaillingRulesFromCollection(objetTeste, vp.getValidationSet().getAllRules().iterator()); + private Collection<ValidationRule> checkRulesFromActivatedViewpoints(final EObject objectToValidate, final DDiagram diagram) { + if (objectToValidate instanceof DSemanticDecorator) { + final EObject semantic = ((DSemanticDecorator) objectToValidate).getTarget(); + final Session session = SessionManager.INSTANCE.getSession(semantic); + if (session != null) { + final Iterator<Viewpoint> it = session.getSelectedViewpoints(false).iterator(); + while (it.hasNext()) { + final Viewpoint vp = it.next(); + if (vp.getValidationSet() != null) { + return getFaillingRulesFromCollection(objectToValidate, vp.getValidationSet().getAllRules().iterator()); + } } } } + return Collections.emptyList(); } - private Collection<ValidationRule> getFaillingRulesFromCollection(final DDiagramElement objetTeste, final Iterator<ValidationRule> it) { + private Collection<ValidationRule> getFaillingRulesFromCollection(final EObject objectToValidate, final Iterator<ValidationRule> it) { final Collection<ValidationRule> failingRules = new ArrayList<ValidationRule>(); /* * Iterate and return the first failling rule. null if no rule is @@ -149,17 +163,18 @@ public abstract class AbstractDDiagramConstraint extends AbstractModelConstraint while (it.hasNext()) { final ValidationRule rule = it.next(); if (isValid(rule)) { - EObject semanticTargetElement = ((DSemanticDecorator) objetTeste).getTarget(); - if (rule instanceof SemanticValidationRule && ((SemanticValidationRule) rule).getTargetClass() != null && !StringUtil.isEmpty(((SemanticValidationRule) rule).getTargetClass().trim())) { - if (isSemanticElementToValidate(objetTeste, semanticTargetElement, ((SemanticValidationRule) rule).getTargetClass())) { + if (objectToValidate instanceof DSemanticDecorator && rule instanceof SemanticValidationRule && ((SemanticValidationRule) rule).getTargetClass() != null + && !StringUtil.isEmpty(((SemanticValidationRule) rule).getTargetClass().trim())) { + EObject semanticTargetElement = ((DSemanticDecorator) objectToValidate).getTarget(); + if (isSemanticElementToValidate(objectToValidate, semanticTargetElement, ((SemanticValidationRule) rule).getTargetClass())) { if (!rule.checkRule(semanticTargetElement)) { failingRules.add(rule); } } - } else if (rule instanceof ViewValidationRule) { - final DiagramElementMapping objMapping = objetTeste.getDiagramElementMapping(); + } else if (objectToValidate instanceof DDiagramElement && rule instanceof ViewValidationRule) { + final DiagramElementMapping objMapping = ((DDiagramElement) objectToValidate).getDiagramElementMapping(); if (objMapping != null && ((ViewValidationRule) rule).getTargets().contains(objMapping)) { - if (!rule.checkRule(objetTeste)) { + if (!rule.checkRule(objectToValidate)) { failingRules.add(rule); } } @@ -173,7 +188,7 @@ public abstract class AbstractDDiagramConstraint extends AbstractModelConstraint * Check if this element must be validated. * * @param objectToValidate - * The diagram element to validate + * The object to validate * @param semanticElement * The semantic element associated with the * <code>objectToValidate</code>. @@ -181,7 +196,7 @@ public abstract class AbstractDDiagramConstraint extends AbstractModelConstraint * The expected class for the semantic element. * @return true if the semantic element must be validate, false otherwise. */ - private boolean isSemanticElementToValidate(DDiagramElement objectToValidate, EObject semanticElement, String expectedClass) { + private boolean isSemanticElementToValidate(EObject objectToValidate, EObject semanticElement, String expectedClass) { boolean result = false; if (SiriusPlugin.getDefault().getModelAccessorRegistry().getModelAccessor(semanticElement).eInstanceOf(semanticElement, expectedClass)) { if (objectToValidate instanceof DEdge) { diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/validation/ticket1666.odesign b/plugins/org.eclipse.sirius.tests.junit/data/unit/validation/ticket1666.odesign index bd2ec84849..a45afd8a7a 100644 --- a/plugins/org.eclipse.sirius.tests.junit/data/unit/validation/ticket1666.odesign +++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/validation/ticket1666.odesign @@ -53,14 +53,6 @@ </centerLabelStyleDescription> </style> </edgeMappings> - <edgeMappings name="containerPackage" semanticCandidatesExpression="var:self" sourceMapping="//@ownedViewpoints[name='Ticket%201666']/@ownedRepresentations[name='Breakdown']/@defaultLayer/@nodeMappings[name='Package']" targetMapping="//@ownedViewpoints[name='Ticket%201666']/@ownedRepresentations[name='Breakdown']/@defaultLayer/@nodeMappings[name='Package']" targetFinderExpression="<%eSubpackages.nGet(0).eSubpackages.nGet(0)%>" sourceFinderExpression="<%eSubpackages.nGet(0)%>" domainClass="EPackage" useDomainElement="true"> - <style sizeComputationExpression="2"> - <strokeColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='gray']"/> - <centerLabelStyleDescription labelExpression="element_edge_<%name%>"> - <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> - </centerLabelStyleDescription> - </style> - </edgeMappings> <toolSections name="tools"> <ownedTools xsi:type="tool:EdgeCreationDescription" name="Contained In" edgeMappings="//@ownedViewpoints[name='Ticket%201666']/@ownedRepresentations[name='Breakdown']/@defaultLayer/@edgeMappings[name='Containers']"> <sourceVariable name="source"/> diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/validation/DiagramValidationTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/validation/DiagramValidationTest.java index 845ab6f6e0..0636006df7 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/validation/DiagramValidationTest.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/validation/DiagramValidationTest.java @@ -20,21 +20,26 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.ILogListener; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.workspace.util.WorkspaceSynchronizer; import org.eclipse.gmf.runtime.common.ui.util.WorkbenchPartDescriptor; import org.eclipse.sirius.diagram.DDiagram; +import org.eclipse.sirius.diagram.DDiagramElement; +import org.eclipse.sirius.diagram.DNode; import org.eclipse.sirius.diagram.DiagramPlugin; import org.eclipse.sirius.diagram.ui.internal.providers.SiriusMarkerNavigationProvider; import org.eclipse.sirius.diagram.ui.part.ValidateAction; import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; +import org.eclipse.sirius.tests.SiriusTestsPlugin; import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase; import org.eclipse.sirius.tests.support.api.TestsUtil; import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; import org.eclipse.sirius.viewpoint.DSemanticDecorator; import org.eclipse.ui.IEditorPart; -import org.eclipse.sirius.tests.SiriusTestsPlugin; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; /** * Validation tests. @@ -125,13 +130,16 @@ public class DiagramValidationTest extends SiriusDiagramTestCase { } /** - * Test there is only one error by elements not validate and not many errors - * message duplicate for same element. Test VP-2940 + * Test there is only one error by elements not validated and not many + * errors message duplicate for same element. See VP-2940 * - * @throws Exception + * Also check that there is only one semantic error for the root element. + * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=441642 + * + * @throws CoreException * Test errors. */ - public void testValidationOnlyOneErrorMessage() throws Exception { + public void testValidationOnlyOneErrorMessage() throws CoreException { diagram = (DDiagram) createRepresentation(REPRESENTATION_DESC_NAME_BREAKDOWN, rootEPackage); editorPart = DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor()); @@ -154,38 +162,101 @@ public class DiagramValidationTest extends SiriusDiagramTestCase { // Check markers EPackage root = (EPackage) ((DSemanticDecorator) diagram).getTarget(); - checkMarkers(root, foundUIMarkers, 0, 1, "element_edge_"); + checkSemanticMarkers(root, foundUIMarkers, 1); EPackage ap1 = root.getESubpackages().get(0); - checkMarkers(ap1, foundUIMarkers, 1, 1, "container_"); + checkMarkers(ap1, foundUIMarkers, 1, 1); EPackage ap2 = ap1.getESubpackages().get(0); - checkMarkers(ap2, foundUIMarkers, 1, 1, "container_"); + checkMarkers(ap2, foundUIMarkers, 1, 1); verify(logListener); } - private void checkMarkers(EPackage tgt, IMarker[] foundMarkers, int nbViewMarker, int nbSemanticMarker, String locationPrefix) { + /** + * Get the first {@link DNode} with target equals to the parameter. + * + * @param target + * target to find + * @return first valid {@link DNode} found + */ + private DDiagramElement getGraphicNodeElement(final EObject target) { + return Iterables.find(diagram.getDiagramElements(), new Predicate<DDiagramElement>() { + @Override + public boolean apply(DDiagramElement element) { + return element instanceof DNode && element.getTarget() == target; + } + }); + } + + /** + * Check markers for {@code semanticElement}. + * + * @param semanticElement + * semantic element to check + * @param foundMarkers + * markers found + * @param expectedNbViewMarker + * expected number of view marker for the first {@link DNode} + * with target equals to {@code semanticElement} + * @param expectedNbSemanticMarker + * expected number of semantic marker for {@code semanticElement} + */ + private void checkMarkers(EPackage semanticElement, IMarker[] foundMarkers, int expectedNbViewMarker, int expectedNbSemanticMarker) { + DDiagramElement graphicElement = getGraphicNodeElement(semanticElement); + String semanticName = semanticElement.getName(); + String graphicName = graphicElement.getName(); + + // Two cases to find: + String graphicCase = "Graphic - The " + graphicName + " element is KO -> View rule OK"; + String semanticCase = "The " + semanticName + " element is KO -> Semantic rule OK"; + int graphicMarkers = 0; int semanticMarkers = 0; for (IMarker marker : foundMarkers) { try { - String location = (String) marker.getAttribute(IMarker.LOCATION); String message = (String) marker.getAttribute(IMarker.MESSAGE); + if (message.equals(graphicCase)) { + graphicMarkers++; + } else if (message.equals(semanticCase)) { + semanticMarkers++; + } + } catch (CoreException e) { + fail(e.getMessage()); + } + } - if (location.endsWith(locationPrefix + tgt.getName())) { - if (message.startsWith("Graphic - ") && message.endsWith("-> View rule OK")) { - graphicMarkers++; - } else if (message.endsWith("-> Semantic rule OK")) { - semanticMarkers++; - } + assertEquals("The graphic element '" + graphicName + "' does not have the expected ViewValidationRule markers", expectedNbViewMarker, graphicMarkers); + assertEquals("The semantic element '" + semanticName + "' does not have the expected SemanticValidationRule markers", expectedNbSemanticMarker, semanticMarkers); + } + + /** + * Check semantic markers for {@code semanticElement}. + * + * @param semanticElement + * semantic element to check + * @param foundMarkers + * markers found + * @param expectedNbSemanticMarker + * expected number of semantic marker for {@code semanticElement} + */ + private void checkSemanticMarkers(EPackage semanticElement, IMarker[] foundMarkers, int expectedNbSemanticMarker) { + String semanticName = semanticElement.getName(); + String expectedMessage = "The " + semanticName + " element is KO -> Semantic rule OK"; + + int semanticMarkers = 0; + for (IMarker marker : foundMarkers) { + try { + String message = (String) marker.getAttribute(IMarker.MESSAGE); + if (message.equals(expectedMessage)) { + semanticMarkers++; } } catch (CoreException e) { fail(e.getMessage()); } } - assertEquals("The element " + tgt.getName() + " does not have the expected ViewValidationRule markers", nbViewMarker, graphicMarkers); - assertEquals("The element " + tgt.getName() + " does not have the expected SemanticValidationRule markers", nbSemanticMarker, semanticMarkers); + + assertEquals("The semantic element '" + semanticName + "' does not have the expected SemanticValidationRule markers", expectedNbSemanticMarker, semanticMarkers); } @Override |
