Running OCL queries

There are two ways to run an OCL query in the OCLEditor. The first one allows navigation from the model element to the associated query which is shown in this flash tutorial.

The second one allows navigation from the OCL query to the model element and is stated in this section.
Open the file querylib.oclx in the OCL editor if you do not already have it open.

  1. Select numberOfAttributes query in the Outline view.
  2. Select Evaluate Query(ies) from the context menu., select the model on which you want to run the query (models.new_file.uml) and finally select the model element.(Class:C1, Class::C2)

    Run test

     

  3. The result of the query appears in the Console view:

    Test result

    The first line in the Console View shows the result of evaluation on Class::C1, the rest of evaluation on Class::C2.

    As expected, the message part of the query is printed to the console: Evaluating the query on Class::C1 results in false, because the trigger evaluates to false. The trigger of evaluating on Class::C2 results in true, so the message is printed out.

Related reference