How to model constraints for use in validation¶
Contents
Step by Step guide¶
The modelling steps are:
Adding a Constraint¶
The video shows creating a validation constraint on a template. The example is using the Domain Model but it is equally applicable to the other layers.
Todo
text of this section
Add descrition - it is suggested that this is the same as the “Validation Rule - Error Message”. If more description is needed see How to format descriptions for details
Tip
Add the constraint from the specification window (rather than from the containment tree) as this will automatically set the “Constrained Element” property
Tip
Some Examples
Check that one property value does not equal another property value (Parent[1] Child[1]):
self.Parent <> self.Child
Check for simple circularities in single elements (InheritsFrom[0..1]):
self.InheritsFrom <> self
Check for simple circularities in a collection (InOrganization[0..*]):
self.InOrganization->excludes(self)
Check that a property value is not also in a property collection (Element[0..*] BreakdownOf[1]):
self.Element->forAll(e | self.BreakdownOf <> e) [Note: syntax error if try to use self.Element->excludes(self.BreakdownOf)]
Check that two collections of property values are mutually exclusive (Manages[0..*] Inputs[0..*]):
self.Manages->forAll(m | self.Inputs->forAll(i | i <> m))
Tip
If the constraint is an “un-computable constraints that cannot, or cannot reasonably, be written in OCL” then the Specification Language should be set to “English”. The constaint is then known as an “Informal Proposition” and will appear as such in the documentation.
Using constraints for Validation¶
To use the OCL Validation tool of MagicDraw, the MagicDraw Architecte or Enterprise version must be used. For validating an OCL constraint, it should be stereotyped as validationRule.
An error message can be attached to a WR so it can be more easily identified and understood during validation.
Stereotype packages as validationSuite if they contain elements with constraints for validation, or elements to be validated.
Instances for TestData and Validation¶
Todo
how to add Instances.
Stereotype the TestData package and sub-packages as validationSuite
Validate the model¶
Launch the validation using the menu Analyse > Validation > Validate.
Then in the Validation dialog box, choose the Validation Suite as the top package containing the constraints to validate.
The results are displayed and can be used for navigation
Section author: Erwan Livolant [Boost Conseil]
Validation Syntax errors¶
The following are some syntax errors with some suggestions for the error.
Error | Suggested fix |
---|---|
No binary relational operation | Trying to compare where mulitplicity is “*” try e.g. self.InOrganization->excludes(self) |
Unsupported kind of expression | the “Constrained Element” has not been set for the constraint |
Section author: Judith Crockford (AP243)