source: branches/new-datamodel/src/unit_tests/testing_db.lisp

Last change on this file was 26, checked in by lgiessmann, 15 years ago

added a license header to all files where the isidorus license is mentioned and referenced, in the ajax file there is also a reference to the MIT-license; an edit/create template for fragments is implemented in the ajax module, but it\'s really terrible and not really useable - this should be only the initial idea of realizing such a functionality\!

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