10YearDresdenOCL-Model Validation In MagicDraw [Kompatibilitätsmodus]

Transcription

Applyingpp y g OCL for Model Validationin MagicDraw UMLD DariusDr.D iŠiliŠilingasPrincipal MagicDraw UML Trainer @ No Magic Europe

About MagicDraw UMLA visual UML modelingg editorDomain-specific language (DSL) enginep code engineeringgg for Java,, C ,, C#,, RoundtripModeling teamwork control systemModel documentation and report generation toolA modeling environment and model repository for EnterpriseArchitecture and Model-DrivenModel Driven Architecture paradigmModel validation engine using Dresden OCL ToolkitDeveloped since 1998 – second oldest UML tool in the market!Sold in 70 countries, used in different business domainsWidely regarded as the most standardstandard-compliantcompliant UML tool2

DisclaimerI use term model validation because it is used in MagicDrawuser interface and documentation manualsIn precise computer science terminology, I will discuss modelverification since it is based on precisely defined rulesValidateVerify3

Model Validation: Correctness and CompletenessM d li likModelinglike programmingi iis an error-prone processA user model can be either incorrect (it breaks some rules) or incomplete (itlacks some required information)Rules defined in UML specification are automated in MagicDrawHowever a specific modeling method typically implies additional rulesHowever,Restriction to single generalization for classesCompulsory role names on navigable association endsEach use case must be documented with owned commentMagicDraw provides a way to define validation rules and validate modelsValidation rules can be specified on OCL 2.0 or Java4

MagicDraw Validation Profile profile A special validation suite that isalways active in the backgroundValidation ProfileProvidesgrouping forrelatedvalidation rulesso that they canb iinvokedbek dtogether stereotype validationSuite[Package] stereotype activeValidationSuite[Package] stereotype validationRule[Constraint] enumeration SeverityKindabbreviation : String [0.1]errorMessage : String [0.1]severity : SeverityKind [1] errorimplementation : String [0.1]Provides rule specification, against whichmodel must to be checkeddebuginfowarningerrorfatalDefines validation errorsignificance levels5

Validation Rule Properties metaclass ConstraintconstrainedElement : Element [0.*]specification : ValueSpecification [1] stereotype validationRule[Constraint]Defines meta-class, class or stereotype forwhich rule is appliedDefines invariant specification in OCL 2Attributes for displaying and filtering validationerrorsabbreviation : String [0.1]errorMessage : String [0.1]severity : SeverityKind [1] errorimplementation : String [0.1]A specialpattribute for indicatingg operationporclass in case the rule is specified in Java6

Validation Suite vs. Active Validation SuiteValidation rules that are collected in a validation suite either bynesting or element import relationship are invoked by userThis is a typical case for model completeness validationValidation suite is re-initialized on every invocationValidation rules that are collected in an active validation suiteare invoked automaticallyy when user changesg the modelThis is a typical case for model correctness validationIt is implemented in an intelligent way so that they fire only whenrelevant changes in model are performedfFor better performance, it is recommended to specify them in JavaActive validation suite is initialized at project load time7

Simple Model Validation Demo8

A Case Study for Various Validation Rule Examples11.2.3.4.5.An university needs a system MagicTestMagicTest, which automates test assessmentsassessments.Teachers specify and maintain questions.Each question must be applicable for 1 or more courses.A question can be closed or open.A closed question defines an ordered set of answer options, where at least oneanswer option is correct and at least one is incorrect.incorrect6. An open question defines an expected correct answer.7. Teachers define tests for pparticular classes that theyy are running.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,12.teachers students,students courses and classes are provided by UniversityData System (UDS).9

Validation Rules with Constrained Meta-ClassesCOMPLETENESSEach use case must be documented with an owned commentcontext UseCase inv UseCaseDocumentationownedComment- size() 0CORRECTNESSEach action cannot have more than one incoming control flowcontext Action inv SingleIncomingControlFlowincoming- size() 210

Missing Use Case DocumentationTake Test AssessmentStudent documentation Takes student through a test, prepared byteacher, collects student's answers andcalculates test assessment grade. include Review TestAssessment EvaluationIn MagicDraw UML the first owned comment is treated as“official” model element documentation.11

Multiple Incoming Control FlowsSelect Assigned TestAssessmentDisplay Test InstructionsStart Test AssessmentRegister TestAssessment StartDisplay QuestionProvide AnswerRegister Answer[more questions available][no more questions available]End Test AssessmentReview TestAssessment Evaluationat(timeout)I will demonstrate later how to implementan auto-resolutionauto resolution for this validation ruleviolations.However, this must be done in Java asOCL is effect-freeeffect free language and we needto fix the model

Validation Rules with Constrained StereotypesWe will be using robustness analysis method, which requires aprofile with stereotypes «boundary», «control», «entity»CORRECTNESSBoundary components can use only boundary and control componentsControl components can use only control and entity componentsEntity components can use only entity componentscontext entity inv UseOnlyEntitiesclientDependency- forAll(cd cd.supplier- forAll(s s.oclIsKindOf(entity)))13

Incorrect Dependency from Entity to Control boundary boundaryTestAssessmentDialog control controlTestService boundary TestSetupDialog entity entityTestAssessment entity Test control t lDataService boundary QuestionBrowser entity QuestionMagicDraw provides DSL engine, which enables modelers toenforce such stereotype-specific rules without OCL14

Validation Rules with Constraints on ClassesCOMPLETENESS CORRECTNESSA closed question defines an ordered set of answer options, whereat least one answer option is correct and at least one is incorrect15

Data Structure Design enumeration Teststatus1author : Teacher [1]1 assignedTo : Class [1]title : Stringinstructions : Stringtest10.*author : Student [1]grade : Integer.0.*questionssubjects : Course [1.*]author : Teacher [1]description : StringOpenQuestionexpectedAnswer : String1answers1.* {ordered}Questionquestion10.*0.* {ordered}Answerregistered : dateClosedQuestion{options- collect(correct)- includes(true){opto s co ect(co ect)c udes(t ue) aanddoptions- collect(correct)- includes(false)}1options1 enumeration status TestAssessmentStatus1 ASSIGNEDIN PROGRESSIN nput : String12.*AnswerOptionstatement : Stringcorrect : BooleanselectedOptions1.*16

Data Sample: Instance SpecificationsDarius : TeacherApplying UML 2 with MagicDraw : CourseUML Basics : Testauthor Dariusquestions Metaclasses, Diagramsqgstatus ACTIVEsupervisor DariusM i DMagicDrawUML @ DDresdend : ClClasscourse ApplyingUML 2 with MagicDrawinstructor Dariuslocation "Technical University Dresden"participants MatthiasMatthias : StudentMetaclasses : OpenQuestionDiagrams : ClosedQuestiondescriptionp "UML2 defines . metaclasses"expectedAnswer "249"descriptionp "UML2 defines . diagrams"goptions 7, 117 : AnswerOptioncorrect false249 : InputAnswerquestion Metaclasses11 : AnswerOptioncorrect false11 : SelectionAnswerquestion DiagramsUML Basics by Matthias : TestAssessmentanswers 249, 11grade 1status COMPLETEDtest UMLBasics17

Ideas for Future OCL-Driven Features in MagicDrawUpdate to the most recent version of Dresden OCL toolkit Needs a bridge from MOF-based to EMF-based modelIntegrate intelligent OCL editor into constraint specificationEasier specification and debugging of OCL 22.00 expressionsSupport implicit model element relationship analysisSpecify criteria in OCL for dependency matrix and related elements finderGenerate code for operation bodies from OCL expressionsApplicable for query operations, test cases18

Thank You for Attention!Questions?Let’s Keep in Touch:Dr. Darius ŠilingasE-mail: darius.silingas@nomagic.comSkype: darius.silingasPhone: 370 37 70589919

In MagicDraw UML the first owned comment is treated as "official" model element documentation. 11. Multiple Incoming Control Flows Select Assigned Test Assessment Display Test Instructions Start Test Assessment Register Test Assessment Start I will demonstrate later how to implement