source: mauRepo/NewmoonJSP/src/main/webapp/WEB-INF/rules/conformance-test/ISO19136-V3.2-AnxE_XMI-V1.1/test-004.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-004.xq@7841
Revision 7841, 4.4 KB checked in by mnagni, 10 years ago (diff)
Line 
1xquery version "1.0";
2(:~~~~~~~~~~~~~~~~~~~~~~~~~~ Conformance Test  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3Test Number:    004
4Description:    Asserts the existence of non-null values for both the
5                                "targetNamespace" and "xmlns" tagged values on the target
6                                Application Schema package.
7Reference:             
8
9#Update:        2009-08-11
10#Author:        Pavel Golodoniuc
11#Note:          Ported to eXist v1.2.x (production release).
12~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~:)
13
14import module namespace mod-fr = "urn:local-module:ISO19136-V3.2-AnxE_XMI-V1.1:framework"
15at "xmldb:exist:///db/modules/conformance-test/ISO19136-V3.2-AnxE_XMI-V1.1/module-framework-functions.xq";
16
17import module namespace mod-xp = "urn:local-module:ISO19136-V3.2-AnxE_XMI-V1.1:xmi-proc"
18at "xmldb:exist:///db/modules/conformance-test/ISO19136-V3.2-AnxE_XMI-V1.1/module-xproc-functions.xq";
19
20declare namespace UML   = "omg.org/UML1.3";
21declare namespace cr    = "http://ndg.service.newmoon.conftest-result/1.0";
22
23(: Declare local variables, particular to this test :)
24declare variable $test-num as xs:integer := 4;
25declare variable $pass-msg as xs:string := "The Application Schema does have one "targetNamespace" and one "xmlns" tagged-values, AND their values are syntactically correct.";
26declare variable $fail-msg as xs:string := "The test has failed bacause:";
27
28(:
29        #Date:          2008-12-02
30        #Author:        Pavel Golodoniuc
31
32        Declare the local assert function which defines a postive condition for pass.
33:)
34declare function local:assert($doc-root as node()?) as node()?
35{
36        let
37                $tns            := local:get-package-tag($doc-root, "targetNamespace"),
38                $xmlns          := local:get-package-tag($doc-root, "xmlns"),
39
40                $fail := (
41                        local:check-cardinality($tns, "targetNamespace"),
42                        local:check-cardinality($xmlns, "xmlns"),
43
44                        (: "targetNamespace" tagged value must be either URI or URN :)
45                        if (count($tns) eq 1) then
46                        (
47                                let $tns := mod-xp:extract-value-from-tagval($tns)
48                                return
49                                        if (mod-xp:is-uri-valid($tns) or mod-xp:is-urn-valid($tns)) then ()
50                                        else
51                                                <cr:message>{ concat("The targetNamespace=&quot;", $tns, "&quot; tagged-value is neither a URI nor a URN.") }</cr:message>
52                        )
53                        else (),
54
55                        (: "xmlns" tagged value must be a xsd:NCName :)
56                        if (count($xmlns) eq 1) then
57                        (
58                                let $xmlns := mod-xp:extract-value-from-tagval($xmlns)
59                                return
60                                        if (mod-xp:is-xsd-ncname-valid($xmlns)) then ()
61                                        else
62                                                <cr:message>{ concat("The xmlns=&quot;", $xmlns, "&quot; tagged-value is NOT a xsd:NCName.") }</cr:message>
63                        )
64                        else ()
65                )
66        return
67                if (empty($fail)) then ()
68                else
69                        <cr:fail>
70                                <cr:messages>{ $fail }</cr:messages>
71                        </cr:fail>
72};
73
74(:
75        #Date:          2008-12-02
76        #Author:        Pavel Golodoniuc
77
78        Retrieve all specified tag value assigned to or inherited by the package.
79:)
80declare function local:get-package-tag($doc-root as node()?, $tag as xs:string) as node()*
81{
82        let $pkg-node                   := mod-xp:get-target-app-schema($doc-root),
83            $pkg-id                             := $pkg-node[1]/string(@xmi.id),
84
85                (: Check for direct descendent tagged values :)
86            $tag-descendent             := $pkg-node/UML:ModelElement.taggedValue/UML:TaggedValue[@tag eq $tag]/@value,
87
88                (: If package is first package of model, tagged values may be linked to model element id :)
89            $first-pck-id               := ($doc-root//UML:Package)[1]/string(@xmi.id),
90            $tag-inherited              := (
91                        if ($pkg-id ne $first-pck-id) then ()
92                        else
93                                let $model-id := ($doc-root/XMI/XMI.content/UML:Model)[1]/@xmi.id
94                                return $doc-root/XMI/XMI.content/UML:TaggedValue[@modelElement eq $model-id][@tag eq $tag]/@value
95                ),
96
97                (: Tagged values may be linked to the package element id :)
98            $tag-linked                 := $doc-root/XMI/XMI.content/UML:TaggedValue[@modelElement eq $pkg-id][@tag eq $tag]/@value
99
100        return ($tag-descendent, $tag-inherited, $tag-linked)
101};
102
103(:
104        #Date:          2008-12-02
105        #Author:        Pavel Golodoniuc
106
107        Checks that cardinality of the input nodeset is exactly one.
108:)
109declare function local:check-cardinality($nodes as node()*, $tag as xs:string) as node()*
110{
111        if (empty($nodes)) then
112        (
113                <cr:message>{ concat("The Application Schema does NOT have one &quot;", $tag, "&quot; tagged-value.") }</cr:message>
114        )
115        else if (count($nodes) gt 1) then
116        (
117                <cr:message>{ concat("The Application Schema has MORE THAN one &quot;", $tag, "&quot; tagged-value.") }</cr:message>
118        )
119        else ()
120};
121
122(: Create a new result element :)
123mod-fr:new-result($test-num, $pass-msg, $fail-msg, local:assert(/))
Note: See TracBrowser for help on using the repository browser.