source: mauRepo/NewmoonJSP/src/main/webapp/WEB-INF/rules/conformance-test/ISO19136-V3.2-AnxE_XMI-V1.1/test-018.xq @ 7841

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/NewmoonJSP/src/main/webapp/WEB-INF/rules/conformance-test/ISO19136-V3.2-AnxE_XMI-V1.1/test-018.xq@7841
Revision 7841, 4.5 KB checked in by mnagni, 10 years ago (diff)
Line 
1xquery version "1.0";
2(:~~~~~~~~~~~~~~~~~~~~~~~~~~ Conformance Test  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3Test Number:    018
4Description:    Every tagged value in the model is on the correct model
5                                element type and stereotype.
6Reference:              ISO 19136 Table E.2.
7
8#Update:        2009-08-11
9#Author:        Pavel Golodoniuc
10#Note:          Ported to eXist v1.2.x (production release).
11~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~:)
12
13import module namespace mod-fr = "urn:local-module:ISO19136-V3.2-AnxE_XMI-V1.1:framework"
14at "xmldb:exist:///db/modules/conformance-test/ISO19136-V3.2-AnxE_XMI-V1.1/module-framework-functions.xq";
15
16import module namespace mod-xp = "urn:local-module:ISO19136-V3.2-AnxE_XMI-V1.1:xmi-proc"
17at "xmldb:exist:///db/modules/conformance-test/ISO19136-V3.2-AnxE_XMI-V1.1/module-xproc-functions.xq";
18
19declare namespace UML   = "omg.org/UML1.3";
20declare namespace cr    = "http://ndg.service.newmoon.conftest-result/1.0";
21
22(: Declare local variables, particular to this test :)
23declare variable $test-num as xs:integer := 18;
24declare variable $pass-msg as xs:string := "Every tagged value in the model is used on the correct model element type and stereotype.";
25declare variable $fail-msg as xs:string := "WARNING: Some tagged values in the model have no effect where they are found:";
26
27(:
28        #Date:          2009-01-14
29        #Author:        Pavel Golodoniuc
30
31        Declare the local assert function which defines a postive condition for pass.
32:)
33declare function local:assert($doc-root as node()?) as node()?
34{
35        let
36                $fail := (
37                        local:assert-tagged-values(("xsdDocument"), ("UML:Package", "UML:ClassifierRole"), ()),
38                        local:assert-tagged-values(("targetNamespace", "xmlns", "gmlProfileSchema"), ("UML:Package"), ("Application Schema", "applicationSchema")),
39                        local:assert-tagged-values(("noPropertyType", "byValuePropertyType", "isCollection"), ("UML:Class"), ()),
40                        local:assert-tagged-values(("asDictionary"), ("UML:Class"), ("CodeList", "codeList")),
41                        local:assert-tagged-values(("xmlSchemaType"), ("UML:Class"), ("Type", "type")),
42                        local:assert-tagged-values(("sequenceNumber", "inlineOrByReference", "isMetadata"), ("UML:Attribute", "UML:AssociationEnd"), ())
43                )
44        return
45                if (empty($fail)) then ()
46                else
47                        <cr:fail>
48                                <cr:messages>{ $fail }</cr:messages>
49                        </cr:fail>
50};
51
52(:
53        #Date:          2009-01-14
54        #Author:        Pavel Golodoniuc
55
56        Assert that tagged values belong to respective elements in the model.
57:)
58declare function local:assert-tagged-values($tags as xs:string*, $expected-owner as xs:string*, $expected-stereotype as xs:string*) as node()*
59{
60        for $tag in (/XMI/XMI.content/UML:TaggedValue[@tag = $tags] | //UML:ModelElement.taggedValue/UML:TaggedValue[@tag = $tags])
61        let $owner              := local:get-tagged-value-owner($tag),
62                $stereotype     := if (count($owner) eq 1) then local:get-element-stereotype($owner) else (),
63
64                $el-verbal := (
65                        if (count($owner) ne 1) then ()
66                        else if (name($owner) eq "UML:Association") then
67                                mod-xp:verbose-association($owner)
68                        else if (name($owner) eq "UML:AssociationEnd") then
69                                concat("association end &quot;", $owner/@name, "&quot; of the ", mod-xp:verbose-association($owner/../..))
70                        else if (name($owner) eq "UML:Generalization") then
71                                mod-xp:verbose-generalization($owner)
72                        else
73                                concat("element ", name($owner), " &quot;", $owner/@name, "&quot;")
74                )
75        where
76                count($owner) eq 1 and
77                name($owner) ne "UML:Model" and
78                (
79                        not(name($owner) = $expected-owner) or
80                        not(empty($expected-stereotype) or $stereotype = $expected-stereotype)
81                )
82        return <cr:message>{ concat("Tagged value &quot;", $tag/@tag, "&quot; is not expected on the ", $el-verbal, ".") }</cr:message>
83};
84
85(:
86        #Date:          2009-01-14
87        #Author:        Pavel Golodoniuc
88
89        Return the owner of the specified tagged value.
90:)
91declare function local:get-tagged-value-owner($tag as node()) as node()*
92{
93        if (local-name($tag/..) eq "XMI.content") then
94                //*[@xmi.id eq $tag/@modelElement]
95        else
96                $tag/../..
97};
98
99(:
100        #Date:          2009-01-14
101        #Author:        Pavel Golodoniuc
102
103        Return the stereotype of the specified model element.
104:)
105declare function local:get-element-stereotype($el as node()) as xs:string?
106{
107        let $stereotype := $el/UML:ModelElement.stereotype/UML:Stereotype
108        return
109                if ($stereotype/@name) then
110                        $stereotype/string(@name)
111                else
112                        /XMI/XMI.content/UML:Model/UML:Namespace.ownedElement/UML:Stereotype[@xmi.id eq $stereotype/@xmi.idref]/string(@name)
113};
114
115(: Create a new result element :)
116mod-fr:new-result($test-num, $pass-msg, $fail-msg, local:assert(/))
Note: See TracBrowser for help on using the repository browser.