1 | ;;+----------------------------------------------------------------------------- |
---|
2 | ;;+ Isidorus |
---|
3 | ;;+ (c) 2008-2009 Marc Kuester, Christoph Ludwig, Lukas Giessmann |
---|
4 | ;;+ |
---|
5 | ;;+ Isidorus is freely distributable under the LGPL license. |
---|
6 | ;;+ You can find a detailed description in trunk/docs/LGPL-LICENSE.txt. |
---|
7 | ;;+----------------------------------------------------------------------------- |
---|
8 | |
---|
9 | |
---|
10 | (defpackage :atom-test |
---|
11 | (:use |
---|
12 | :common-lisp |
---|
13 | :datamodel |
---|
14 | :it.bese.FiveAM |
---|
15 | :fixtures |
---|
16 | :atom |
---|
17 | :xml-tools |
---|
18 | :cxml |
---|
19 | :unittests-constants) |
---|
20 | (:import-from :constants |
---|
21 | *atom-ns* |
---|
22 | *xtm2.0-ns*) |
---|
23 | (:import-from :xml-tools |
---|
24 | xpath-child-elems-by-qname |
---|
25 | xpath-select-location-path) |
---|
26 | (:import-from :exceptions |
---|
27 | missing-reference-error |
---|
28 | duplicate-identifier-error) |
---|
29 | (:export :atom-test |
---|
30 | :test-feed-to-string |
---|
31 | :test-collection-configuration |
---|
32 | :test-changes-feeds |
---|
33 | :run-atom-tests)) |
---|
34 | |
---|
35 | ;test configuration |
---|
36 | (in-package :atom-test) |
---|
37 | |
---|
38 | (def-suite atom-test :description "Tests for the Atom interface") |
---|
39 | (in-suite atom-test) |
---|
40 | |
---|
41 | ;; (test test-snapshots () |
---|
42 | ;; "test the behaviour of the snapshot feed" |
---|
43 | ;; (with-fixture merge-test-db () |
---|
44 | ;; (let* |
---|
45 | ;; ((feed-string |
---|
46 | ;; (snapshot-feed-to-string)) |
---|
47 | ;; (feed-dom |
---|
48 | ;; (cxml:parse feed-string (cxml-dom:make-dom-builder))) |
---|
49 | ;; (feed-elem (dom:document-element feed-dom))) |
---|
50 | ;; ;very initial test |
---|
51 | ;; (is (= 3 (length (xpath-child-elems-by-qname feed-elem *atom-ns* "entry"))))))) |
---|
52 | |
---|
53 | (test test-feed-to-string () |
---|
54 | (with-fixture atom-test-db () |
---|
55 | (let* |
---|
56 | ((worms-feed |
---|
57 | (find "http://psi.egovpt.org/tm/worms" |
---|
58 | (atom:subfeeds atom:*tm-feed*) |
---|
59 | :test #'string= |
---|
60 | :key #'atom:id)) |
---|
61 | (datetime-revision3 |
---|
62 | (atom::datetime-in-iso-format fixtures::revision3)) |
---|
63 | (datetime-revision1 |
---|
64 | (atom::datetime-in-iso-format fixtures::revision1)) |
---|
65 | (collection-feed-string |
---|
66 | (format nil "<a:feed xmlns:a=\"http://www.w3.org/2005/Atom\" xmlns:e=\"http://www.egovpt.org/sdshare/\"><a:title>Topicmaps on psi.egovpt.org</a:title><a:id>http://london.ztt.fh-worms.de:8000/feeds</a:id><a:author><a:name>Isidor</a:name></a:author><a:link href=\"http://london.ztt.fh-worms.de:8000/feeds\" rel=\"self\"></a:link><a:updated>~a</a:updated><a:entry xmlns:a=\"http://www.w3.org/2005/Atom\" xmlns:e=\"http://www.egovpt.org/sdshare/\"><a:title>Data behind the portal of the city of Worms</a:title><a:id>http://psi.egovpt.org/tm/worms/entry</a:id><a:link href=\"http://london.ztt.fh-worms.de:8000/feeds/worms\" rel=\"alternate\"></a:link><a:link href=\"http://london.ztt.fh-worms.de:8000/feeds/worms\" rel=\"alternate\" type=\"application/atom+xml\"></a:link><a:author><a:name>Isidor</a:name></a:author><a:link href=\"http://london.ztt.fh-worms.de:8000/feeds/worms\" rel=\"http://www.egovpt.org/sdshare/collectionfeed\" type=\"application/atom+xml\"></a:link><a:updated>~a</a:updated></a:entry><a:entry xmlns:a=\"http://www.w3.org/2005/Atom\" xmlns:e=\"http://www.egovpt.org/sdshare/\"><a:title>eGov Reference Ontology</a:title><a:id>http://psi.egovpt.org/tm/egov-ontology/entry</a:id><a:link href=\"http://london.ztt.fh-worms.de:8000/feeds/egov-ontology\" rel=\"alternate\"></a:link><a:link href=\"http://london.ztt.fh-worms.de:8000/feeds/egov-ontology\" rel=\"alternate\" type=\"application/atom+xml\"></a:link><a:author><a:name>Isidor</a:name></a:author><a:link href=\"http://london.ztt.fh-worms.de:8000/feeds/egov-ontology\" rel=\"http://www.egovpt.org/sdshare/collectionfeed\" type=\"application/atom+xml\"></a:link><a:updated>~a</a:updated></a:entry></a:feed>" datetime-revision3 datetime-revision3 datetime-revision1)) |
---|
67 | (worms-feed-string |
---|
68 | (format nil "<a:feed xmlns:a=\"http://www.w3.org/2005/Atom\" xmlns:e=\"http://www.egovpt.org/sdshare/\"><a:title>Data behind the portal of the city of Worms</a:title><a:id>http://london.ztt.fh-worms.de:8000/feeds/worms</a:id><a:author><a:name>Isidor</a:name></a:author><a:link href=\"http://london.ztt.fh-worms.de:8000/feeds/worms\" rel=\"self\"></a:link><e:dependency>http://london.ztt.fh-worms.de:8000/feeds/egov-ontology</e:dependency><a:updated>~a</a:updated><a:entry xmlns:a=\"http://www.w3.org/2005/Atom\" xmlns:e=\"http://www.egovpt.org/sdshare/\"><a:title>Snapshots of the Worms data</a:title><a:id>http://psi.egovpt.org/tm/worms/snapshots/entry</a:id><a:link href=\"http://london.ztt.fh-worms.de:8000/feeds/worms/snapshots\" rel=\"alternate\"></a:link><a:link href=\"http://london.ztt.fh-worms.de:8000/feeds/worms/snapshots\" rel=\"http://www.egovpt.org/sdshare/snapshotsfeed\" type=\"application/atom+xml\"></a:link><a:updated>~a</a:updated></a:entry><a:entry xmlns:a=\"http://www.w3.org/2005/Atom\" xmlns:e=\"http://www.egovpt.org/sdshare/\"><a:title>A list of all change fragments for the Worms data</a:title><a:id>http://psi.egovpt.org/tm/worms/fragments/entry</a:id><a:link href=\"http://london.ztt.fh-worms.de:8000/feeds/worms/fragments\" rel=\"alternate\"></a:link><a:link href=\"http://london.ztt.fh-worms.de:8000/feeds/worms/fragments\" rel=\"http://www.egovpt.org/sdshare/fragmentsfeed\" type=\"application/atom+xml\"></a:link><a:updated>~a</a:updated></a:entry></a:feed>" datetime-revision3 datetime-revision3 datetime-revision3))) |
---|
69 | (is |
---|
70 | (string= |
---|
71 | collection-feed-string |
---|
72 | (cxml:with-xml-output |
---|
73 | (cxml:make-string-sink :canonical t) |
---|
74 | (atom:feed-to-elem atom:*tm-feed*)))) |
---|
75 | (is (eq 'atom::collection-feed (type-of worms-feed))) |
---|
76 | (is |
---|
77 | (string= |
---|
78 | worms-feed-string |
---|
79 | (cxml:with-xml-output |
---|
80 | (cxml:make-string-sink :canonical t) |
---|
81 | (atom:feed-to-elem worms-feed)))) |
---|
82 | ))) |
---|
83 | |
---|
84 | (test test-changes-feeds () |
---|
85 | "test the snapshots and fragments feeds" |
---|
86 | (with-fixture atom-test-db () |
---|
87 | (let* |
---|
88 | ((worms-feed |
---|
89 | (find "http://psi.egovpt.org/tm/worms" |
---|
90 | (atom:subfeeds atom:*tm-feed*) |
---|
91 | :test #'string= |
---|
92 | :key #'atom:id)) |
---|
93 | (ont-feed |
---|
94 | (find "http://psi.egovpt.org/tm/egov-ontology" |
---|
95 | (atom:subfeeds atom:*tm-feed*) |
---|
96 | :test #'string= |
---|
97 | :key #'atom:id)) |
---|
98 | (fragments-feed |
---|
99 | (find 'atom::fragments-feed |
---|
100 | (atom:subfeeds worms-feed) |
---|
101 | :key #'type-of)) |
---|
102 | (snapshots-feed |
---|
103 | (find 'atom::snapshots-feed |
---|
104 | (atom:subfeeds worms-feed) |
---|
105 | :key #'type-of))) |
---|
106 | |
---|
107 | (format t "~a~%~%~a~%" fragments-feed (map 'list #'atom::psi (atom:entries fragments-feed))) |
---|
108 | (is (= 11 (length (atom:entries fragments-feed)))) |
---|
109 | (is (string= "http://london.ztt.fh-worms.de:8000/feeds/worms/fragments" |
---|
110 | (link fragments-feed))) |
---|
111 | (is (string= "http://london.ztt.fh-worms.de:8000/feeds/worms/snapshots" |
---|
112 | (link snapshots-feed))) |
---|
113 | |
---|
114 | (format t "~a" (cxml:with-xml-output |
---|
115 | (cxml:make-string-sink :canonical t) |
---|
116 | (atom::feed-to-elem fragments-feed))) |
---|
117 | (is (= 3 (length (atom:entries snapshots-feed)))) |
---|
118 | |
---|
119 | ;;cross check against ontology feed (no changes there and |
---|
120 | ;;only one snapshot) |
---|
121 | (assert ont-feed) |
---|
122 | (is (= 0 (length |
---|
123 | (atom:entries |
---|
124 | (find 'atom::fragments-feed |
---|
125 | (atom:subfeeds ont-feed) |
---|
126 | :key #'type-of))))) |
---|
127 | (is (= 1 (length |
---|
128 | (atom:entries |
---|
129 | (find 'atom::snapshots-feed |
---|
130 | (atom:subfeeds ont-feed) |
---|
131 | :key #'type-of))))) |
---|
132 | (format t "~a" |
---|
133 | (cxml:with-xml-output |
---|
134 | (cxml:make-string-sink :canonical t) |
---|
135 | (atom:feed-to-elem snapshots-feed))) |
---|
136 | ))) |
---|
137 | |
---|
138 | (test test-collection-configuration () |
---|
139 | "test the configuration reader" |
---|
140 | (with-fixture atom-test-db () |
---|
141 | (let |
---|
142 | ((collection-feeds (atom:subfeeds atom:*tm-feed*)) |
---|
143 | (collection-entries (atom:entries atom:*tm-feed*))) |
---|
144 | (is (= 2 (length collection-feeds))) |
---|
145 | (is (= 2 (length collection-entries))) |
---|
146 | (is (string= "psi.egovpt.org" (atom:id atom:*tm-feed*))) |
---|
147 | |
---|
148 | ;;id-test for feeds |
---|
149 | (is-false |
---|
150 | (set-exclusive-or |
---|
151 | '("http://psi.egovpt.org/tm/egov-ontology" |
---|
152 | "http://psi.egovpt.org/tm/worms" ) |
---|
153 | (mapcar #'atom:id collection-feeds) :test #'string=)) |
---|
154 | |
---|
155 | ;;id-test for entries |
---|
156 | ;!!!! |
---|
157 | (is-false |
---|
158 | (set-exclusive-or |
---|
159 | '("http://psi.egovpt.org/tm/egov-ontology/entry" |
---|
160 | "http://psi.egovpt.org/tm/worms/entry" ) |
---|
161 | (mapcar #'atom:id collection-entries) :test #'string=)) |
---|
162 | |
---|
163 | |
---|
164 | ;;test relative paths for feeds |
---|
165 | (is-false |
---|
166 | (set-exclusive-or |
---|
167 | '("feeds/egov-ontology" |
---|
168 | "feeds/worms") |
---|
169 | (mapcar #'atom:path collection-feeds) :test #'string=)) |
---|
170 | |
---|
171 | ;;test relative paths for entries (the same as for feeds) |
---|
172 | (is-false |
---|
173 | (set-exclusive-or |
---|
174 | '("feeds/egov-ontology" |
---|
175 | "feeds/worms") |
---|
176 | (mapcar #'atom:path collection-entries) :test #'string=)) |
---|
177 | |
---|
178 | ;;test self links for feeds |
---|
179 | (is-false |
---|
180 | (set-exclusive-or |
---|
181 | '("http://london.ztt.fh-worms.de:8000/feeds/egov-ontology" |
---|
182 | "http://london.ztt.fh-worms.de:8000/feeds/worms") |
---|
183 | (mapcar #'atom:link collection-feeds) :test #'string=)) |
---|
184 | ;;test alternate links for entries (the same as the one of |
---|
185 | ;;the feed they point to) |
---|
186 | (is-false |
---|
187 | (set-exclusive-or |
---|
188 | '("http://london.ztt.fh-worms.de:8000/feeds/egov-ontology" |
---|
189 | "http://london.ztt.fh-worms.de:8000/feeds/worms") |
---|
190 | (mapcar #'atom:link collection-entries) :test #'string=)) |
---|
191 | |
---|
192 | ;;test dependencies |
---|
193 | (is-false |
---|
194 | (set-exclusive-or |
---|
195 | '(() ("http://london.ztt.fh-worms.de:8000/feeds/egov-ontology")) |
---|
196 | (mapcar #'atom:dependency collection-feeds) :test #'equal)) |
---|
197 | |
---|
198 | ;;test types for feeds |
---|
199 | (is-false |
---|
200 | (set-exclusive-or |
---|
201 | '(atom::collection-feed |
---|
202 | atom::collection-feed) |
---|
203 | (mapcar #'type-of collection-feeds))) |
---|
204 | |
---|
205 | ;;test types for entries |
---|
206 | (is-false |
---|
207 | (set-exclusive-or |
---|
208 | '(atom::overview-entry |
---|
209 | atom::overview-entry) |
---|
210 | (mapcar #'type-of collection-entries))) |
---|
211 | ))) |
---|
212 | |
---|
213 | |
---|
214 | (defun run-atom-tests() |
---|
215 | (it.bese.fiveam:run! 'test-feed-to-string) |
---|
216 | (it.bese.fiveam:run! 'test-changes-feeds) |
---|
217 | (it.bese.fiveam:run! 'test-collection-configuration)) |
---|