Page last modified 14:46, 8 Jan 2018 by Antero

B - Advanced 1 - Modifying validation rule definition

    Purpose

    Purpose of this task is to introduce modification of the definition of validation rule.

    Description

    Following steps are done here:

    1. Creating a new validation rule(Tx/Id must be value "Id1") 
    2. Modifying OCL in an existing validation rule(Tx/Id must be value "Id1" or "Id2")
    3. Compiling project and testing

    Instructions

    1: Creating a new validation rule (Tx/Id must be value "Id1") 

    We start by using the dropdown menu to generate OCL code automatically, as done in basics section. We'll have to find the relevenat element (Transaction/Id), press the down-icon, select value restriction and write the value we want to limit this element to be ("Id1").

     

    2: Modifying OCL in an existing validation rule(Tx/Id must be value "Id1" or "Id2")

    This phase requires us to look at the generated OCL code for the rule we have just made. We'll open the rule by double clicking it. Definition section will contain following:

    Context: TransactionType1
    Definition: self.Id.matches("Id1")
    

    OCL allows us to use following logical operators: and, or, xor, not(), implies

    In this case, as we want to make either value Id1 or Id2 valid to be used, we'll have to use operator or between the valid values. We can use the existing defition as our basis for completing the OCL to be as follows:

    self.Id.matches("Id1") or self.Id.matches("Id2")
    

    3: Compiling project and testing

    Finally, we can test the implementation. Our test should include both values "Id1" and "Id2" to be in the XML file.

    During the test, we should be able to take notice that the error message is invalid, as it only refers to "Id1" even though the rule itself allows both values.

    4: Modifying error message

    To make rule to be valid, we shall modify error message to match the rule definition. It is important to keep in mind that error messages are generated at the point when rule is generated, but error messages are not automatically changed when changes are made within rule.

     

    Menu