source: trunk/src/unit_tests/testing_db.lisp

Last change on this file was 452, checked in by lgiessmann, 14 years ago

datamodel: implemented the function "open-tm-store" which wrapps elephant:open-store and uses :register t to support mutliple isidorus instances on one database; implemented the wrapper function "close-tm-store" that calls elephant:close-store; => adapted all unit-tests to these changes

  • Property svn:eol-style set to native
File size: 7.7 KB
Line 
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(asdf:operate 'asdf:load-op 'FiveAM)
11(asdf:operate 'asdf:load-op 'cxml)
12(asdf:operate 'asdf:load-op 'elephant)
13(asdf:operate 'asdf:load-op 'isidorus)
14(load "../src/external/packages.lisp")
15(load "../src/external/pathnames.lisp")
16
17(use-package :it.bese.FiveAM)
18(use-package :base-tools)
19
20(def-suite testing-db
21    :description "compares saved objects in the db with the original objects")
22(in-suite testing-db)
23
24(defun set-up-test-db ()
25  "clears out the database and (re-)imports a defined topic map."
26  (ensure-directories-exist (make-pathname :directory '(:relative "data_base")))
27  (loop for filename in (com.gigamonkeys.pathnames:list-directory #p"data_base") do
28       (delete-file filename))
29     
30  ;; TODO
31  ;; sample_objects.xtm is inconsistent - e.g., topic "Subject" is instance of t-2497, but
32  ;; there is no topic with id t-2497 etc.
33  ;; 1) make sample_objects.xtm consistent --> OK
34  ;; 2) prepare a test that importer signals an error if the XTM file loaded is inconsistent
35  ;;    (NB: there are different possible inconsistencies: Inconsistent associations,
36  ;;     instanceofs, occurrences, role types etc.) --> OK
37  ;; 3) add also tests for associations --> OK
38
39  (importer "./sample_objects_2_0.xtm" "data_base")
40  (open-tm-store "data_base"))
41
42(defun tear-down-test-db ()
43  "make sure the elephant store is properly closed"
44  (close-tm-store))
45
46
47(def-fixture initialized-test-db ()
48  (set-up-test-db)
49  (&body)
50  (tear-down-test-db))
51
52
53;; searches for a topic(parent-id) which is an instanceOf in another topic(me)
54(defun get-instanceOf(me parent-id)
55  (let ((child-psi (elephant:get-instance-by-value 'PersistentIdC 'uri "http://psi.topicmaps.org/iso13250/model/instance"))
56        (parent-psi (elephant:get-instance-by-value 'PersisitentIdC 'uro "http://psi.topicmaps.org/iso13250/model/type"))
57        (parent-topic (elephant:get-instance-by-value 'TopicC 'topicid parent-id)))
58    (let ((child-roletype (loop for item in (elephant:get-instances-by-class 'TopicC)
59                             when (elephant:associatedp item 'psis child-psi)
60                             do (return item)))
61          (parent-roletype (loop for item in (elephant:get-instances-by-class 'TopicC)
62                              when (elephant:associatedp item 'psis parent-psi)
63                              do (return item))))
64      (let ((role (loop for item in (player-in-roles me)
65                     when (elephant:associatedp item 'roletype child-roletype)
66                     do (return item))))
67        (loop for item in (roles (parent-association role))
68           when (and (elephant:associatedp item 'roletype parent-roletype)
69                     (elephant:associatedp item 'player parent-topic))
70             do (return t))))))
71
72
73;; === topic tests ===================================================
74(test test-obj1
75  (with-fixture initialized-test-db()
76    (let ((obj (elephant:get-instance-by-value 'TopicC 'topicid "t1")))
77      (is (elephant:associatedp obj 'psis (elephant:get-instance-by-value 'PersistentIdC 'uri "http://www.networkedplanet.com/psi/npcl/meta-types/topic-type")))
78      (is (elephant:associatedp obj 'names (elephant:get-instance-by-value 'NameC 'name "Topic Type"))))))
79                   
80
81(test test-obj2
82  (with-fixture initialized-test-db()
83    (let ((obj (elephant:get-instance-by-value 'TopicC 'topicid "t8")))
84      (is (elephant:associatedp obj 'psis (elephant:get-instance-by-value 'PersistentIdC 'uri "http://www.networkedplanet.com/psi/npcl/meta-types/association-role-type")))
85      (is (get-instanceOf obj "t1"))
86      (is (elephant:associatedp obj 'names (elephant:get-instance-by-value 'NameC 'name "Association Role Type"))))))
87
88
89(test test-obj3
90  (with-fixture initialized-test-db ()
91    (let ((obj (elephant:get-instance-by-value 'TopicC 'topicid "t56")))
92      (is (elephant:associatedp obj 'psis (elephant:get-instance-by-value 'PersistentIdC 'uri "http://psi.egovpt.org/types/topicIsAboutSubject")))
93      (is (get-instanceOf obj "t7"))
94      (is (elephant:associatedp obj 'names (elephant:get-instance-by-value 'NameC name "topic is about subject"))))))
95
96
97(test test-obj4
98  (with-fixture initialized-test-db ()
99    (let ((obj (elephant:get-instance-by-value 'TopicC 'topicid "t100")))
100      (is (elephant:associatedp obj 'psis (elephant:get-instance-by-value 'PersistentIdC 'uri "http://psi.egovpt.org/standard/ISO+19115%3A+Geographic+Information+-+Metadata")))
101      (is (get-instanceOf obj "t3a"))
102      (is (elephant:associatedp obj 'names (elephant:get-instance-by-value 'NameC 'name "ISO 19115")))
103      (is (elephant:associatedp obj 'names (elephant:get-instance-by-value 'NameC 'name "ISO 19115:2003 Geographic Information - Metadata")))
104      ;; occurrence <---
105      ;; occurrence <---
106      ;; occurrence <---
107      ;; occurrence <---
108      )))
109
110
111;; === associations tests ============================================
112(test test-obj5
113  (with-fixture initialized-test-db ()
114    (let ((obj (elephant:get-instance-by-value 'AssociationC 'associationtype (elephant:get-instance-by-value 'TopicC 'topicid "t57")))
115          (t59 (elephant:get-instance-by-value 'TopicC 'topicid "t59"))
116          (t202 (elephant:get-instance-by-value 'TopicC 'topicid "t202"))
117          (t58 (elephant:get-instance-by-value 'TopicC 'topicid "t58"))
118          (t204 (elephant:get-instances-by-value 'TopicC 'topicid "t204")))
119      (let ((role-1 (first (roles obj)))
120            (role-2 (second (roles obj))))
121        (is (= 2 length (roles obj)))
122        (is (or (and (elephant:associatedp role-1 'player t202)
123                     (elephant:associatedp role-1 'roletype t59))
124                (and (elephant:associatedp role-1 'player t204)
125                     (elephant:associatedp role-1 'roletype t59))))
126        (is (or (and (elephant:associatedp role-2 'player t202)
127                     (elephant:associatedp role-2 'roletype t59))
128                (and (elephant:associatedp role-2 'player t204)
129                     (elephant:associatedp role-2 'roletype t59))))))))
130     
131
132(test test-obj6
133  (with-fixture initialized-test-db ()
134    (let ((obj (elephant:get-instance-by-value 'AssociationC 'associationtype (elephant:get-instance-by-value 'TopicC 'topicid "t64")))
135          (t63 (elephant:get-instance-by-value 'TopicC 'topicid "t63"))
136          (t301 (elephant:get-instance-by-value 'TopicC 'topicid "t301"))
137          (t62 (elephant:get-instance-by-value 'TopicC 'topicid "t62"))
138          (t100 (elephant:get-instance-by-value 'TopicC 'topicid "t100")))
139      (let ((role-1 (first (roles obj)))
140            (role-2 (second (roles obj))))
141        (is (= 2 (length (roles obj))))
142        (is (or (and (elephant:associatedp role-1 'player t301)
143                     (elephant:associatedp role-1 'roletype t63))
144                (and (elephant:associatedp role-1 'player t100)
145                     (elephant:associatedp role-1 'roletype t62))))
146        (is (or (and (elephant:associatedp role-2 'player t301)
147                     (elephant:associatedp role-2 'roletype t63))
148                (and (elephant:associatedp role-2 'player t100)
149                     (elephant:associatedp role-2 'roletype t62))))))))
150
151
152;; === db tests ======================================================
153(test test-closing-db 
154  ;; the point of this test is to check that an error is signaeld if there is no
155  ;; open elephant store -- therefore don't run this test with the
156  ;; fixture initialized-test-db!
157
158  ;;TODO: test is wrong, should expect the signalled error
159  ;;ELEPHANT:CONTROLLER-LOST-ERROR --> OK
160  (signals ELEPHANT:CONTROLLER-LOST-ERROR
161    (elephant:get-instance-by-value 'TopicC 'topicid "t-2502")))
162 
163
164(test test-inconsistent-file
165  (with-fixture initialized-test-db ()
166    (signals inconsistent-file-error
167      (progn
168        (importer "./inconsistent_2_0.xtm" "data_base")
169        (error 'inconsistent-file-error :message "test"))))) ;has to be thrown only if the file is inconsistent
170
171
172;(!run 'testing-db)
Note: See TracBrowser for help on using the repository browser.