1 | ;;+----------------------------------------------------------------------------- |
---|
2 | ;;+ Isidorus |
---|
3 | ;;+ (c) 2008-2010 Marc Kuester, Christoph Ludwig, Lukas Georgieff |
---|
4 | ;;+ |
---|
5 | ;;+ Isidorus is freely distributable under the LLGPL license. |
---|
6 | ;;+ You can find a detailed description in trunk/docs/LLGPL-LICENSE.txt and |
---|
7 | ;;+ trunk/docs/LGPL-LICENSE.txt. |
---|
8 | ;;+----------------------------------------------------------------------------- |
---|
9 | |
---|
10 | (defpackage :importer-test |
---|
11 | (:use |
---|
12 | :common-lisp |
---|
13 | :xtm-importer |
---|
14 | :base-tools |
---|
15 | :datamodel |
---|
16 | :it.bese.FiveAM |
---|
17 | :unittests-constants |
---|
18 | :fixtures) |
---|
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 | not-mergable-error ) |
---|
28 | (:export :importer-test |
---|
29 | :test-error-detection |
---|
30 | :run-importer-tests |
---|
31 | :test-from-association-elem |
---|
32 | :test-create-instanceof-association |
---|
33 | :test-from-name-elem |
---|
34 | :test-from-scope-elem |
---|
35 | :test-from-type-elem |
---|
36 | :test-from-role-elem |
---|
37 | :test-from-occurrence-elem |
---|
38 | :test-merge-topic |
---|
39 | :test-setup-repository-xtm1.0 |
---|
40 | :test-topic-t100 |
---|
41 | :test-topicmaps |
---|
42 | :test-variants |
---|
43 | :test-variants-xtm1.0 |
---|
44 | :test-merge-topicmaps |
---|
45 | :test-merge-topicmaps-xtm1.0)) |
---|
46 | (declaim (optimize (debug 3) (speed 0) (safety 3) (space 0) (compilation-speed 0))) |
---|
47 | |
---|
48 | (in-package :importer-test) |
---|
49 | |
---|
50 | |
---|
51 | (def-suite importer-test |
---|
52 | :description "tests various key functions of the importer") |
---|
53 | |
---|
54 | (in-suite importer-test) |
---|
55 | |
---|
56 | (defvar *T100-TM* |
---|
57 | (dom:document-element |
---|
58 | (cxml:parse-file *t100.xtm* (cxml-dom:make-dom-builder)))) |
---|
59 | |
---|
60 | (test test-from-type-elem |
---|
61 | "Test the from-type-elem function of the importer" |
---|
62 | (with-fixture |
---|
63 | initialized-test-db() |
---|
64 | (let ((type-elems |
---|
65 | (xpath-select-location-path |
---|
66 | *XTM-TM* |
---|
67 | '((*xtm2.0-ns* "topic") |
---|
68 | (*xtm2.0-ns* "occurrence") |
---|
69 | (*xtm2.0-ns* "type")))) |
---|
70 | (rev-1 *TM-REVISION*)) |
---|
71 | (loop for type-elem in type-elems do |
---|
72 | (is (typep (from-type-elem type-elem rev-1) 'TopicC))) |
---|
73 | (is-false (from-type-elem nil rev-1)) |
---|
74 | (let |
---|
75 | ((t100-occtype |
---|
76 | (from-type-elem (first type-elems) rev-1))) |
---|
77 | (format t "occtype: ~a~&" t100-occtype) |
---|
78 | (format t "occtype: ~a~&" (psis t100-occtype)) |
---|
79 | (is |
---|
80 | (string= "http://psi.egovpt.org/types/standardHasStatus" |
---|
81 | (uri (first (psis t100-occtype))))))))) |
---|
82 | |
---|
83 | |
---|
84 | (test test-from-scope-elem |
---|
85 | "Test the from-scope-elem function of the importer" |
---|
86 | (declare (optimize (debug 3))) |
---|
87 | (with-fixture |
---|
88 | initialized-test-db() |
---|
89 | (let ((scope-elems |
---|
90 | (xpath-select-location-path |
---|
91 | *XTM-TM* |
---|
92 | '((*xtm2.0-ns* "topic") |
---|
93 | (*xtm2.0-ns* "name") |
---|
94 | (*xtm2.0-ns* "scope")))) |
---|
95 | (rev-1 *TM-REVISION*)) |
---|
96 | (loop for scope-elem in scope-elems do |
---|
97 | (is (>= (length (from-scope-elem scope-elem rev-1)) 1))) |
---|
98 | (is-false (from-scope-elem nil rev-1)) |
---|
99 | (let |
---|
100 | ((t101-themes |
---|
101 | (from-scope-elem (first scope-elems) rev-1))) |
---|
102 | (is (= 1 (length t101-themes))) |
---|
103 | (is |
---|
104 | (string= |
---|
105 | (topic-id (first t101-themes) rev-1 *TEST-TM*) |
---|
106 | "t50a")))))) |
---|
107 | |
---|
108 | (test test-from-name-elem |
---|
109 | "Test the from-name-elem function of the importer" |
---|
110 | (with-fixture |
---|
111 | initialized-test-db() |
---|
112 | (let ((name-elems |
---|
113 | (xpath-select-location-path |
---|
114 | *XTM-TM* |
---|
115 | '((*xtm2.0-ns* "topic") |
---|
116 | (*xtm2.0-ns* "name")))) |
---|
117 | (top (get-item-by-id "t1")) ;an arbitrary topic |
---|
118 | (rev-1 *TM-REVISION*)) |
---|
119 | (loop for name-elem in name-elems do |
---|
120 | (is (typep (from-name-elem name-elem top rev-1) 'NameC))) |
---|
121 | (let |
---|
122 | ((t1-name (from-name-elem (first name-elems) top rev-1)) |
---|
123 | (t1-name-copy (from-name-elem (first name-elems) top rev-1)) |
---|
124 | (t101-longname (from-name-elem (nth 27 name-elems) top rev-1))) |
---|
125 | (is (string= (charvalue t1-name) "Topic Type")) |
---|
126 | (is (string= (charvalue t101-longname) |
---|
127 | "ISO/IEC 13250:2002: Topic Maps")) |
---|
128 | (is (= 1 (length (item-identifiers t101-longname :revision rev-1)))) |
---|
129 | (is (string= (uri (first (psis (instance-of t101-longname)))) |
---|
130 | "http://psi.egovpt.org/types/long-name")) |
---|
131 | (is (themes t101-longname :revision rev-1)) |
---|
132 | (is (string= |
---|
133 | (topic-id (first (themes t101-longname :revision rev-1)) |
---|
134 | rev-1 *TEST-TM*) |
---|
135 | "t50a")) |
---|
136 | (is (eq t1-name t1-name-copy)))))) ;must be merged |
---|
137 | |
---|
138 | |
---|
139 | (test test-from-occurrence-elem |
---|
140 | "Test the form-occurrence-elem function of the importer" |
---|
141 | (with-fixture |
---|
142 | initialized-test-db() |
---|
143 | (let ((occ-elems |
---|
144 | (xpath-select-location-path |
---|
145 | *XTM-TM* |
---|
146 | '((*xtm2.0-ns* "topic") |
---|
147 | (*xtm2.0-ns* "occurrence")))) |
---|
148 | (top (get-item-by-id "t1")) ;an abritrary topic |
---|
149 | (rev-1 *TM-REVISION*)) |
---|
150 | (loop for occ-elem in occ-elems do |
---|
151 | (is (typep (from-occurrence-elem occ-elem top rev-1) |
---|
152 | 'OccurrenceC))) |
---|
153 | (is (= 1 (length (elephant:get-instances-by-value |
---|
154 | 'ItemIdentifierC |
---|
155 | 'uri |
---|
156 | "http://psi.egovpt.org/itemIdentifiers#t100_o1")))) |
---|
157 | (let |
---|
158 | ((t100-occ1 |
---|
159 | (identified-construct |
---|
160 | (elephant:get-instance-by-value |
---|
161 | 'ItemIdentifierC |
---|
162 | 'uri |
---|
163 | "http://psi.egovpt.org/itemIdentifiers#t100_o1"))) |
---|
164 | (t100-occ2 |
---|
165 | (identified-construct |
---|
166 | (elephant:get-instance-by-value |
---|
167 | 'ItemIdentifierC |
---|
168 | 'uri |
---|
169 | "http://psi.egovpt.org/itemIdentifiers#t100_o2")))) |
---|
170 | (is (= 1 (length (item-identifiers t100-occ1 :revision rev-1)))) ;just to double-check |
---|
171 | (is (string= |
---|
172 | (uri (first (item-identifiers t100-occ1 :revision rev-1))) |
---|
173 | "http://psi.egovpt.org/itemIdentifiers#t100_o1")) |
---|
174 | (is (string= (charvalue t100-occ1) "http://www.budabe.de/")) |
---|
175 | (is (string= (datatype t100-occ1) "http://www.w3.org/2001/XMLSchema#anyURI")) |
---|
176 | (is (string= (datatype t100-occ2) |
---|
177 | "http://www.w3.org/2001/XMLSchema#string")))))) |
---|
178 | |
---|
179 | (test test-merge-topic |
---|
180 | "Test the merge-topic-elem function of the importer" |
---|
181 | (with-fixture |
---|
182 | initialized-test-db() |
---|
183 | (let ((topic-elems |
---|
184 | (xpath-select-location-path |
---|
185 | *XTM-TM* |
---|
186 | '((*xtm2.0-ns* "topic")))) |
---|
187 | (rev-1 *TM-REVISION*)) |
---|
188 | (loop for topic-elem in topic-elems do |
---|
189 | (is (typep |
---|
190 | (merge-topic-elem topic-elem rev-1 :tm fixtures::tm) |
---|
191 | 'TopicC))) |
---|
192 | (let |
---|
193 | ((top-t1 (merge-topic-elem (first topic-elems) |
---|
194 | rev-1 :tm fixtures::tm)) |
---|
195 | (top-t57 (get-item-by-id "t57")) |
---|
196 | (top-t101 (get-item-by-id "t101")) |
---|
197 | (top-t301 (get-item-by-id "t301")) |
---|
198 | (top-t301a (get-item-by-id "t301a")) |
---|
199 | ;one of the core PSIs |
---|
200 | (top-sup-sub (get-item-by-id "supertype-subtype" :xtm-id "core.xtm"))) |
---|
201 | (is (= (elephant::oid top-t301) (elephant::oid top-t301a))) |
---|
202 | (is-true top-t301a) |
---|
203 | (is (= (length (occurrences top-t1 :revision rev-1)) 0)) |
---|
204 | (is (= (length (occurrences top-t101 :revision rev-1)) 4)) |
---|
205 | (is (= (length (names top-t57 :revision rev-1)) 1)) |
---|
206 | (is (string= (uri (first (item-identifiers top-t57 :revision rev-1))) |
---|
207 | "http://psi.egovpt.org/itemIdentifiers#t57")) |
---|
208 | (is (= 2 (length (names top-t101 :revision rev-1)))) |
---|
209 | (is (= 2 (length (names top-t301 :revision rev-1)))) ;after merge |
---|
210 | (is-true (item-identifiers (first (names top-t301 :revision rev-1)) |
---|
211 | :revision rev-1)) ;after merge |
---|
212 | (is (= 2 (length (psis top-t301 :revision rev-1)))) ;after merge |
---|
213 | (is (= 3 (length (occurrences top-t301 :revision rev-1)))) ;after merge |
---|
214 | (is (string= "http://www.topicmaps.org/xtm/1.0/core.xtm#supertype-subtype" |
---|
215 | (uri (first (psis top-sup-sub :revision rev-1))))))) |
---|
216 | ;34 topics in 35 topic elements in notificationbase.xtm and 14 |
---|
217 | ;core topics |
---|
218 | (is (= (+ 34 14) (length (elephant:get-instances-by-class 'TopicC)))))) |
---|
219 | |
---|
220 | (test test-from-role-elem |
---|
221 | "Test the form-role-elem function of the importer" |
---|
222 | (with-fixture |
---|
223 | initialized-test-db() |
---|
224 | (let |
---|
225 | ((role-elems |
---|
226 | (xpath-select-location-path |
---|
227 | *XTM-TM* |
---|
228 | '((*xtm2.0-ns* "association") |
---|
229 | (*xtm2.0-ns* "role")))) |
---|
230 | (rev-1 *TM-REVISION*)) |
---|
231 | (loop for role-elem in role-elems do |
---|
232 | (is (typep (from-role-elem role-elem revision) 'list))) |
---|
233 | (let |
---|
234 | ((12th-role |
---|
235 | (from-role-elem (nth 11 role-elems) revision))) |
---|
236 | (is (string= "t101" |
---|
237 | (topic-id |
---|
238 | (getf 12th-role :player) rev-1 *TEST-TM*))) |
---|
239 | (is (string= "t62" |
---|
240 | (topic-id |
---|
241 | (getf 12th-role :instance-of) rev-1 *TEST-TM*))))))) |
---|
242 | |
---|
243 | |
---|
244 | (test test-from-association-elem |
---|
245 | "Test the form-association-elem function of the importer" |
---|
246 | (with-fixture |
---|
247 | initialized-test-db() |
---|
248 | (let ((assoc-elems |
---|
249 | (xpath-select-location-path |
---|
250 | *XTM-TM* |
---|
251 | '((*xtm2.0-ns* "association")))) |
---|
252 | (rev-1 *TM-REVISION*)) |
---|
253 | (loop for assoc-elem in assoc-elems do |
---|
254 | (is |
---|
255 | (typep (from-association-elem assoc-elem rev-1 :tm fixtures::tm) |
---|
256 | 'AssociationC))) |
---|
257 | (let ((6th-assoc |
---|
258 | (sixth (elephant:get-instances-by-class 'AssociationC))) |
---|
259 | (last-assoc |
---|
260 | (seventh (elephant:get-instances-by-class 'AssociationC)))) |
---|
261 | (is (= 2 (length (roles last-assoc :revision rev-1)))) |
---|
262 | (is (= 1 (length (item-identifiers last-assoc :revision rev-1)))) |
---|
263 | (is (string= "t300" |
---|
264 | (topic-id (player (first (roles 6th-assoc :revision rev-1)) |
---|
265 | :revision rev-1) rev-1 *TEST-TM*))) |
---|
266 | (is (string= "t63" |
---|
267 | (topic-id (instance-of (first (roles 6th-assoc :revision rev-1)) |
---|
268 | :revision rev-1) rev-1 *TEST-TM*))) |
---|
269 | (is (string= "t301" |
---|
270 | (topic-id (player (first (roles last-assoc :revision rev-1)) |
---|
271 | :revision rev-1) rev-1 *TEST-TM*))))) |
---|
272 | (is (= 7 |
---|
273 | (length (elephant:get-instances-by-class 'AssociationC)))))) |
---|
274 | |
---|
275 | |
---|
276 | (test test-create-instanceof-association |
---|
277 | "Test the creation of instanceof associations" |
---|
278 | (declare (optimize (debug 3))) |
---|
279 | (with-fixture |
---|
280 | initialized-test-db() |
---|
281 | (let ((topic-elems |
---|
282 | (xpath-select-location-path |
---|
283 | *XTM-TM* |
---|
284 | '((*xtm2.0-ns* "topic")))) |
---|
285 | (rev-1 *TM-REVISION*)) |
---|
286 | (loop for topic-elem in topic-elems do |
---|
287 | (let (;this already implicitly creates the instanceOf |
---|
288 | ;associations as needed |
---|
289 | (topic (merge-topic-elem topic-elem rev-1 :tm fixtures::tm))) |
---|
290 | (dolist (io-role (map 'list #'d::parent-construct |
---|
291 | (d::slot-p topic 'd::player-in-roles))) |
---|
292 | (let ((io-assoc (parent io-role :revision rev-1))) |
---|
293 | (is (typep io-assoc 'AssociationC)) |
---|
294 | (is (string= (topic-id topic rev-1) |
---|
295 | (topic-id (player (second |
---|
296 | (roles io-assoc :revision rev-1)) |
---|
297 | :revision rev-1) rev-1))))))) |
---|
298 | (let* ((t101-top (get-item-by-id "t101" :revision rev-1)) |
---|
299 | ;get all the roles t101 is involved in |
---|
300 | (roles-101 (map 'list #'d::parent-construct |
---|
301 | (d::slot-p t101-top 'd::player-in-roles))) |
---|
302 | ;and filter those whose roletype is "instance" |
---|
303 | ;(returning, of course, a list) |
---|
304 | ;TODO: what we'd really need |
---|
305 | ;is a filter that works |
---|
306 | ;directly on the indices |
---|
307 | ;rather than instantiating |
---|
308 | ;many unnecessary role objects |
---|
309 | (role-101 (remove-if-not |
---|
310 | (lambda (role) |
---|
311 | (string= (uri (first (psis |
---|
312 | (instance-of role :revision rev-1) |
---|
313 | :revision rev-1))) |
---|
314 | "http://psi.topicmaps.org/iso13250/model/instance")) |
---|
315 | roles-101))) |
---|
316 | ;Topic t101 (= Topic Maps 2002 |
---|
317 | ;standard) is subclass of |
---|
318 | ;topic t3a (semantic standard) |
---|
319 | (is-true t101-top) |
---|
320 | (is (= 1 (length role-101))) |
---|
321 | (is (string= "t3a" |
---|
322 | (topic-id (player (first (roles (parent (first role-101)) |
---|
323 | :revision rev-1)) |
---|
324 | :revision rev-1) |
---|
325 | rev-1 *TEST-TM*))) |
---|
326 | (is (string= "type-instance" |
---|
327 | (topic-id (instance-of |
---|
328 | (parent (first role-101) :revision rev-1)) |
---|
329 | rev-1 "core.xtm"))))))) |
---|
330 | |
---|
331 | |
---|
332 | (test test-error-detection |
---|
333 | "Test for the detection of common errors such as dangling |
---|
334 | references, duplicate PSIs or item identifiers" |
---|
335 | (declare (optimize (debug 3))) |
---|
336 | (with-fixture bare-test-db() |
---|
337 | (signals missing-reference-error |
---|
338 | (let |
---|
339 | ((di-xtm-dom |
---|
340 | (dom:document-element |
---|
341 | (cxml:parse-file *dangling_instanceof.xtm* (cxml-dom:make-dom-builder))))) |
---|
342 | (importer di-xtm-dom :xtm-id "missing-reference-error-1" |
---|
343 | :tm-id "http://www.isidor.us/unittests/baretests")))) |
---|
344 | (with-fixture bare-test-db() |
---|
345 | (signals missing-reference-error |
---|
346 | (let |
---|
347 | ((xtm-dom |
---|
348 | (dom:document-element |
---|
349 | (cxml:parse-file *dangling_topicref.xtm* (cxml-dom:make-dom-builder))))) |
---|
350 | (importer xtm-dom :xtm-id "missing-reference-error-2" |
---|
351 | :tm-id "http://www.isidor.us/unittests/baretests")))) |
---|
352 | (with-fixture bare-test-db() |
---|
353 | (signals not-mergable-error |
---|
354 | (let |
---|
355 | ((xtm-dom |
---|
356 | (dom:document-element |
---|
357 | (cxml:parse-file *duplicate_identifier.xtm* (cxml-dom:make-dom-builder))))) |
---|
358 | (importer xtm-dom :xtm-id "duplicate-identifier-error-1" |
---|
359 | :tm-id "http://www.isidor.us/unittests/baretests"))))) |
---|
360 | |
---|
361 | |
---|
362 | (test test-topic-t100 |
---|
363 | "test for the entire topic t100. checks all slot values and references" |
---|
364 | (let |
---|
365 | ((dir "data_base")) |
---|
366 | (with-fixture initialize-destination-db (dir) |
---|
367 | (xtm-importer:setup-repository *t100.xtm* dir :xtm-id *TEST-TM* |
---|
368 | :tm-id "http://www.isidor.us/unittests/topic-t100") |
---|
369 | (open-tm-store dir) |
---|
370 | (is (= 26 (length (elephant:get-instances-by-class 'TopicC)))) ;; are all topics in the db + std topics |
---|
371 | (is-true (get-item-by-id "t100" :revision 0)) ;; main topic |
---|
372 | (is-true (get-item-by-id "t3a" :revision 0)) ;; instanceOf |
---|
373 | (is-true (get-item-by-id "t50a" :revision 0)) ;; scope |
---|
374 | (is-true (get-item-by-id "t51" :revision 0)) ;; occurrence/type |
---|
375 | (is-true (get-item-by-id "t52" :revision 0)) ;; occurrence/resourceRef |
---|
376 | (is-true (get-item-by-id "t53" :revision 0)) ;; occurrence/type |
---|
377 | (is-true (get-item-by-id "t54" :revision 0)) ;; occurrence/type |
---|
378 | (is-true (get-item-by-id "t55" :revision 0)) ;; occurrence/type |
---|
379 | (let ((t100 (get-item-by-id "t100" :revision 0))) |
---|
380 | ;; checks instanceOf |
---|
381 | (is (= 1 (length (player-in-roles t100 :revision 0)))) |
---|
382 | (let* ((role-t100 (first (player-in-roles t100 :revision 0))) |
---|
383 | (assoc (parent role-t100 :revision 0)) |
---|
384 | (role-t3a (first (roles assoc :revision 0)))) |
---|
385 | (is (= 1 (length (psis (instance-of role-t100 :revision 0) :revision 0)))) |
---|
386 | (is (string= (uri (first (psis (instance-of role-t100 :revision 0) |
---|
387 | :revision 0))) |
---|
388 | "http://psi.topicmaps.org/iso13250/model/instance")) |
---|
389 | (is (= 1 (length (psis (instance-of role-t3a :revision 0) :revision 0)))) |
---|
390 | (is (string= (uri (first (psis (instance-of role-t3a :revision 0) |
---|
391 | :revision 0))) |
---|
392 | "http://psi.topicmaps.org/iso13250/model/type"))) |
---|
393 | ;; checks subjectIdentifier |
---|
394 | (is (= 1 (length (psis t100 :revision 0)))) |
---|
395 | (is (string= "http://psi.egovpt.org/standard/ISO+19115%3A+Geographic+Information+-+Metadata" |
---|
396 | (uri (first (psis t100 :revision 0))))) |
---|
397 | (is (equal (identified-construct (first (psis t100 :revision 0)) |
---|
398 | :revision 0) t100)) ;;other association part |
---|
399 | ;; checks names |
---|
400 | (is (= 2 (length (names t100 :revision 0)))) |
---|
401 | (loop for item in (names t100 :revision 0) |
---|
402 | do (is (or (string= (charvalue item) "ISO 19115") |
---|
403 | (and (string= (charvalue item) "ISO 19115:2003 Geographic Information - Metadata") |
---|
404 | (= (length (themes item :revision 0)) 1) |
---|
405 | (= (length (psis (first (themes item :revision 0)) |
---|
406 | :revision 0))) |
---|
407 | (string= (uri (first (psis (first (themes item :revision 0)) |
---|
408 | :revision 0))) |
---|
409 | "http://psi.egovpt.org/types/long-name"))))) |
---|
410 | (is-true (used-as-theme (get-item-by-id "t50a" :revision 0) |
---|
411 | :revision 0)) ;checks the other part of the association -> fails |
---|
412 | ;; checks occurrences |
---|
413 | (setf *TM-REVISION* 0) |
---|
414 | (is (= 4 (length (occurrences (get-item-by-id "t100"))))) |
---|
415 | (loop for item in (occurrences t100) |
---|
416 | when (elephant:associatedp (get-item-by-id "t51") 'datamodel::used-as-type item) |
---|
417 | do (progn |
---|
418 | (is (string= (charvalue item) "#t52")) |
---|
419 | (is (string= (uri (first (psis (instance-of item)))) "http://psi.egovpt.org/types/standardHasStatus"))) |
---|
420 | when (elephant:associatedp (get-item-by-id "t53") 'datamodel::used-as-type item) |
---|
421 | do (progn |
---|
422 | (is (string= (charvalue item) "The ISO 19115 standard ...")) |
---|
423 | (is (string= (datatype item) "http://www.w3.org/2001/XMLSchema#string")) |
---|
424 | (is (string= (uri (first (psis (instance-of item)))) "http://psi.egovpt.org/types/description"))) |
---|
425 | when (elephant:associatedp (get-item-by-id "t54") 'datamodel::used-as-type item) |
---|
426 | do (progn |
---|
427 | (is (string= (charvalue item) "2003-01-01")) |
---|
428 | (is (string= (datatype item) "http://www.w3.org/2001/XMLSchema#date")) |
---|
429 | (is (string= (uri (first (psis (instance-of item)))) "http://psi.egovpt.org/types/standardValidFromDate"))) |
---|
430 | when (elephant:associatedp (get-item-by-id "t55") 'datamodel::used-as-type item) |
---|
431 | do (progn |
---|
432 | (is (string= (charvalue item) "http://www.editeur.org/standards/ISO19115.pdf")) |
---|
433 | (is (string= (uri (first (psis (instance-of item)))) "http://psi.egovpt.org/types/links")))))))) |
---|
434 | |
---|
435 | |
---|
436 | (test test-setup-repository-xtm1.0 |
---|
437 | "tests the importer-xtm1.0 functions" |
---|
438 | (let |
---|
439 | ((dir "data_base")) |
---|
440 | (with-fixture initialize-destination-db (dir) |
---|
441 | (xtm-importer:setup-repository |
---|
442 | *sample_objects.xtm* dir |
---|
443 | :tm-id "http://www.isidor.us/unittests/xtm1.0-tests" |
---|
444 | :xtm-id *TEST-TM* :xtm-format :1.0) |
---|
445 | (setf *TM-REVISION* 0) |
---|
446 | (open-tm-store dir) |
---|
447 | ;14 + (23 core topics) |
---|
448 | (is (= 37 (length (elephant:get-instances-by-class 'TopicC)))) |
---|
449 | ;2 + (11 instanceOf) |
---|
450 | (is (= 13 (length (elephant:get-instances-by-class 'AssociationC)))) |
---|
451 | ;4 + (22 instanceOf-associations) |
---|
452 | (is (= 26 (length (elephant:get-instances-by-class 'RoleC)))) |
---|
453 | ;23 + (14 core topics) |
---|
454 | (is (= 37 (length (elephant:get-instances-by-class 'PersistentIdC)))) |
---|
455 | (is (= 0 (length (elephant:get-instances-by-class 'SubjectLocatorC)))) |
---|
456 | ;2 + (0 core topics) |
---|
457 | (is (= 2 (length (elephant:get-instances-by-class 'OccurrenceC)))) |
---|
458 | ;18 + (0 core topics) |
---|
459 | (is (= 18 (length (elephant:get-instances-by-class 'NameC)))) |
---|
460 | (let ((t-2526 (get-item-by-id "t-2526")) |
---|
461 | (t-2656 (get-item-by-id "t-2656")) |
---|
462 | (assoc (first (used-as-type (get-item-by-id "t89671052499"))))) |
---|
463 | (is (= (length (player-in-roles t-2526)) 1)) |
---|
464 | (is (= (length (psis t-2526)) 1)) |
---|
465 | (is (string= (uri (first (psis t-2526))) |
---|
466 | "http://psi.egovpt.org/types/serviceUsesTechnology")) |
---|
467 | (is (= (length (names t-2526)) 3)) |
---|
468 | (is (or (string= (charvalue (first (names t-2526))) |
---|
469 | "service uses technology") |
---|
470 | (string= (charvalue (second (names t-2526))) |
---|
471 | "service uses technology") |
---|
472 | (string= (charvalue (third (names t-2526))) |
---|
473 | "service uses technology"))) |
---|
474 | (is (or (string= (charvalue (first (names t-2526))) |
---|
475 | "uses technology") |
---|
476 | (string= (charvalue (second (names t-2526))) |
---|
477 | "uses technology") |
---|
478 | (string= (charvalue (third (names t-2526))) |
---|
479 | "uses technology"))) |
---|
480 | (is (or (string= (charvalue (first (names t-2526))) |
---|
481 | "used by service") |
---|
482 | (string= (charvalue (second (names t-2526))) |
---|
483 | "used by service") |
---|
484 | (string= (charvalue (third (names t-2526))) |
---|
485 | "used by service"))) |
---|
486 | (loop for name in (names t-2526) |
---|
487 | when (string= (charvalue name) "uses technology") |
---|
488 | do (is (= (length (themes name)) 1)) |
---|
489 | (is (eq (first (themes name)) (get-item-by-id "t-2555"))) |
---|
490 | when (string= (charvalue name) "used by service") |
---|
491 | do (is (= (length (themes name)) 1)) |
---|
492 | (is (eq (first (themes name)) (get-item-by-id "t-2593")))) |
---|
493 | (is (= (length (player-in-roles t-2656)) 2)) ;association + instanceOf |
---|
494 | (is (= (length (psis t-2656)) 1)) |
---|
495 | (is (string= (uri (first (psis t-2656))) |
---|
496 | "http://psi.egovpt.org/types/DO-NOT-SIGNAL-no-identifier-error")) |
---|
497 | (is (= (length (occurrences t-2656)) 2)) |
---|
498 | (loop for occ in (occurrences t-2656) |
---|
499 | when (eq (instance-of occ) (get-item-by-id "t-2625")) |
---|
500 | do (is (string= (charvalue occ) "0")) |
---|
501 | (is (string= (datatype occ) |
---|
502 | "http://www.w3.org/2001/XMLSchema#string")) |
---|
503 | when (eq (instance-of occ) (get-item-by-id "t-2626")) |
---|
504 | do (is (string= (charvalue occ) "unbounded")) |
---|
505 | (is (string= (datatype occ) |
---|
506 | "http://www.w3.org/2001/XMLSchema#string")) |
---|
507 | when (not (or (eq (instance-of occ) (get-item-by-id "t-2625")) |
---|
508 | (eq (instance-of occ) (get-item-by-id "t-2626")))) |
---|
509 | do (is-true (format t "bad occurrence found in t-2526"))) |
---|
510 | (is (= (length (roles assoc)) 2)) |
---|
511 | (loop for role in (roles assoc) |
---|
512 | when (eq (player role) (get-item-by-id "all-subjects")) |
---|
513 | do (is (eq (instance-of role) (get-item-by-id "broader-term"))) |
---|
514 | when (eq (player role) (get-item-by-id "t1106723946")) |
---|
515 | do (is (eq (instance-of role) (get-item-by-id "narrower-term"))) |
---|
516 | when (not (or (eq (player role) (get-item-by-id "all-subjects")) |
---|
517 | (eq (player role) (get-item-by-id "t1106723946")))) |
---|
518 | do (is-true (format t "bad role found in association: ~A" |
---|
519 | (topic-identifiers (player role))))))))) |
---|
520 | |
---|
521 | |
---|
522 | (test test-variants |
---|
523 | (let |
---|
524 | ((dir "data_base")) |
---|
525 | (with-fixture initialize-destination-db (dir) |
---|
526 | (xtm-importer:setup-repository |
---|
527 | *notificationbase.xtm* dir :xtm-id *TEST-TM* |
---|
528 | :tm-id "http://isidorus.org/test-tm") |
---|
529 | (setf *TM-REVISION* 0) |
---|
530 | (open-tm-store dir) |
---|
531 | (let ((variants (elephant:get-instances-by-class 'VariantC))) |
---|
532 | (is (= (length variants) 4)) |
---|
533 | (loop for variant in variants |
---|
534 | do (let ((resourceData (charvalue variant)) |
---|
535 | (d-type (datatype variant)) |
---|
536 | (string-type "http://www.w3.org/2001/XMLSchema#string") |
---|
537 | (itemIdentities (map 'list #'uri (item-identifiers variant))) |
---|
538 | (parent-name-value (charvalue (parent variant))) |
---|
539 | (scopes (map 'list #'uri |
---|
540 | (map 'list #'(lambda(x) |
---|
541 | (first (psis x))) ;these topics have only one psi |
---|
542 | (themes variant)))) |
---|
543 | (sort-psi "http://www.topicmaps.org/xtm/1.0/core.xtm#sort") |
---|
544 | (display-psi "http://www.topicmaps.org/xtm/1.0/core.xtm#display") |
---|
545 | (t50a-psi "http://psi.egovpt.org/types/long-name")) |
---|
546 | (cond |
---|
547 | ((string= resourceData "Long-Version") |
---|
548 | (is (string= parent-name-value "long version of a name")) |
---|
549 | (is (= (length (variants (parent variant))) 1)) |
---|
550 | (is (eql variant (first (variants (parent variant))))) |
---|
551 | (check-for-duplicate-identifiers variant) |
---|
552 | (is-false itemIdentities) |
---|
553 | (is (= (length scopes) 1)) |
---|
554 | (is (string= (first scopes) sort-psi)) |
---|
555 | (is (string= d-type string-type))) |
---|
556 | ((string= resourceData "Geographic Information - Metadata") |
---|
557 | (is (string= parent-name-value "ISO 19115")) |
---|
558 | (is (= (length (variants (parent variant))) 2)) |
---|
559 | (is (or (eql variant (first (variants (parent variant)))) |
---|
560 | (eql variant (second (variants (parent variant)))))) |
---|
561 | (check-for-duplicate-identifiers variant) |
---|
562 | (is (= (length scopes) 1)) |
---|
563 | (is (string= (first scopes) display-psi)) |
---|
564 | (is (= (length itemIdentities) 1)) |
---|
565 | (is (string= (first itemIdentities) |
---|
566 | "http://psi.egovpt.org/itemIdentifiers#t100_n1_v1")) |
---|
567 | (is (string= d-type string-type))) |
---|
568 | ((string= resourceData "ISO-19115") |
---|
569 | (check-for-duplicate-identifiers variant) |
---|
570 | (is (= (length itemIdentities) 1)) |
---|
571 | (is (string= (first itemIdentities) |
---|
572 | "http://psi.egovpt.org/itemIdentifiers#t100_n1_v2")) |
---|
573 | (is (= (length scopes) 1)) |
---|
574 | (is (string= (first scopes) sort-psi)) |
---|
575 | (is (string= d-type string-type))) |
---|
576 | ((string= resourceData "ISO/IEC-13250:2002") |
---|
577 | (is (string= parent-name-value "ISO/IEC 13250:2002: Topic Maps")) |
---|
578 | (is (= (length (variants (parent variant))) 1)) |
---|
579 | (is (eql variant (first (variants (parent variant))))) |
---|
580 | (check-for-duplicate-identifiers variant) |
---|
581 | (check-for-duplicate-identifiers variant) |
---|
582 | (is (= (length scopes) 2)) |
---|
583 | (is (or (string= (first scopes) t50a-psi) |
---|
584 | (string= (first scopes) sort-psi))) |
---|
585 | (is (or (string= (second scopes) t50a-psi) |
---|
586 | (string= (second scopes) sort-psi))) |
---|
587 | (is (= (length itemIdentities) 2)) |
---|
588 | (is (or (string= (first itemIdentities) |
---|
589 | "http://psi.egovpt.org/itemIdentifiers#t101_n2_v1") |
---|
590 | (string= (first itemIdentities) |
---|
591 | "http://psi.egovpt.org/itemIdentifiers#t101_n2_v2"))) |
---|
592 | (is (or (string= (second itemIdentities) |
---|
593 | "http://psi.egovpt.org/itemIdentifiers#t101_n2_v1") |
---|
594 | (string= (second itemIdentities) |
---|
595 | "http://psi.egovpt.org/itemIdentifiers#t101_n2_v2"))) |
---|
596 | (is (string= d-type string-type))) |
---|
597 | (t |
---|
598 | (is-true (format t "found bad resourceData in variant object: ~A~%" resourceData)))))))))) |
---|
599 | |
---|
600 | |
---|
601 | |
---|
602 | (test test-variants-xtm1.0 |
---|
603 | "tests the importer-xtm1.0 -> variants" |
---|
604 | (let ((dir "data_base")) |
---|
605 | (with-fixture initialize-destination-db (dir) |
---|
606 | (xtm-importer:setup-repository |
---|
607 | *sample_objects.xtm* dir :xtm-id *TEST-TM* :xtm-format :1.0 |
---|
608 | :tm-id "http://isidorus.org/test-tm") |
---|
609 | (open-tm-store dir) |
---|
610 | (is (= (length (elephant:get-instances-by-class 'VariantC)) 5)) |
---|
611 | (let ((t-2526 (get-item-by-id "t-2526"))) |
---|
612 | (loop for baseName in (names t-2526) |
---|
613 | do (let ((baseNameString (charvalue baseName)) |
---|
614 | (name-variants (variants baseName))) |
---|
615 | (loop for variant in name-variants |
---|
616 | do (is (string= (datatype variant) |
---|
617 | "http://www.w3.org/2001/XMLSchema#string"))) |
---|
618 | (cond |
---|
619 | ((string= baseNameString "service uses technology") |
---|
620 | (is (= (length name-variants) 2)) |
---|
621 | (loop for variant in name-variants |
---|
622 | do (is (eql baseName (parent variant))) |
---|
623 | (let ((variantName (charvalue variant))) |
---|
624 | (cond |
---|
625 | ((string= variantName "service-uses-technology") |
---|
626 | (is (= (length (themes variant)) 1)) |
---|
627 | (is (eql (first (themes variant)) |
---|
628 | (get-item-by-id "sort")))) |
---|
629 | ((string= variantName "service uses technology") |
---|
630 | (is (= (length (themes variant)) 1)) |
---|
631 | (is (eql (first (themes variant)) |
---|
632 | (get-item-by-id "display")))) |
---|
633 | (t |
---|
634 | (is-true (format t "basevariantName found in t-2526: ~A~%" variantName))))))) |
---|
635 | ((string= baseNameString "uses technology") |
---|
636 | (is (= (length name-variants) 2)) |
---|
637 | (loop for variant in name-variants |
---|
638 | do (is (eql baseName (parent variant))) |
---|
639 | (let ((variantName (charvalue variant))) |
---|
640 | (cond |
---|
641 | ((string= variantName "uses technology") |
---|
642 | (is (= (length (themes variant)) 2)) |
---|
643 | (is-true (find (get-item-by-id "t-2555") |
---|
644 | (themes variant) :test #'eql)) |
---|
645 | (is-true (find (get-item-by-id "display") |
---|
646 | (themes variant) :test #'eql))) |
---|
647 | ((string= variantName "uses-technology") |
---|
648 | (is (= (length (themes variant)) 3)) |
---|
649 | (is-true (find (get-item-by-id "t-2555") |
---|
650 | (themes variant) :test #'eql)) |
---|
651 | (is-true (find (get-item-by-id "display") |
---|
652 | (themes variant) :test #'eql)) |
---|
653 | (is-true (find (get-item-by-id "sort") |
---|
654 | (themes variant) :test #'eql))) |
---|
655 | (t |
---|
656 | (is-true (format t "bad variantName found in t-2526: ~A~%" variantName))))))) |
---|
657 | ((string= baseNameString "used by service") |
---|
658 | (is (= (length name-variants) 1)) |
---|
659 | (loop for variant in name-variants |
---|
660 | do (is (eql baseName (parent variant))) |
---|
661 | (is (string= (charvalue variant) "used-by-service")) |
---|
662 | (is (= (length (themes variant)) 3)) |
---|
663 | (is-true (find (get-item-by-id "t-2593") |
---|
664 | (themes variant) :test #'eql)) |
---|
665 | (is-true (find (get-item-by-id "display") |
---|
666 | (themes variant) :test #'eql)) |
---|
667 | (is-true (find (get-item-by-id "sort") |
---|
668 | (themes variant) :test #'eql)))) |
---|
669 | (t |
---|
670 | (is-true (format t "bad baseNameString found in names of t-2526: ~A~%" baseNameString)))))))))) |
---|
671 | |
---|
672 | |
---|
673 | (test test-topicmaps |
---|
674 | "Test the working of the TopicMap class" |
---|
675 | (with-fixture |
---|
676 | initialized-test-db() |
---|
677 | (let |
---|
678 | ((tms (elephant:get-instances-by-class 'd:TopicMapC))) |
---|
679 | (is (= 2 (length tms))) |
---|
680 | (is-false |
---|
681 | (set-exclusive-or |
---|
682 | '("http://www.isidor.us/unittests/testtm" |
---|
683 | "http://www.topicmaps.org/xtm/1.0/core.xtm") |
---|
684 | (mapcan (lambda (tm) |
---|
685 | (mapcar #'uri (item-identifiers tm :revision 0))) |
---|
686 | tms) :test #'string=))))) |
---|
687 | |
---|
688 | |
---|
689 | (test test-merge-topicmaps |
---|
690 | (let ((dir "data_base") |
---|
691 | (tm-id-1 "tm-id-1") |
---|
692 | (tm-id-2 "tm-id-2")) |
---|
693 | (with-fixture with-empty-db (dir) |
---|
694 | (xtm-importer:setup-repository *poems_light_tm_ii.xtm* |
---|
695 | dir :tm-id tm-id-1) |
---|
696 | (xtm-importer:import-from-xtm *poems_light_tm_ii_merge.xtm* |
---|
697 | dir :tm-id tm-id-2) |
---|
698 | (with-revision 0 |
---|
699 | (let ((tm-1 |
---|
700 | (d:identified-construct |
---|
701 | (first (elephant:get-instances-by-value |
---|
702 | 'd:ItemIdentifierC 'd:uri tm-id-1)))) |
---|
703 | (tm-2 |
---|
704 | (d:identified-construct |
---|
705 | (first (elephant:get-instances-by-value |
---|
706 | 'd:ItemIdentifierC 'd:uri tm-id-2))))) |
---|
707 | (is-true tm-1) |
---|
708 | (is-true tm-2) |
---|
709 | (is (eql tm-1 tm-2)) |
---|
710 | (is-false (set-exclusive-or (map 'list #'d:uri (item-identifiers tm-1)) |
---|
711 | (list tm-id-1 tm-id-2 |
---|
712 | "http://some.where/poems_light_tm_ii_1" |
---|
713 | "http://some.where/poems_light_tm_ii_2") |
---|
714 | :test #'string=)) |
---|
715 | (is (eql (reifier tm-1) |
---|
716 | (d:get-item-by-item-identifier |
---|
717 | "http://some.where/poems/topicMap-reifier"))) |
---|
718 | (is (= (length (d:topics tm-1)) (+ 9 3))) |
---|
719 | (is (= (length (d:associations tm-1)) (+ 1 3))) |
---|
720 | (is (= (length (d:in-topicmaps (d:get-item-by-id "schiller"))) 1)) |
---|
721 | (is (eql (first (d:in-topicmaps (d:get-item-by-id "schiller"))) tm-1)) |
---|
722 | |
---|
723 | |
---|
724 | (let ((schiller-1 (d:get-item-by-id |
---|
725 | "schiller" |
---|
726 | :revision (first (last (d:get-all-revisions))))) |
---|
727 | (schiller-2 (d:get-item-by-id |
---|
728 | "schiller" |
---|
729 | :revision (elt (d:get-all-revisions) |
---|
730 | (- (length (d:get-all-revisions)) 2))))) |
---|
731 | (is-true schiller-1) |
---|
732 | (is-false schiller-2))))))) |
---|
733 | |
---|
734 | |
---|
735 | (test test-merge-topicmaps-xtm1.0 |
---|
736 | (let ((dir "data_base") |
---|
737 | (tm-id-1 "tm-id-1")) |
---|
738 | (with-fixture with-empty-db (dir) |
---|
739 | (xtm-importer:setup-repository *poems_light_tm_reification_xtm1.0.xtm* |
---|
740 | dir :tm-id tm-id-1 :xtm-format :1.0) |
---|
741 | (open-tm-store dir) |
---|
742 | (with-revision 0 |
---|
743 | (let ((tm-1 |
---|
744 | (d:identified-construct |
---|
745 | (first (elephant:get-instances-by-value |
---|
746 | 'd:ItemIdentifierC 'd:uri tm-id-1))))) |
---|
747 | (is-true tm-1) |
---|
748 | (is (= (length (topics tm-1)) (+ 8 3))) |
---|
749 | (is (= (length (associations tm-1)) (+ 1 2))) |
---|
750 | (is (eql (reifier tm-1) |
---|
751 | (get-item-by-psi "#tm-reifier")))))))) |
---|
752 | |
---|
753 | |
---|
754 | (defun run-importer-tests () |
---|
755 | (run! 'importer-test)) |
---|
756 | |
---|
757 | |
---|