10YearDresdenOCL-Model Validation in MagicDraw...

19
Applying OCL for Model Validation in MagicDraw UML D D i Šili Dr. Darius Šilingas Principal MagicDraw UML Trainer @ No Magic Europe

Transcript of 10YearDresdenOCL-Model Validation in MagicDraw...

Applying OCL for Model Validationpp y gin MagicDraw UML

D D i ŠiliDr. Darius ŠilingasPrincipal MagicDraw UML Trainer @ No Magic Europe

About MagicDraw UML

A visual UML modeling editorg

Domain-specific language (DSL) engine

Roundtrip code engineering for Java, C++, C#, …p g g , , ,

Modeling teamwork control system

Model documentation and report generation toolModel documentation and report generation tool

A modeling environment and model repository for Enterprise Architecture and Model Driven Architecture paradigmArchitecture and Model-Driven Architecture paradigm

Model validation engine using Dresden OCL Toolkit

Developed since 1998 – second oldest UML tool in the market!Sold in >70 countries, used in different business domainsWidely regarded as the most standard compliant UML tool

2

Widely regarded as the most standard-compliant UML tool

Disclaimer

I use term model validation because it is used in MagicDraw user interface and documentation manuals

In precise computer science terminology, I will discuss model verification since it is based on precisely defined rulesverification since it is based on precisely defined rules

Validate Verify

3

Model Validation: Correctness and Completeness

M d li lik i iModeling like programming is an error-prone process

A user model can be either incorrect (it breaks some rules) or incomplete (itA user model can be either incorrect (it breaks some rules) or incomplete (it lacks some required information)

Rules defined in UML specification are automated in MagicDraw

However a specific modeling method typically implies additional rulesHowever, a specific modeling method typically implies additional rulesRestriction to single generalization for classesCompulsory role names on navigable association endsEach use case must be documented with owned comment

MagicDraw provides a way to define validation rules and validate modelsMagicDraw provides a way to define validation rules and validate modelsValidation rules can be specified on OCL 2.0 or Java

4

MagicDraw Validation Profile

<<profile>>Validation Profile

A special validation suite that is always active in the background

<<stereotype>>activeValidationSuite

[Package]

<<stereotype>>validationSuite

[Package]

Provides grouping for

<<stereotype>>validationRule

[Package][Package]

<<enumeration>>SeverityKind

related validation rules so that they can

b i k d

abbreviation : String [0..1]errorMessage : String [0..1]severity : SeverityKind [1] = error

validationRule[Constraint]

warning

debug

error

info

SeverityKindbe invoked together

severity : SeverityKind [1] = errorimplementation : String [0..1]

errorfatal

Defines validation error significance levels

Provides rule specification, against which model must to be checked

5

Validation Rule Properties

<<metaclass>>Constraint

Defines meta-class, class or stereotype for which rule is applied

constrainedElement : Element [0..*]specification : ValueSpecification [1]

Constraint

Defines invariant specification in OCL 2

<<stereotype>>validationRule

Attributes for displaying and filtering validation

abbreviation : String [0..1]errorMessage : String [0..1]

validationRule[Constraint]

errors

severity : SeverityKind [1] = errorimplementation : String [0..1]

A special attribute for indicating operation or p g pclass in case the rule is specified in Java

6

Validation Suite vs. Active Validation Suite

Validation rules that are collected in a validation suite either by nesting or element import relationship are invoked by user

This is a typical case for model completeness validationThis is a typical case for model completeness validationValidation suite is re-initialized on every invocation

Validation rules that are collected in an active validation suiteare invoked automatically when user changes the modely g

This is a typical case for model correctness validationIt is implemented in an intelligent way so that they fire only when

frelevant changes in model are performedFor better performance, it is recommended to specify them in JavaActive validation suite is initialized at project load timeActive validation suite is initialized at project load time

7

Simple Model Validation Demo

8

A Case Study for Various Validation Rule Examples

1 An university needs a system MagicTest which automates test assessments1. An university needs a system MagicTest, which automates test assessments.2. Teachers specify and maintain questions.3. Each question must be applicable for 1 or more courses.4. A question can be closed or open.5. A closed question defines an ordered set of answer options, where at least one

answer option is correct and at least one is incorrectanswer option is correct and at least one is incorrect.6. An open question defines an expected correct answer.7. Teachers define tests for particular classes that they are running.p y g8. A test collects a number of questions.9. A test author also specifies test title, instructions, and allowed time.10. Students participate in test assessments by providing answers to test questions.11. MagicTest calculates test assessment evaluations.12 Data about teachers students courses and classes are provided by University12. Data about teachers, students, courses and classes are provided by University

Data System (UDS).

9

Validation Rules with Constrained Meta-Classes

COMPLETENESSEach use case must be documented with an owned comment

context UseCase inv UseCaseDocumentationownedComment->size()>0

CORRECTNESSEach action cannot have more than one incoming control flow

context Action inv SingleIncomingControlFlowcontext Action inv SingleIncomingControlFlowincoming->size()<2

10

Missing Use Case Documentation

Take Test Assessment<<documentation>>

Takes student through a test, prepared by teacher, collects student's answers and calculates test assessment grade.

Review Test

Student <<include>>

Assessment Evaluation

In MagicDraw UML the first owned comment is treated as “official” model element documentation.

11

Multiple Incoming Control FlowsSelect Assigned Test

Assessment

Display Test Instructions

Start Test Assessment

Register Test Assessment Start I will demonstrate later how to implement

an auto-resolution for this validation ruleDisplay Question

an auto resolution for this validation rule violations.

However, this must be done in Java as OCL is effect-free language and we need

Provide Answer at (timeout)

OCL is effect free language and we need to fix the model…

Register Answer

[more questions available]

End Test Assessment

Review Test

[no more questions available]

Review Test Assessment Evaluation

Validation Rules with Constrained Stereotypes

We will be using robustness analysis method, which requires a profile with stereotypes «boundary», «control», «entity»

CORRECTNESSBoundary components can use only boundary and control componentsBoundary components can use only boundary and control componentsControl components can use only control and entity componentsEntity components can use only entity componentsEntity components can use only entity components

context entity inv UseOnlyEntitiesclientDependency->forAll(cd | cd.supplier->forAll(s | s.oclIsKindOf(entity)))

13

Incorrect Dependency from Entity to Control

<<boundary>> <<entity>><<control>>boundaryTestAssessmentDialog

entityTestAssessment

controlTestService

<<boundary>>TestSetupDialog

t l

<<entity>>Test

<<boundary>>

<<control>>DataService

<<entity>>QuestionBrowser Question

MagicDraw provides DSL engine, which enables modelers to enforce such stereotype-specific rules without OCL

14

Validation Rules with Constraints on Classes

COMPLETENESS | CORRECTNESSA closed question defines an ordered set of answer options, where at least one answer option is correct and at least one is incorrectat least one answer option is correct and at least one is incorrect

15

Data Structure Design

author : Student [1]grade : Integer

TestAssessment

PREPAREDDRAFT

<<enumeration>>TestStatus author : Teacher [1]

assignedTo : Class [1]title : String

Test

IN PROGRESSASSIGNED

<<enumeration>>TestAssessmentStatus

1status1 1

test0..*

status11...PREPARED

EXPIREDACTIVE

title : Stringinstructions : String

...

IN_PROGRESS

COMPLETEDPAUSED

0..* 1

subjects : Course [1..*]author : Teacher [1]description : String

Questionregistered : date

Answerquestion1 0..*

questions {ordered}1..* {ordered}answers 0..*

ClosedQuestion{options->collect(correct)->includes(true) and�

description : String

expectedAnswer : StringOpenQuestion SelectionAnswer

input : StringInputAnswer

{opt o s co ect(co ect) c udes(t ue) a doptions->collect(correct)->includes(false)}

expectedAnswer : String input : String

AnswerOption

1options 2..*

1

statement : Stringcorrect : Boolean

selectedOptions1..*

16

Data Sample: Instance Specifications

author = Dariusquestions = Metaclasses, Diagrams

UML Basics : TestDarius : Teacher

q gstatus = ACTIVE

description = "UML2 defines ... metaclasses"Metaclasses : OpenQuestion

description = "UML2 defines ... diagrams"Diagrams : ClosedQuestion

M i D UML @ D d Cl

supervisor = DariusApplying UML 2 with MagicDraw : Course

pexpectedAnswer = "249"

p goptions = 7, 11

course = Applying UML 2 with MagicDrawinstructor = Dariuslocation = "Technical University Dresden"participants = Matthias

MagicDraw UML @ Dresden : Class

correct = false11 : AnswerOption

correct = false7 : AnswerOption

question = Metaclasses249 : InputAnswer

question = Diagrams11 : SelectionAnswerMatthias : Student

answers = 249, 11grade = 1status = COMPLETED

UML Basics by Matthias : TestAssessment

status = COMPLETEDtest = UML Basics

17

Ideas for Future OCL-Driven Features in MagicDraw

☺Update to the most recent version of Dresden OCL toolkit ☺Needs a bridge from MOF-based to EMF-based model

Integrate intelligent OCL editor into constraint specificationEasier specification and debugging of OCL 2 0 expressionsEasier specification and debugging of OCL 2.0 expressions

Support implicit model element relationship analysisSupport implicit model element relationship analysisSpecify criteria in OCL for dependency matrix and related elements finder

Generate code for operation bodies from OCL expressionsApplicable for query operations, test cases

18

Thank You for Attention!

?Questions? ?

Let’s Keep in Touch:Dr. Darius Šilingas

E-mail: [email protected]: darius.silingasPhone: +370 37 705899Phone: +370 37 705899

19