]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - tests/xtm-item-identities.lisp
Integrate qualified XML anyType values into the XTM reader
[topic-maps.git] / tests / xtm-item-identities.lisp
1 (in-package #:topic-maps.xtm.tests)
2
3 (defparameter *item-identity-originals*
4 '("itemid-occurrence" "occurrence-duplicate-iid" "itemid-association"
5 "association-duplicate-iid" "association-duplicate-iid2" "association-duplicate-iid3"
6 "itemid-role" "role-duplicate-iid" "role-duplicate-iid2"))
7 (defun ik-items (map) (append (all-occurrences map) (topic-map-associations map) (as-roles map)))
8 (defun ik-state (map)
9 (list (mm-state map) (loop for i in (topic-maps.tmdm::map-information-items map) collect (list i (item-identifiers i)))))
10 (defun ik-current-p (map) (and (as-current-p map) (topic-maps.tmdm::validate-map-item-identifiers map)))
11 (defun ik-model (map)
12 (mm-fields "nativeModel" (as-model map) "globalItemIdentifiersUnique" (if (ik-current-p map) :true :false)
13 "items" (coerce (loop for i in (ik-items map) collect
14 (mm-fields "kind" (string (type-of i)) "identifiers" (coerce (item-identifiers i) 'vector))) 'vector)))
15 (defun ik-observe (raw key)
16 ;; Observe actual native handles at the shared productive metadata boundary.
17 ;; AS-OBSERVE also retains pre-normalization Association/Role handles, scoped
18 ;; to the returned real map rather than private TMDM preflight graphs.
19 (let ((reader (symbol-function 'topic-maps.xtm::read-item-identities))
20 (held nil) (map nil) (native-held nil) (stages nil) (calls 0) (same nil))
21 (unwind-protect
22 (progn
23 (setf (symbol-function 'topic-maps.xtm::read-item-identities)
24 (lambda (node item) (pushnew item held :test #'eq) (funcall reader node item)))
25 (multiple-value-setq (map native-held stages calls same) (as-observe raw key)))
26 (setf (symbol-function 'topic-maps.xtm::read-item-identities) reader))
27 (values map (union held native-held :test #'eq) stages calls same)))
28 (defun ik-held-p (map held)
29 (every (lambda (i) (member (topic-maps.tmdm::canonical-item i) (ik-items map) :test #'eq)) held))
30 (defun ik-pure (label map)
31 (let ((before (ik-state map)) (held (topic-maps.tmdm::map-information-items map)) (cx (mm-cxtm map)))
32 (check (format nil "item-identity:~A:pure-CXTM-identifiers-and-handles" label)
33 (and (equalp cx (mm-cxtm map)) (equal before (ik-state map)) (ik-current-p map)
34 (every (lambda (i) (eq i (topic-maps.tmdm::canonical-item i))) held))) cx))
35 (defun ik-original-model-checks (name map)
36 (let* ((occurrence-p (search "occurrence" name)) (role-p (search "role" name))
37 (item (cond (occurrence-p (first (all-occurrences map))) (role-p (first (as-roles map))) (t (first (topic-map-associations map)))))
38 (suffix (cond (occurrence-p "the-occurrence") (role-p "the-role") (t "the-association")))
39 (ids (mapcar (lambda (s) (concatenate 'string *document* "#" s))
40 (if (member name '("association-duplicate-iid2" "association-duplicate-iid3") :test #'equal)
41 '("the-association" "the-association2") (list suffix)))))
42 (check (format nil "item-identity-original:~A:exact-native-owner-identifiers-no-extra-topics" name)
43 (and (= (if occurrence-p 2 3) (length (topic-map-topics map)))
44 (= (if occurrence-p 1 0) (length (all-occurrences map)))
45 (= (if occurrence-p 0 1) (length (topic-map-associations map)))
46 (= (if occurrence-p 0 1) (length (as-roles map)))
47 (same-identifiers-p ids (item-identifiers item))
48 (every (lambda (other) (or (eq other item) (null (item-identifiers other)))) (ik-items map))
49 (every (lambda (topic) (and (= 1 (length (item-identifiers topic)))
50 (null (topic-subject-identifiers topic)) (null (topic-subject-locators topic))
51 (null (topic-reified topic)) (null (topic-names topic)))) (topic-map-topics map))
52 (null (item-identifiers map)) (null (item-reifier map)) (ik-current-p map)))
53 (check (format nil "item-identity-original:~A:exact-parent-type-player-scope-value" name)
54 (if occurrence-p
55 (and (eq (by-id map "topic") (occurrence-parent item)) (eq (by-id map "occtype") (occurrence-type item))
56 (equal "Testing resource data." (occurrence-value item)) (equal (string-datatype) (occurrence-datatype item))
57 (null (occurrence-scope item)))
58 (let* ((a (first (topic-map-associations map))) (r (first (association-roles a))))
59 (and (eq map (association-parent a)) (eq a (association-role-parent r))
60 (eq (by-id map "assoctype") (association-type a)) (eq (by-id map "roletype") (association-role-type r))
61 (eq (by-id map "topic") (association-role-player r)) (null (association-scope a))
62 (equal (list r) (topic-roles-played (by-id map "topic")))))))
63 (check (format nil "item-identity-original:~A:each-locator-on-exactly-one-canonical-item" name)
64 (every (lambda (id) (= 1 (count-if (lambda (i) (member id (item-identifiers i) :test #'equal))
65 (topic-maps.tmdm::map-information-items map)))) ids))))
66 (defun item-identity-original-contracts ()
67 (setf *item-identity-outputs* nil)
68 (let ((previous (copy-list *cases*)))
69 (dolist (name *item-identity-originals*)
70 (let* ((id (format nil "xtm2/in/~A.xtm" name))
71 (*document* (concatenate 'string "https://xtm-tests.example.invalid/cd165b150176c1d6842b37be9cc9051b40d4996b/" id))
72 (raw (file-bytes (corpus-path id))) (copy (copy-seq raw))
73 (baseline (corpus-path (format nil "xtm2/baseline/~A.xtm.cxtm" name))) (expected (file-bytes baseline))
74 (case (topic-maps.test-foundation:make-test-case :id id :category :valid :source-pathname (corpus-path id)
75 :document-iri *document* :expected-outcome :cxtm-equal :expected-baseline baseline
76 :clauses '("XTM 4.3.3-4.3.4,4.6,4.15,4.18-4.19" "TMDM 5.1,5.6-5.8,6.5-6.7" "CXTM 3,4")))
77 (map nil) (held nil) (stages nil) (calls 0) (same nil) (actual nil) (c nil))
78 (check (format nil "item-identity-original:~A:new-case-once" name)
79 (null (find id *cases* :key #'topic-maps.test-foundation:test-case-id :test #'equal)))
80 (setf *cases* (append *cases* (list case)))
81 (handler-case
82 (progn
83 (multiple-value-setq (map held stages calls same) (ik-observe raw id))
84 (ik-original-model-checks name map)
85 (check (format nil "item-identity-original:~A:real-qualified-parser-original-octets" name)
86 (and (= 1 calls) same (equalp copy raw)))
87 (check (format nil "item-identity-original:~A:all-observed-native-handles-live" name) (ik-held-p map held))
88 (when (search "duplicate" name)
89 (check (format nil "item-identity-original:~A:actual-native-replacement-handles" name)
90 (some (lambda (i) (not (eq i (topic-maps.tmdm::canonical-item i)))) held)))
91 (setf actual (ik-pure name map))
92 (let ((other (deserialize-octets raw :document-iri *document* :source-key "different:item-identity-provenance")))
93 (check (format nil "item-identity-original:~A:source-key-independent-identities-and-bytes" name)
94 (and (equalp (ik-model map) (ik-model other)) (equalp actual (mm-cxtm other))))))
95 (error (condition) (setf c condition)))
96 (record-original-result case actual expected c)
97 (push (mm-fields "id" id "documentIRI" *document* "sourceKey" id "sourceBytes" (length raw)
98 "sourceHex" (format nil "~{~2,'0X~}" (coerce raw 'list)) "sourceText" (babel:octets-to-string raw :encoding :utf-8)
99 "qualifiedParserCalls" calls "originalOctetsEQ" (if same :true :false)
100 "model" (when map (ik-model map)) "normalizationStages" (coerce (mapcar (lambda (s) (coerce s 'vector)) stages) 'vector)
101 "observedNativeHandles" (length held) "replacedNativeHandles" (count-if (lambda (i) (not (eq i (topic-maps.tmdm::canonical-item i)))) held)
102 "oldHandlesCanonicalAndLive" (if (and map (ik-held-p map held)) :true :false)
103 "actualBytes" (when actual (length actual)) "expectedBytes" (length expected)
104 "actualCXTM" (when actual (babel:octets-to-string actual :encoding :utf-8)) "expectedCXTM" (babel:octets-to-string expected :encoding :utf-8)
105 "firstDifferentByte" (when actual (mismatch actual expected)) "condition" (mm-condition c)
106 "status" (string-downcase (string (topic-maps.test-foundation:test-case-status case)))) *item-identity-outputs*)
107 (when c (error c))
108 (check (format nil "item-identity-original:~A:complete-original-CXTM-byte-exact" name) (equalp actual expected))))
109 (check "item-identity-original:requested-membership-unique-all-prior-cases-preserved"
110 (and (every (lambda (case) (and (member case *cases* :test #'eq) (eq :pass (topic-maps.test-foundation:test-case-status case)))) previous)
111 (same-identifiers-p (mapcar #'topic-maps.test-foundation:test-case-id (set-difference *cases* previous :test #'eq))
112 (mapcar (lambda (n) (format nil "xtm2/in/~A.xtm" n)) *item-identity-originals*))
113 (every (lambda (case) (= 1 (count (topic-maps.test-foundation:test-case-id case) *cases* :key #'topic-maps.test-foundation:test-case-id :test #'equal))) *cases*))))
114 (setf *item-identity-outputs* (nreverse *item-identity-outputs*)))
115
116 (defun ik-ids (ids) (format nil "~{<itemIdentity href='~A'/>~}" ids))
117 (defun ik-occ (ids &key (type "#t") (value "V") scope)
118 (format nil "<occurrence>~A<type><topicRef href='~A'/></type>~A<resourceData>~A</resourceData></occurrence>"
119 (ik-ids ids) type (if scope (format nil "<scope>~{<topicRef href='~A'/>~}</scope>" scope) "") value))
120 (defun ik-role (ids &optional (type "#r") (player "#p"))
121 (format nil "<role>~A<type><topicRef href='~A'/></type><topicRef href='~A'/></role>" (ik-ids ids) type player))
122 (defun ik-assoc (ids roles &key (type "#t") scope)
123 (format nil "<association>~A<type><topicRef href='~A'/></type>~A~{~A~}</association>"
124 (ik-ids ids) type (if scope (format nil "<scope>~{<topicRef href='~A'/>~}</scope>" scope) "") roles))
125 (defun ik-probe (label body verify &optional replacement)
126 (let* ((raw (bytes (document body))) (copy (copy-seq raw)))
127 (multiple-value-bind (map held stages calls same) (ik-observe raw label)
128 (check (format nil "item-identity:~A:native-EQ-parents-types-scopes-players-inverses" label)
129 (and (= 1 calls) same (equalp copy raw) (ik-current-p map) (ik-held-p map held)))
130 (funcall verify map)
131 (when replacement
132 (check (format nil "item-identity:~A:old-handles-forward-to-current-items" label)
133 (some (lambda (i) (not (eq i (topic-maps.tmdm::canonical-item i)))) held)))
134 (let ((cx (ik-pure label map)))
135 (push (mm-fields "label" label "documentIRI" *document* "sourceKey" label "sourceText" (document body)
136 "model" (ik-model map) "CXTM" (babel:octets-to-string cx :encoding :utf-8)
137 "observedNativeHandles" (length held) "replacedNativeHandles" (count-if (lambda (i) (not (eq i (topic-maps.tmdm::canonical-item i)))) held)
138 "oldHandlesCanonicalAndLive" :true "normalizationStages" (coerce (mapcar (lambda (s) (coerce s 'vector)) stages) 'vector)) *item-identity-controls*)) map)))
139 (defun ik-only-ids (label kind ids count)
140 (lambda (map)
141 (let ((items (remove-if-not (lambda (i) (typep i kind)) (ik-items map))))
142 (check (format nil "item-identity:~A:exact-identifier-union-no-extra-topics" label)
143 (and (= count (length items))
144 (= (if (eq kind 'occurrence) 2 3) (length (topic-map-topics map)))
145 (every (lambda (i) (same-identifiers-p ids (item-identifiers i))) items))))))
146 (defun ik-error (label body class code &key resolver)
147 ;; Preserve the native condition and show that each failing ID assignment is
148 ;; checked before mutation. XTM/XML source contexts and causes remain intact.
149 (let ((saved (symbol-function 'add-item-identifier)) (c nil) (failed-assignments nil)
150 (raw (bytes (ss-unsupported-source (document body) code label))))
151 (unwind-protect
152 (progn
153 (setf (symbol-function 'add-item-identifier)
154 (lambda (item iri)
155 (let* ((map (topic-maps.tmdm::item-topic-map item)) (before (ik-state map)))
156 (handler-case (funcall saved item iri)
157 (error (condition)
158 (push (list (string (type-of item)) iri (equal before (ik-state map))) failed-assignments)
159 (error condition))))))
160 (setf c (condition-from (lambda () (deserialize-octets raw :document-iri *document* :source-key label :resource-resolver resolver)))))
161 (setf (symbol-function 'add-item-identifier) saved))
162 (let ((actual-code (cond ((typep c 'topic-maps.xtm:xtm-error) (error-code c))
163 ((typep c 'item-identifier-error) (item-identifier-error-code c)))))
164 (check (format nil "item-identity-error:~A:exact-class-code-intended-cause" label)
165 (and (eq (type-of c) class) (eq code actual-code)))
166 (when (typep c 'topic-maps.xtm:xtm-error)
167 (check (format nil "item-identity-error:~A:document-source-position-cause" label)
168 (and (equal *document* (error-document-iri c)) (equal label (error-source-key c))
169 (if (typep c 'xtm-xml-error) (topic-maps.xtm:error-cause c)
170 (and (integerp (error-line c)) (integerp (error-column c)))))))
171 (when (typep c 'item-identifier-error)
172 (check (format nil "item-identity-error:~A:failed-native-assignment-atomic-not-merged-by-II" label)
173 (and failed-assignments (every #'third failed-assignments))))
174 (push (mm-fields "label" label "documentIRI" *document* "sourceKey" label "sourceText" (babel:octets-to-string raw :encoding :utf-8)
175 "condition" (mm-condition c) "nativeIdentifierCode" (when (typep c 'item-identifier-error) (string-downcase (string actual-code)))
176 "nativeConditionHasNoSourcePositionSlots" (if (typep c 'item-identifier-error) :true :false)
177 "rejectedAssignments" (coerce (mapcar (lambda (x) (mm-fields "itemKind" (first x) "locator" (second x) "nativeAssignmentUnchanged" (if (third x) :true :false))) failed-assignments) 'vector)) *item-identity-controls*)) c))
178 (defun item-identity-tests ()
179 (setf *item-identity-controls* nil)
180 (dolist (kind '(occurrence association association-role))
181 (dolist (row '(("one-II" ("urn:first")) ("multiple-and-repeated-II" ("urn:first" "urn:second" "urn:first"))))
182 (let* ((label (format nil "~A:~A" kind (first row))) (ids (second row))
183 (body (ecase kind
184 (occurrence (format nil "<topic id='p'>~A</topic>" (ik-occ ids)))
185 (association (ik-assoc ids (list (ik-role nil))))
186 (association-role (ik-assoc nil (list (ik-role ids)))))))
187 (ik-probe label body (ik-only-ids label kind (remove-duplicates ids :test #'equal) 1))))
188 (let* ((label (format nil "~A:equal-items-different-II" kind))
189 (body (ecase kind
190 (occurrence (format nil "<topic id='p'>~A~A</topic>" (ik-occ '("urn:first")) (ik-occ '("urn:second"))))
191 (association (concatenate 'string (ik-assoc '("urn:first") (list (ik-role nil))) (ik-assoc '("urn:second") (list (ik-role nil)))))
192 (association-role (ik-assoc nil (list (ik-role '("urn:first")) (ik-role '("urn:second"))))))))
193 (ik-probe label body (ik-only-ids label kind '("urn:first" "urn:second") 1) t)))
194 (dolist (kind '(occurrence association association-role))
195 (let* ((label (format nil "~A:relative-percent-Unicode-II" kind))
196 (ids '("../asset#one" "#two" "../%E9%A6%AC#three" "https://id.example/a#four"))
197 (body (ecase kind (occurrence (format nil "<topic id='p'>~A</topic>" (ik-occ ids)))
198 (association (ik-assoc ids (list (ik-role nil)))) (association-role (ik-assoc nil (list (ik-role ids)))))))
199 (ik-probe label body (ik-only-ids label kind (mapcar #'mm-child-iri ids) 1))))
200 ;; Corresponding Roles in duplicate Associations occur in reversed source
201 ;; order; II must follow actual Type/Player, never list position.
202 (ik-probe "role-II-match-by-signature-after-association-normalization"
203 (concatenate 'string
204 (ik-assoc '("urn:as1") (list (ik-role '("urn:r1") "#r" "#p") (ik-role '("urn:r2") "#rr" "#q")))
205 (ik-assoc '("urn:as2") (list (ik-role '("urn:r4") "#rr" "#q") (ik-role '("urn:r3") "#r" "#p"))))
206 (lambda (map)
207 (let ((a (first (topic-map-associations map))))
208 (check "item-identity:role-signature:correct-unions-parent-and-inverses"
209 (and (= 1 (length (topic-map-associations map))) (= 2 (length (association-roles a)))
210 (same-identifiers-p '("urn:as1" "urn:as2") (item-identifiers a))
211 (loop for player in '("p" "q") for ids in '(("urn:r1" "urn:r3") ("urn:r2" "urn:r4")) always
212 (same-identifiers-p ids (item-identifiers (find (by-id map player) (association-roles a) :key #'association-role-player :test #'eq)))))))) t)
213 (ik-late-merges)
214 (ik-negative-tests)
215 (ik-import-tests)
216 (setf *item-identity-controls* (nreverse *item-identity-controls*)))
217 (defun ik-late-merges ()
218 (dolist (kind '("subjectIdentifier" "subjectLocator" "itemIdentity"))
219 (let* ((label (concatenate 'string "late-" kind))
220 (body (concatenate 'string
221 (format nil "<topic id='p'>~A</topic><topic id='q'>~A</topic>"
222 (ik-occ '("urn:o1") :type "#t" :scope '("#s")) (ik-occ '("urn:o2") :type "#u" :scope '("#v")))
223 (ik-assoc '("urn:a1") (list (ik-role '("urn:r1") "#r" "#p")) :type "#t" :scope '("#s"))
224 (ik-assoc '("urn:a2") (list (ik-role '("urn:r2") "#rr" "#q")) :type "#u" :scope '("#v"))
225 (format nil "<topic id='p2'><itemIdentity href='#p'/><~A href='urn:owner'/></topic><topic id='q2'><itemIdentity href='#q'/><~A href='urn:owner'/></topic><topic id='t'><~A href='urn:type'/></topic><topic id='u'><~A href='urn:type'/></topic><topic id='r'><~A href='urn:role'/></topic><topic id='rr'><~A href='urn:role'/></topic><topic id='s'><~A href='urn:scope'/></topic><topic id='v'><~A href='urn:scope'/></topic>" kind kind kind kind kind kind kind kind))))
226 (ik-probe label body
227 (lambda (map)
228 (check (format nil "item-identity:~A:all-three-item-unions-and-native-relations" label)
229 (and (= 4 (length (topic-map-topics map))) (= 1 (length (all-occurrences map)))
230 (= 1 (length (topic-map-associations map))) (= 1 (length (as-roles map)))
231 (same-identifiers-p '("urn:o1" "urn:o2") (item-identifiers (first (all-occurrences map))))
232 (same-identifiers-p '("urn:a1" "urn:a2") (item-identifiers (first (topic-map-associations map))))
233 (same-identifiers-p '("urn:r1" "urn:r2") (item-identifiers (first (as-roles map))))
234 (eq (by-id map "p") (by-id map "q")) (eq (by-id map "s") (by-id map "v"))))) t))))
235 (defun ik-negative-tests ()
236 (dolist (kind '(occurrence association association-role))
237 (dolist (bad '("%ZZ" "%C3%28" "a#b#c"))
238 (let ((body (ecase kind (occurrence (format nil "<topic id='p'>~A</topic>" (ik-occ (list bad))))
239 (association (ik-assoc (list bad) (list (ik-role nil)))) (association-role (ik-assoc nil (list (ik-role (list bad))))))))
240 (ik-error (format nil "~A:invalid-II:~A" kind bad) body 'xtm-rejection
241 (cond ((equal bad "%ZZ") :invalid-percent-escape) ((equal bad "%C3%28") :invalid-percent-utf8) (t :invalid-iri)))))
242 (let* ((label (format nil "~A:II-collides-with-map" kind))
243 (body (ecase kind (occurrence (format nil "<topic id='p'>~A</topic>" (ik-occ '("urn:collision"))))
244 (association (ik-assoc '("urn:collision") (list (ik-role nil))))
245 (association-role (ik-assoc nil (list (ik-role '("urn:collision"))))))))
246 (ik-error label (concatenate 'string "<itemIdentity href='urn:collision'/>" body) 'item-identifier-error :duplicate-item-identifier)))
247 (ik-error "different-occurrences-same-II" (format nil "<topic id='p'>~A~A</topic>" (ik-occ '("urn:collision")) (ik-occ '("urn:collision") :value "different")) 'item-identifier-error :duplicate-item-identifier)
248 (ik-error "different-associations-same-II" (concatenate 'string (ik-assoc '("urn:collision") (list (ik-role nil))) (ik-assoc '("urn:collision") (list (ik-role nil)) :type "#other")) 'item-identifier-error :duplicate-item-identifier)
249 (ik-error "different-roles-same-II" (ik-assoc nil (list (ik-role '("urn:collision") "#r" "#p") (ik-role '("urn:collision") "#r" "#q"))) 'item-identifier-error :duplicate-item-identifier)
250 (ik-error "same-role-signature-different-parents-same-II" (concatenate 'string (ik-assoc nil (list (ik-role '("urn:collision")))) (ik-assoc nil (list (ik-role '("urn:collision"))) :type "#other")) 'item-identifier-error :duplicate-item-identifier)
251 (ik-error "association-role-cross-type-collision" (ik-assoc '("urn:collision") (list (ik-role '("urn:collision")))) 'item-identifier-error :duplicate-item-identifier)
252 (ik-error "occurrence-association-cross-type-collision" (concatenate 'string (format nil "<topic id='p'>~A</topic>" (ik-occ '("urn:collision"))) (ik-assoc '("urn:collision") (list (ik-role nil)))) 'item-identifier-error :duplicate-item-identifier)
253 (ik-error "II-stays-conflict-after-topic-merging"
254 (concatenate 'string (ik-assoc '("urn:collision") (list (ik-role nil "#r" "#p")))
255 (ik-assoc '("urn:other") (list (ik-role nil "#r" "#q")))
256 "<topic id='p'><subjectIdentifier href='urn:owner'/></topic><topic id='q'><subjectIdentifier href='urn:owner'/></topic>"
257 (ik-assoc '("urn:collision") (list (ik-role nil "#r" "#other")))) 'item-identifier-error :duplicate-item-identifier)
258 (dolist (row '(("occurrence-II-after-type" "<topic id='p'><occurrence><type><topicRef href='#t'/></type><itemIdentity href='urn:o'/><resourceData>V</resourceData></occurrence></topic>" :element-order)
259 ("association-II-after-type" "<association><type><topicRef href='#t'/></type><itemIdentity href='urn:a'/><role><type><topicRef href='#r'/></type><topicRef href='#p'/></role></association>" :element-order)
260 ("role-II-after-type" "<association><type><topicRef href='#t'/></type><role><type><topicRef href='#r'/></type><itemIdentity href='urn:r'/><topicRef href='#p'/></role></association>" :element-order)
261 ("II-in-type" "<association><type><itemIdentity href='urn:a'/></type></association>" :unexpected-element)
262 ("II-in-scope" "<association><type><topicRef href='#t'/></type><scope><itemIdentity href='urn:a'/></scope></association>" :unexpected-element)
263 ("II-not-empty" "<association><itemIdentity href='urn:a'><topicRef href='#p'/></itemIdentity></association>" :unexpected-child)
264 ("II-missing-href" "<association><itemIdentity/></association>" :missing-attribute)))
265 (ik-error (first row) (second row) 'xtm-rejection (third row)))
266 (ik-error "malformed-XML" "<association><itemIdentity href='urn:a'></association>" 'xtm-xml-error :xml-not-well-formed)
267 (ik-error "occurrence-reification-remains-unsupported" "<topic id='p'><occurrence reifier='#r'><itemIdentity href='urn:o'/><type><topicRef href='#t'/></type><resourceData datatype='http://www.w3.org/2001/XMLSchema#anyType'>V</resourceData></occurrence></topic>" 'xtm-unsupported :resource-resolver-required)
268 ;; Explicitly excluded original: preserve XML-ID uniqueness, no registration.
269 (let* ((id "xtm2/in/occurrence-duplicate-iid2.xtm") (raw (file-bytes (corpus-path id)))
270 (c (condition-from (lambda () (deserialize-octets raw :document-iri *document* :source-key id)))))
271 (check "item-identity:excluded-duplicate-XML-ID-not-registered"
272 (and (eq (type-of c) 'xtm-rejection) (eq :duplicate-id (error-code c))
273 (null (find id *cases* :key #'topic-maps.test-foundation:test-case-id :test #'equal))))
274 (push (mm-fields "label" "excluded-duplicate-XML-ID" "id" id "sourceHex" (format nil "~{~2,'0X~}" (coerce raw 'list))
275 "sourceText" (babel:octets-to-string raw :encoding :utf-8) "condition" (mm-condition c) "registered" :false) *item-identity-controls*)))
276 (defun ik-import-tests ()
277 (let* ((child (mm-child-iri "child.xtm"))
278 (raw (bytes (document (concatenate 'string (format nil "<topic id='p'>~A</topic>" (ik-occ '("urn:child-occurrence")))
279 (ik-assoc '("urn:child-association") (list (ik-role '("urn:child-role")))))))))
280 (mm-call "item-identities-native-import" (document (mm-directive "child.xtm")) (list (list child raw "identifier-child"))
281 (lambda (map imports calls) (declare (ignore calls))
282 (check "item-identity:import:all-three-identifier-sets-native-EQ-source-preserved"
283 (and (ik-current-p map)
284 (equal '("urn:child-occurrence") (item-identifiers (first (all-occurrences map))))
285 (equal '("urn:child-association") (item-identifiers (first (topic-map-associations map))))
286 (equal '("urn:child-role") (item-identifiers (first (as-roles map))))
287 (every (lambda (record) (every (lambda (item)
288 (same-identifiers-p (item-identifiers item) (item-identifiers (funcall (second record) item)))) (ik-items (first record)))) imports))))))
289 (let* ((child (mm-child-iri "child.xtm"))
290 (raw (bytes (document (ik-assoc '("urn:map-collision") (list (ik-role nil))))))
291 (body (concatenate 'string "<itemIdentity href='urn:map-collision'/>" (mm-directive "child.xtm")))
292 (c (ik-error "import-II-conflict-cause" body 'topic-maps.xtm:xtm-resource-error :mergemap-import-failure
293 :resolver (lambda (&rest args) (declare (ignore args)) (values raw "conflicting-child")))))
294 (declare (ignore child))
295 (check "item-identity:import-conflict:original-native-Cause-retained"
296 (and (typep (topic-maps.xtm:error-cause c) 'item-identifier-error)
297 (eq :duplicate-item-identifier (item-identifier-error-code (topic-maps.xtm:error-cause c)))))))