How to model constraints for use in validation

Warning

../../_images/construction.png

This page is under construction.

To contribute or participate contact support@boost-lab.net

Step by Step guide

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

display of constraints on BDD - only the name

../../_images/ht_vc_showname.png

Figure 40 set “Constraint Text mode” to “Name”

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.

../../_images/ht_vc_constraintStereotype.png

Figure 41 Stereotype constraints as validationRule

An error message can be attached to a WR so it can be more easily identified and understood during validation.

../../_images/ht_vc_constraintErrorMsg.png

Figure 42 Add an error message string

Stereotype packages as validationSuite if they contain elements with constraints for validation, or elements to be validated.

../../_images/ht_vc_validationSuite.png

Figure 43 Stereotype packages as validationSuite

Instances for TestData and Validation

Todo

how to add Instances.

Stereotype the TestData package and sub-packages as validationSuite

../../_images/ht_vc_validationSuite.png

Figure 44 Stereotype packages as validationSuite

Validate the model

Launch the validation using the menu Analyse > Validation > Validate.

../../_images/ht_vc_validate01.png

Figure 45 Launch Validation

Then in the Validation dialog box, choose the Validation Suite as the top package containing the constraints to validate.

../../_images/ht_vc_validate02.png

Figure 46 Select Validation Suite

The results are displayed and can be used for navigation

../../_images/ht_vc_validate03.png

Figure 47 Validation Results

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)