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 | ;-*- standard-indent: 2; indent-tabs-mode: nil -*- |
---|
11 | (defpackage :versions-test |
---|
12 | (:use |
---|
13 | :common-lisp |
---|
14 | :xml-importer |
---|
15 | :datamodel |
---|
16 | :it.bese.FiveAM |
---|
17 | :fixtures |
---|
18 | :unittests-constants) |
---|
19 | (:import-from :constants |
---|
20 | *xtm2.0-ns*) |
---|
21 | (:import-from :xml-tools |
---|
22 | xpath-child-elems-by-qname |
---|
23 | xpath-select-location-path) |
---|
24 | (:import-from :exceptions |
---|
25 | missing-reference-error |
---|
26 | duplicate-identifier-error) |
---|
27 | (:export :test-get-item-by-id-t100 |
---|
28 | :test-get-item-by-id-t301 |
---|
29 | :test-get-item-by-id-common-lisp |
---|
30 | :test-mark-as-deleted |
---|
31 | :test-instance-of-t64 |
---|
32 | :test-norwegian-curriculum-association |
---|
33 | :test-change-lists |
---|
34 | :test-changed-p |
---|
35 | :versions-test |
---|
36 | :run-versions-tests)) |
---|
37 | (declaim (optimize (debug 3))) |
---|
38 | |
---|
39 | (in-package :versions-test) |
---|
40 | |
---|
41 | (def-suite versions-test |
---|
42 | :description "tests various key functions of the importer") |
---|
43 | |
---|
44 | (in-suite versions-test) |
---|
45 | |
---|
46 | (test test-get-item-by-id-t100 () |
---|
47 | "test certain characteristics of |
---|
48 | http://psi.egovpt.org/standard/ISO+19115%3A+Geographic+Information+-+Metadata |
---|
49 | of which two revisions are created, the original one and then one during the |
---|
50 | merge with *XTM-MERGE1*" |
---|
51 | (with-fixture merge-test-db () |
---|
52 | (let |
---|
53 | ((top-t100-current (get-item-by-id "t100" :xtm-id *TEST-TM*)) |
---|
54 | (top-t100-first (get-item-by-id "t100" :xtm-id *TEST-TM* |
---|
55 | :revision fixtures::revision1)) |
---|
56 | (top-t100-second (get-item-by-id "t100" :xtm-id *TEST-TM* |
---|
57 | :revision fixtures::revision2)) |
---|
58 | (link-topic (get-item-by-id "t55" :xtm-id *TEST-TM* |
---|
59 | :revision fixtures::revision2))) |
---|
60 | (is (eq top-t100-current top-t100-second)) |
---|
61 | (is (eq top-t100-current top-t100-first)) |
---|
62 | (is (= 2 (length (names top-t100-current)))) |
---|
63 | (with-revision fixtures::revision1 |
---|
64 | (is (= 1 (length (names top-t100-first))))) |
---|
65 | (is (string= (charvalue (first (names top-t100-first))) |
---|
66 | "ISO 19115")) |
---|
67 | (with-revision fixtures::revision2 |
---|
68 | (is (= 2 (length (names top-t100-second)))) |
---|
69 | (is (= 5 (length (occurrences top-t100-second)))) |
---|
70 | (is (eq link-topic (get-item-by-id "t50" :xtm-id "merge1"))) ;the topic with t55 in notificationbase has the id t50 in merge1 |
---|
71 | (is (eq link-topic (instance-of (fifth (occurrences top-t100-second)))))) |
---|
72 | (is (string= (charvalue (first (names top-t100-second))) |
---|
73 | "ISO 19115")) |
---|
74 | (is (string= (charvalue (second (names top-t100-second))) |
---|
75 | "Geo Data")) |
---|
76 | (is (= 5 (length (occurrences top-t100-current)))) |
---|
77 | (is (= 2 (length (item-identifiers top-t100-current)))) |
---|
78 | (with-revision fixtures::revision1 |
---|
79 | (is (= 4 (length (occurrences top-t100-first)))) |
---|
80 | (is (= 1 (length (item-identifiers top-t100-first))))) |
---|
81 | (is (= 2 (length (elephant:get-instances-by-class 'd:TopicMapC))))))) |
---|
82 | |
---|
83 | |
---|
84 | (test test-get-item-by-id-t301 () |
---|
85 | "test characteristics of http://psi.egovpt.org/service/Google+Maps which |
---|
86 | occurs twice in notificationbase.xtm but is not subsequently revised" |
---|
87 | (with-fixture merge-test-db () |
---|
88 | (let |
---|
89 | ((top-t301-current (get-item-by-id "t301" :xtm-id *TEST-TM*)) |
---|
90 | (top-t301-first (get-item-by-id "t301a" :xtm-id *TEST-TM* |
---|
91 | :revision fixtures::revision1)) |
---|
92 | (top-t301-second (get-item-by-id "t301a" :xtm-id *TEST-TM* |
---|
93 | :revision fixtures::revision2))) |
---|
94 | (is (eq top-t301-current top-t301-first)) |
---|
95 | (is (eq top-t301-current top-t301-second))))) |
---|
96 | |
---|
97 | |
---|
98 | (test test-get-item-by-id-common-lisp () |
---|
99 | "Get the http://psi.egovpt.org/standard/Common+Lisp topic that was first |
---|
100 | introduced in merge1 and then modified in merge2" |
---|
101 | (with-fixture merge-test-db () |
---|
102 | (let |
---|
103 | ((top-cl-current (get-item-by-id "t100" :xtm-id "merge2" |
---|
104 | :revision fixtures::revision3)) |
---|
105 | (top-cl-first (get-item-by-id "t100" :xtm-id "merge2" |
---|
106 | :revision fixtures::revision1)) |
---|
107 | (top-cl-second (get-item-by-id "t100" :xtm-id "merge1" |
---|
108 | :revision fixtures::revision2))) |
---|
109 | (is-false top-cl-first) |
---|
110 | (is (eq top-cl-second top-cl-current)) |
---|
111 | (is (= 1 (length (names top-cl-current)))) |
---|
112 | (with-revision fixtures::revision2 |
---|
113 | (is (= 1 (length (item-identifiers top-cl-second))))) |
---|
114 | (is (= 2 (length (item-identifiers top-cl-current)))) |
---|
115 | (with-revision fixtures::revision2 |
---|
116 | (is (= 1 (length (occurrences top-cl-second))))) |
---|
117 | (is (= 2 (length (occurrences top-cl-current))))))) |
---|
118 | |
---|
119 | |
---|
120 | (test test-norwegian-curriculum-association () |
---|
121 | "Check the various incarnations of the norwegian curriculum |
---|
122 | associations across its revisions" |
---|
123 | (with-fixture merge-test-db () |
---|
124 | (let* |
---|
125 | ((norwegian-curr-topic |
---|
126 | (get-item-by-id "t300" :xtm-id *TEST-TM* :revision fixtures::revision3)) |
---|
127 | |
---|
128 | (curriculum-assoc ;this is the only "true" association in which the |
---|
129 | ;Norwegian Curriculum is a player in revision1 |
---|
130 | (parent |
---|
131 | (second ;the first one is the instanceOf association |
---|
132 | (player-in-roles |
---|
133 | norwegian-curr-topic :revision fixtures::revision3)) |
---|
134 | :revision fixtures::revision3)) |
---|
135 | (scoped-curriculum-assoc ;this one is added in revision3 |
---|
136 | (parent |
---|
137 | (third |
---|
138 | (player-in-roles |
---|
139 | norwegian-curr-topic :revision fixtures::revision3)) |
---|
140 | :revision fixtures::revision3)) |
---|
141 | (semantic-standard-topic |
---|
142 | (get-item-by-id "t3a" :xtm-id *TEST-TM* :revision fixtures::revision3))) |
---|
143 | (is (string= "http://psi.egovpt.org/service/Norwegian+National+Curriculum" |
---|
144 | (uri (first (psis norwegian-curr-topic |
---|
145 | :revision fixtures::revision3))))) |
---|
146 | (is (= 1 (length (item-identifiers curriculum-assoc |
---|
147 | :revision fixtures::revision3)))) |
---|
148 | (is (= 3 (length (psis semantic-standard-topic |
---|
149 | :revision fixtures::revision3)))) |
---|
150 | (with-revision fixtures::revision1 |
---|
151 | ;one explicit association and the association resulting |
---|
152 | ;from instanceOf |
---|
153 | (is (= 2 (length (player-in-roles norwegian-curr-topic)))) |
---|
154 | (is-false (item-identifiers curriculum-assoc)) |
---|
155 | (is-false (used-as-theme semantic-standard-topic))) |
---|
156 | (with-revision fixtures::revision2 |
---|
157 | ;one explicit association and the association resulting |
---|
158 | ;from instanceOf |
---|
159 | (is (= 2 (length (player-in-roles norwegian-curr-topic)))) |
---|
160 | (is (= 1 (length (item-identifiers curriculum-assoc)))) |
---|
161 | (is (= 1 (length (item-identifiers (first (roles curriculum-assoc)))))) |
---|
162 | (is (= 2 (length (item-identifiers (second (roles curriculum-assoc)))))) |
---|
163 | (is-false (used-as-theme semantic-standard-topic))) |
---|
164 | (with-revision fixtures::revision3 |
---|
165 | ;two explicit associations and the association resulting |
---|
166 | ;from instanceOf |
---|
167 | (is (= 3 (length (player-in-roles norwegian-curr-topic)))) |
---|
168 | (is (= 1 (length (item-identifiers curriculum-assoc)))) |
---|
169 | (is (eq semantic-standard-topic (first (themes scoped-curriculum-assoc)))) |
---|
170 | (is (= 1 (length (used-as-theme semantic-standard-topic)))) |
---|
171 | (is (= 1 (length (item-identifiers (first (roles curriculum-assoc)))))) |
---|
172 | (is (= 3 (length (item-identifiers (second (roles curriculum-assoc)))))))))) |
---|
173 | |
---|
174 | |
---|
175 | (test test-instance-of-t64 () |
---|
176 | "Check if all instances of t64 are properly registered." |
---|
177 | (with-fixture merge-test-db () |
---|
178 | (let ((t63 (get-item-by-id "t63" :xtm-id *TEST-TM* |
---|
179 | :revision fixtures::revision3)) |
---|
180 | (t64 (get-item-by-id "t64" :xtm-id *TEST-TM* |
---|
181 | :revision fixtures::revision3)) |
---|
182 | (t300 (get-item-by-id "t300" :xtm-id *TEST-TM* |
---|
183 | :revision fixtures::revision3))) |
---|
184 | (with-revision fixtures::revision1 |
---|
185 | (let ((assocs (used-as-type t64))) |
---|
186 | (is (= 2 (length assocs))) |
---|
187 | (is (= (d::internal-id t63) |
---|
188 | (d::internal-id (instance-of (first (roles (first assocs))))))) |
---|
189 | (is (= (d::internal-id t300) |
---|
190 | (d::internal-id (player (first (roles (first assocs))))))))) |
---|
191 | (with-revision fixtures::revision2 |
---|
192 | (let ((assocs (used-as-type t64))) |
---|
193 | (is (= 2 (length assocs))))) |
---|
194 | (with-revision fixtures::revision3 |
---|
195 | (let ((assocs (used-as-type t64))) |
---|
196 | (is (= 3 (length assocs)))))))) |
---|
197 | |
---|
198 | |
---|
199 | (test test-change-lists () |
---|
200 | "Check various properties of changes applied to Isidor in this |
---|
201 | test suite" |
---|
202 | (with-fixture merge-test-db () |
---|
203 | (let ((all-revision-set (get-all-revisions)) |
---|
204 | (fragments-revision2 |
---|
205 | (get-fragments fixtures::revision2)) |
---|
206 | (fragments-revision3 |
---|
207 | (get-fragments fixtures::revision3))) |
---|
208 | (is (= 3 (length all-revision-set))) |
---|
209 | (is (= fixtures::revision1 (first all-revision-set))) |
---|
210 | (is (= fixtures::revision2 (second all-revision-set))) |
---|
211 | (is (= fixtures::revision3 (third all-revision-set))) |
---|
212 | ;topics changed in revision2 / merge1: topic type, service, |
---|
213 | ;standard, semantic standard, standardHasStatus, geo data |
---|
214 | ;standard, common lisp, norwegian curriculum |
---|
215 | (is (= 8 (length fragments-revision2))) |
---|
216 | ;topics changed in revision3 / merge2: semantic standard, |
---|
217 | ;norwegian curriculum, common lisp |
---|
218 | (is (= 3 (length fragments-revision3))) |
---|
219 | (is (= fixtures::revision3 |
---|
220 | (revision (first fragments-revision3)))) |
---|
221 | (is (string= |
---|
222 | "http://psi.egovpt.org/types/semanticstandard" |
---|
223 | (uri (first (psis (topic (first fragments-revision3))))))) |
---|
224 | (format t "semantic-standard: ~a~&" |
---|
225 | (remove-duplicates (map 'list #'uri (mapcan #'psis (referenced-topics (first fragments-revision3)))) |
---|
226 | :test #'string=)) |
---|
227 | (is-false |
---|
228 | (set-exclusive-or |
---|
229 | '("http://psi.egovpt.org/types/standard") |
---|
230 | (remove-duplicates (map 'list #'uri (mapcan #'psis (referenced-topics (first fragments-revision3)))) |
---|
231 | :test #'string=) |
---|
232 | :test #'string=)) |
---|
233 | ;0 if we ignore instanceOf associations |
---|
234 | (is (= 0 (length (associations (first fragments-revision3))))) |
---|
235 | (is (string= "http://psi.egovpt.org/standard/Common+Lisp" |
---|
236 | (uri (first (psis (topic (third fragments-revision3))))))) |
---|
237 | (is-false |
---|
238 | (set-exclusive-or |
---|
239 | '("http://psi.egovpt.org/types/standard" |
---|
240 | "http://psi.egovpt.org/types/links";) |
---|
241 | "http://www.topicmaps.org/xtm/1.0/core.xtm#sort" |
---|
242 | "http://www.topicmaps.org/xtm/1.0/core.xtm#display" |
---|
243 | "http://psi.egovpt.org/types/long-name") |
---|
244 | (remove-duplicates |
---|
245 | (map 'list |
---|
246 | #'uri |
---|
247 | (mapcan #'psis (referenced-topics (third fragments-revision3)))) |
---|
248 | :test #'string=) |
---|
249 | :test #'string=)) |
---|
250 | ;0 if we ignore instanceOf associations |
---|
251 | (is (= 0 (length (associations (third fragments-revision3))))) |
---|
252 | (is (string= |
---|
253 | "http://psi.egovpt.org/service/Norwegian+National+Curriculum" |
---|
254 | (uri (first (psis (topic (second fragments-revision3))))))) |
---|
255 | (is-false |
---|
256 | (set-exclusive-or |
---|
257 | '("http://psi.egovpt.org/types/service" |
---|
258 | "http://psi.egovpt.org/types/description" |
---|
259 | "http://psi.egovpt.org/types/links" |
---|
260 | "http://psi.egovpt.org/types/serviceUsesStandard" |
---|
261 | "http://psi.egovpt.org/types/StandardRoleType" |
---|
262 | "http://psi.egovpt.org/standard/Topic+Maps+2002" |
---|
263 | "http://psi.egovpt.org/types/ServiceRoleType" |
---|
264 | ;these three PSIS all stand for the same topic |
---|
265 | "http://psi.egovpt.org/types/semanticstandard" |
---|
266 | "http://psi.egovpt.org/types/greatstandard" |
---|
267 | "http://psi.egovpt.org/types/knowledgestandard") |
---|
268 | (remove-duplicates (map 'list #'uri (mapcan #'psis (referenced-topics (second fragments-revision3)))) |
---|
269 | :test #'string=) |
---|
270 | :test #'string=)) |
---|
271 | ;the second time round the object should be fetched from the |
---|
272 | ;cache |
---|
273 | (is (equal fragments-revision3 |
---|
274 | (get-fragments fixtures::revision3)))))) |
---|
275 | |
---|
276 | |
---|
277 | (test test-changed-p () |
---|
278 | "Check the is-changed mechanism" |
---|
279 | (with-fixture merge-test-db () |
---|
280 | (let* |
---|
281 | ((service-topic ;changed in merge1 |
---|
282 | (get-item-by-id "t2" :xtm-id *TEST-TM* :revision fixtures::revision1)) |
---|
283 | (service-name ;does not change after creation |
---|
284 | (first (names service-topic :revision fixtures::revision1))) |
---|
285 | (google-maps-topic ;does not change after creation |
---|
286 | (get-item-by-id "t301a" :xtm-id *TEST-TM* :revision fixtures::revision1)) |
---|
287 | (norwegian-curr-topic ;changes in merge1 (only through |
---|
288 | ;association) and merge2 (again through association) |
---|
289 | (get-item-by-id "t300" :xtm-id *TEST-TM* :revision fixtures::revision1)) |
---|
290 | (geodata-topic ;does not change after creation |
---|
291 | (get-item-by-id "t203" :xtm-id *TEST-TM* :revision fixtures::revision1)) ;the subject "geodata", not the standard |
---|
292 | (semantic-standard-topic ;changes in merge1 and merge2 |
---|
293 | (get-item-by-id "t3a" :xtm-id *TEST-TM* :revision fixtures::revision1)) |
---|
294 | (common-lisp-topic ;created in merge1 and changed in merge2 |
---|
295 | (get-item-by-id "t100" :xtm-id "merge1" :revision fixtures::revision2)) |
---|
296 | (subject-geodata-assoc ;does not change after creation |
---|
297 | (parent |
---|
298 | (second ;the first one is the instanceOf association |
---|
299 | (player-in-roles |
---|
300 | geodata-topic :revision fixtures::revision1)) |
---|
301 | :revision fixtures::revision1)) |
---|
302 | (norwegian-curriculum-assoc ;changes in merge1 and merge2 |
---|
303 | (identified-construct |
---|
304 | (elephant:get-instance-by-value |
---|
305 | 'ItemIdentifierC 'uri |
---|
306 | "http://psi.egovpt.org/itemIdentifiers#assoc_6") |
---|
307 | :revision fixtures::revision2))) |
---|
308 | (is-true (changed-p service-name fixtures::revision1)) |
---|
309 | (is-false (changed-p service-name fixtures::revision2)) |
---|
310 | (is-false (changed-p service-name fixtures::revision3)) |
---|
311 | (is-true (changed-p service-topic fixtures::revision1)) |
---|
312 | (is-true (changed-p service-topic fixtures::revision2)) |
---|
313 | (is-false (changed-p service-topic fixtures::revision3)) |
---|
314 | (is-true (changed-p google-maps-topic fixtures::revision1)) |
---|
315 | (is-false (changed-p google-maps-topic fixtures::revision2)) |
---|
316 | (is-false (changed-p google-maps-topic fixtures::revision3)) |
---|
317 | (is-true (changed-p norwegian-curr-topic fixtures::revision1)) |
---|
318 | (is-true (changed-p norwegian-curr-topic fixtures::revision2)) |
---|
319 | (is-true (changed-p norwegian-curr-topic fixtures::revision3)) |
---|
320 | (is-true (changed-p geodata-topic fixtures::revision1)) |
---|
321 | (is-false (changed-p geodata-topic fixtures::revision2)) |
---|
322 | (is-false (changed-p geodata-topic fixtures::revision3)) |
---|
323 | (is-true (changed-p semantic-standard-topic fixtures::revision1)) |
---|
324 | (is-true (changed-p semantic-standard-topic fixtures::revision2)) |
---|
325 | (is-true (changed-p semantic-standard-topic fixtures::revision3)) |
---|
326 | (is-false (changed-p common-lisp-topic fixtures::revision1)) ;didn't even exist then |
---|
327 | (is-true (changed-p common-lisp-topic fixtures::revision2)) |
---|
328 | (is-true (changed-p common-lisp-topic fixtures::revision3)) |
---|
329 | (is-true (changed-p subject-geodata-assoc fixtures::revision1)) |
---|
330 | (is-false (changed-p subject-geodata-assoc fixtures::revision2)) |
---|
331 | (is-false (changed-p subject-geodata-assoc fixtures::revision3)) |
---|
332 | (is-true (changed-p norwegian-curriculum-assoc fixtures::revision1)) |
---|
333 | (is-true (changed-p norwegian-curriculum-assoc fixtures::revision2)) |
---|
334 | (is-true (changed-p norwegian-curriculum-assoc fixtures::revision3)) |
---|
335 | (delete-name service-topic service-name :revision fixtures::revision3) |
---|
336 | (is-true (changed-p service-topic fixtures::revision3))))) |
---|
337 | |
---|
338 | |
---|
339 | (test test-mark-as-deleted () |
---|
340 | "Check the pseudo-deletion mechanism" |
---|
341 | (with-fixture merge-test-db () |
---|
342 | (let |
---|
343 | ((norwegian-curriculum-topic |
---|
344 | (get-item-by-psi "http://psi.egovpt.org/service/Norwegian+National+Curriculum" |
---|
345 | :revision fixtures::revision3)) |
---|
346 | (semantic-standard-topic |
---|
347 | (get-item-by-psi "http://psi.egovpt.org/types/semanticstandard" |
---|
348 | :revision fixtures::revision3))) |
---|
349 | (is-true norwegian-curriculum-topic) |
---|
350 | (is-true semantic-standard-topic) |
---|
351 | (mark-as-deleted norwegian-curriculum-topic |
---|
352 | :source-locator "http://psi.egovpt.org/" |
---|
353 | :revision fixtures::revision3) |
---|
354 | (is-false (get-item-by-psi |
---|
355 | "http://psi.egovpt.org/service/Norwegian+National+Curriculum" |
---|
356 | :revision (1+ fixtures::revision3))) |
---|
357 | (mark-as-deleted semantic-standard-topic |
---|
358 | :source-locator "http://blablub.egovpt.org/" |
---|
359 | :revision fixtures::revision3) |
---|
360 | (is-true (get-item-by-psi "http://psi.egovpt.org/types/semanticstandard" |
---|
361 | :revision (1+ fixtures::revision3))) |
---|
362 | (is (= 0 (d::end-revision |
---|
363 | (d::get-most-recent-version-info semantic-standard-topic)))) |
---|
364 | (is (= (d::end-revision |
---|
365 | (first (last (d::versions norwegian-curriculum-topic)))) |
---|
366 | (d::end-revision |
---|
367 | (d::get-most-recent-version-info norwegian-curriculum-topic))))))) |
---|
368 | |
---|
369 | |
---|
370 | |
---|
371 | (defun run-versions-tests() |
---|
372 | (it.bese.fiveam:run! 'test-get-item-by-id-t100) |
---|
373 | (it.bese.fiveam:run! 'test-get-item-by-id-t301) |
---|
374 | (it.bese.fiveam:run! 'test-norwegian-curriculum-association) |
---|
375 | (it.bese.fiveam:run! 'test-instance-of-t64) |
---|
376 | (it.bese.fiveam:run! 'test-change-lists) |
---|
377 | (it.bese.fiveam:run! 'test-changed-p) |
---|
378 | (it.bese.fiveam:run! 'test-mark-as-deleted)) |
---|