(in-package #:topic-maps.xtm.tests) (defvar *association-reifier-native* nil) (defun arr-current-p (map) (and (orr-current-p map) (every (lambda (a) (let ((r (item-reifier a))) (or (null r) (and (eq r (canonical-topic r)) (eq map (topic-parent r)) (eq a (topic-reified r)))))) (topic-map-associations map)))) (defun arr-model (map) (mm-fields "existingModel" (orr-model map) "canonicalAssociationReifierInverseEQ" (if (arr-current-p map) :true :false) "associationReifiers" (coerce (loop for a in (topic-map-associations map) collect (mm-fields "associationItemIdentifiers" (coerce (item-identifiers a) 'vector) "reifierItemIdentifiers" (coerce (when (item-reifier a) (item-identifiers (item-reifier a))) 'vector) "inverseReifiedEQ" (if (or (null (item-reifier a)) (eq a (topic-reified (item-reifier a)))) :true :false))) 'vector))) (defun arr-native-tests () ;; Native API probes, executed before Reader edits and repeated through ASDF. ;; No Reader calls or original registrations occur here. (setf *association-reifier-native* nil) (dolist (kind '("subjectIdentifier" "subjectLocator" "itemIdentity")) (let* ((map (make-topic-map)) (type (intern-topic map :item-identifier "urn:type")) (rt (intern-topic map :item-identifier "urn:role-type")) (s (intern-topic map :item-identifier "urn:scope")) (p (intern-topic map :item-identifier "urn:p")) (q (intern-topic map :item-identifier "urn:q")) (a (make-association map type (list (list rt p)) :scope (list s))) (b (make-association map type (list (list rt q)) :scope (list s))) (ra (first (association-roles a))) (rb (first (association-roles b))) (r (intern-topic map :item-identifier "urn:r")) (u (intern-topic map :item-identifier "urn:u"))) (add-item-identifier a "urn:a") (add-item-identifier b "urn:b") (add-item-identifier ra "urn:ra") (add-item-identifier rb "urn:rb") (check (format nil "association-reifier-native:~A:assign-and-inverse" kind) (and (eq a (set-item-reifier a r)) (eq b (set-item-reifier b u)) (eq r (item-reifier a)) (eq a (topic-reified r)) (eq b (topic-reified u)))) (let ((identity-kind (cond ((equal kind "subjectIdentifier") :subject-identifier) ((equal kind "subjectLocator") :subject-locator) (t :item-identifier)))) (add-topic-identifier p identity-kind "urn:common") (add-topic-identifier q identity-kind "urn:common")) (let ((c (canonical-association a)) (role (canonical-association-role ra))) (check (format nil "association-reifier-native:~A:merge-signatures-all-II-and-old-handles" kind) (and (= 1 (length (topic-map-associations map))) (eq c (canonical-association b)) (not (eq a c)) (not (eq b c)) (eq map (association-parent c)) (eq type (association-type c)) (equal (list s) (association-scope c)) (equal (list role) (association-roles c)) (eq role (canonical-association-role rb)) (eq c (association-role-parent role)) (eq (canonical-topic p) (canonical-topic q)) (eq (canonical-topic p) (association-role-player role)) (same-identifiers-p '("urn:a" "urn:b") (item-identifiers c)) (same-identifiers-p '("urn:ra" "urn:rb") (item-identifiers role)) (eq (canonical-topic r) (canonical-topic u)) (eq (canonical-topic r) (item-reifier c)) (same-identifiers-p '("urn:r" "urn:u") (item-identifiers (item-reifier c))) (eq c (topic-reified r)) (eq c (topic-reified u)) (arr-current-p map)))) (push (mm-fields "label" kind "kind" "native-TMDM-probe-not-original-contract" "model" (arr-model map) "oldAssociationRoleTopicHandlesResolveEQ" :true) *association-reifier-native*))) (let* ((map (make-topic-map)) (type (intern-topic map :item-identifier "urn:t")) (rt (intern-topic map :item-identifier "urn:rt")) (p (intern-topic map :item-identifier "urn:p")) (r (intern-topic map :item-identifier "urn:r")) (a (make-association map type (list (list rt p))))) (set-item-reifier a r) (add-item-identifier a "urn:a") (let ((b (make-association map type (list (list rt p))))) (set-item-reifier b r) (add-item-identifier b "urn:b") (check "association-reifier-native:equal-Associations-same-Reifier-native-normalization" (and (= 1 (length (topic-map-associations map))) (eq (canonical-association a) b) (eq r (item-reifier b)) (eq b (topic-reified r)) (same-identifiers-p '("urn:a" "urn:b") (item-identifiers b)) (arr-current-p map))) (push (mm-fields "label" "same-Reifier" "kind" "native-TMDM-probe-not-original-contract" "model" (arr-model map)) *association-reifier-native*))) (let* ((map (make-topic-map)) (type (intern-topic map :item-identifier "urn:t")) (rt (intern-topic map :item-identifier "urn:rt")) (p (intern-topic map :item-identifier "urn:p")) (q (intern-topic map :item-identifier "urn:q")) (a (make-association map type (list (list rt p)))) (b (make-association map type (list (list rt q)))) (r (intern-topic map :item-identifier "urn:r")) (u (intern-topic map :item-identifier "urn:u")) (o (add-occurrence p type "V"))) (set-item-reifier a r) (set-item-reifier b u) (dolist (row (list (list "different-Association" (lambda () (set-item-reifier b r))) (list "Occurrence-versus-Association" (lambda () (set-item-reifier o r))) (list "Map-versus-Association" (lambda () (set-item-reifier map r))) (list "late-Reifier-merge" (lambda () (merge-topics r u))))) (let* ((before (ik-state map)) (c (condition-from (second row)))) (check (format nil "association-reifier-native:~A:exact-atomic-conflict" (first row)) (and (eq (type-of c) 'reification-error) (eq :reifier-conflict (reification-error-code c)) (equal before (ik-state map)) (eq a (topic-reified r)) (eq b (topic-reified u)) (arr-current-p map))) (push (mm-fields "label" (first row) "kind" "native-TMDM-probe-not-original-contract" "condition" (mm-condition c) "nativeOperationUnchanged" (if (equal before (ik-state map)) :true :false)) *association-reifier-native*))) (add-item-identifier a "urn:association") (let* ((before (ik-state map)) (c (condition-from (lambda () (intern-topic map :item-identifier "urn:association"))))) (check "association-reifier-native:own-II-not-Reifier-Topic-II:atomic-conflict" (and (typep c 'item-identifier-error) (eq :duplicate-item-identifier (item-identifier-error-code c)) (equal before (ik-state map)))) (push (mm-fields "label" "own-II-not-Reifier-II" "kind" "native-TMDM-probe-not-original-contract" "condition" (mm-condition c) "nativeOperationUnchanged" :true) *association-reifier-native*))) (setf *association-reifier-native* (nreverse *association-reifier-native*)))