StarUML model validation using Schematron

Main benefits of Continuous Integration practice are improved quality and team communication. The former is achieved by automated compilation with testing and the latter by publishing the results. Nowadays successful building any bigger system is not possible without both.

In one of my recent posts I presented how to transform StarUML model to XML Schema outside the tool. Implementation dependant model generation corresponds to compilation. Testing can be implemented as validation. In this case literal and structural analysis of UML file is fairly simple owing to its XML format.

There is nothing to invent – there is an ISO standard also known as Schematron. It is simple language that defines rules of assertions that are applicable in specific document context. Conditions are written in pluggable expression languages – XPath is default one. Default implementation of the standard compiles tests into XSLT stylesheet and then executes against a document.

Model will be verified on three levels - document conformance (if it is StarUML document), model quality (defined for model itself) and transformation profile constraints (schema in that case). List of rules (not planned as complete):

  1. Document conformance
  2. Model general quality
    • class cannot extend itself
    • abstract classes should have abstract prefix
    • class name should be longer than 5 chars (after dropping abstract prefix)
    • attribute must have defined type
    • attribute must have defined multiplicity
  3. Schema transformation profile
    • class must extend one class at most

First point of the list looks as follow:

  <sch:title>Verifying StarUML document conformance</sch:title>
  <sch:rule context="/" id="document-conformance" role="fatal">
    <sch:assert test="XPD:PROJECT[@version='1']/XPD:BODY">
      Document not conforms StarUML structure of version 1

And point three:

    Validating constraints for schema transformation profile - non multiple extending
  <sch:rule id="xsd-profile.single-extending"
      context="XPD:OBJ[@type='UMLClass' and child::XPD:ATTR[@name='#Generalizations']]">
      test="XPD:ATTR[@name='#Generalizations'] and XPD:ATTR[@name='#Generalizations']='1'">
      Class <sch:value-of select="XPD:ATTR[@name='Name']"/> must not extend more than one class
      (but extends <sch:value-of select="XPD:ATTR[@name='#Generalizations']"/>)

To test out implemented Schematron rules I prepared the worst model I can as pictured below.

Incorrect class diagram

When no includes nor abstract rules is used execution has two phases - validator compilation and validation itself. Apache Ant target controlling this process looks as follow:

<target name="validation-of-model">
  <!-- compilation -->
    <factory name="net.sf.saxon.TransformerFactoryImpl" />
  <!-- validation -->
    <factory name="net.sf.saxon.TransformerFactoryImpl" />

Result is saved in XML document that shows fired rules, assertion results in schematron document sequence order. Adding simple XSLT allow to generate nice looking report. Using xmltask I described few days ago you can simply signal if there is any error.

Complete example you can download from my files site.

2 komentarze:

Anonymous said...

Sports Betting at Safest Betting Sites in Israel - Airjordan10 RetroOutlet
Safest where to buy air jordan 18 retro racer blue Betting Sites in Israel air jordan 18 stockx outlet · The Best and Best Betting Sites in the UK · 운명 도메인 The UK's Hottest Bookmakers how can i find jordan 18 white royal blue · Betfair Sports Betting air jordan 18 retro on sale Authority · Betfair

Anonymous said...

Sign up now to get the inside scoop on the most recent bonus presents. As a general rule, it’s finest to stay with sites that use well-known 온라인 카지노 and trusted software builders. Slot machines may be be} held for as much as} 5 minutes, solely if you have notified a slot employee and there are no credit left on the machine. All about action, our High-Limit Slots allow you to play the widest variety of new and classic high-limit machines. Just off the main floor, The Enclave is final word|the final word} experience in lounge luxury.

Post a Comment