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 | (defpackage :fixtures |
---|
11 | (:use |
---|
12 | :common-lisp |
---|
13 | :xml-importer |
---|
14 | :datamodel |
---|
15 | :it.bese.FiveAM |
---|
16 | :unittests-constants) |
---|
17 | (:import-from :constants |
---|
18 | *xtm2.0-ns*) |
---|
19 | (:import-from :xml-tools |
---|
20 | xpath-child-elems-by-qname |
---|
21 | xpath-select-location-path) |
---|
22 | (:import-from :exceptions |
---|
23 | missing-reference-error |
---|
24 | duplicate-identifier-error) |
---|
25 | (:export :atom-test-db |
---|
26 | :bare-test-db |
---|
27 | :clean-out-db |
---|
28 | :initialized-test-db |
---|
29 | :initialize-destination-db |
---|
30 | :merge-test-db |
---|
31 | :set-up-test-db |
---|
32 | :tear-down-test-db |
---|
33 | :rdf-exporter-test-db |
---|
34 | :*TEST-TM* |
---|
35 | :*NOTIFICATIONBASE-TM* |
---|
36 | :*XTM-TM* |
---|
37 | :*XTM-MERGE1-TM* |
---|
38 | :*XTM-MERGE2-TM* |
---|
39 | :rdf-init-db |
---|
40 | :rdf-test-db |
---|
41 | :with-empty-db)) |
---|
42 | |
---|
43 | (in-package :fixtures) |
---|
44 | |
---|
45 | (defvar *XTM-TM* nil) |
---|
46 | |
---|
47 | (defvar *TEST-TM* "test-tm") |
---|
48 | |
---|
49 | (defvar *NOTIFICATIONBASE-TM* |
---|
50 | (dom:document-element |
---|
51 | (cxml:parse-file *notificationbase.xtm* (cxml-dom:make-dom-builder)))) |
---|
52 | |
---|
53 | (setf *debug-on-error* t) |
---|
54 | (setf *debug-on-failure* t) |
---|
55 | |
---|
56 | (defun clean-out-db (dir) |
---|
57 | (let |
---|
58 | ((dirname (make-pathname :directory (list :relative dir)))) |
---|
59 | (ensure-directories-exist dirname) |
---|
60 | (loop for filename in (com.gigamonkeys.pathnames:list-directory dirname) do |
---|
61 | (delete-file filename)))) |
---|
62 | |
---|
63 | (defun set-up-test-db (&optional (revision 0)) |
---|
64 | "clears out the database and parses the test file" |
---|
65 | (clean-out-db "data_base") |
---|
66 | |
---|
67 | (elephant:open-store (get-store-spec "data_base")) |
---|
68 | (init-isidorus revision) |
---|
69 | (setf *current-xtm* *TEST-TM*) |
---|
70 | ;deliberately only use stubs at this stage |
---|
71 | (import-only-topics *xtm-tm* |
---|
72 | :tm-id "http://www.isidor.us/unittests/testtm" |
---|
73 | :revision revision |
---|
74 | :xtm-id *TEST-TM*)) |
---|
75 | |
---|
76 | (defun set-up-raw-test-db () |
---|
77 | (clean-out-db "data_base") |
---|
78 | (elephant:open-store (get-store-spec "data_base")) |
---|
79 | (init-isidorus) |
---|
80 | (setf *current-xtm* *TEST-TM*)) |
---|
81 | |
---|
82 | (defun tear-down-test-db () |
---|
83 | "make sure the elephant store is properly closed" |
---|
84 | (elephant:close-store)) |
---|
85 | |
---|
86 | (def-fixture bare-test-db () |
---|
87 | (set-up-raw-test-db) |
---|
88 | (&body) |
---|
89 | (tear-down-test-db)) |
---|
90 | |
---|
91 | (def-fixture initialize-destination-db (dir) |
---|
92 | (clean-out-db dir) |
---|
93 | (&body) |
---|
94 | (tear-down-test-db)) |
---|
95 | |
---|
96 | (def-fixture initialized-test-db (&optional (xtm *NOTIFICATIONBASE-TM*)) |
---|
97 | (let ((revision (get-revision))) |
---|
98 | (declare (ignorable revision)) |
---|
99 | (setf *TM-REVISION* revision) |
---|
100 | (setf *XTM-TM* xtm) |
---|
101 | (set-up-test-db revision) |
---|
102 | (let ((tm |
---|
103 | (get-item-by-item-identifier "http://www.isidor.us/unittests/testtm" |
---|
104 | :revision revision))) |
---|
105 | (declare (ignorable tm)) |
---|
106 | (&body) |
---|
107 | (tear-down-test-db)))) |
---|
108 | |
---|
109 | |
---|
110 | (defvar *XTM-MERGE1-TM* |
---|
111 | (dom:document-element |
---|
112 | (cxml:parse-file *notification_merge1.xtm* (cxml-dom:make-dom-builder)))) |
---|
113 | |
---|
114 | (defparameter *XTM-MERGE2-TM* |
---|
115 | (dom:document-element |
---|
116 | (cxml:parse-file *notification_merge2.xtm* (cxml-dom:make-dom-builder)))) |
---|
117 | |
---|
118 | (defparameter *XTM-ATOM-TM* |
---|
119 | (dom:document-element |
---|
120 | (cxml:parse-file *atom_test.xtm* (cxml-dom:make-dom-builder)))) |
---|
121 | |
---|
122 | (def-fixture merge-test-db () |
---|
123 | (setf *XTM-TM* *NOTIFICATIONBASE-TM*) |
---|
124 | (let* |
---|
125 | ((revision1 (get-revision)) |
---|
126 | (revision2 (+ 200 revision1)) ; some arbitrary differences |
---|
127 | (revision3 (+ 400 revision1))) |
---|
128 | (set-up-test-db revision1) |
---|
129 | |
---|
130 | (importer *XTM-TM* |
---|
131 | :tm-id "http://www.isidor.us/unittests/testtm" |
---|
132 | :xtm-id *TEST-TM* :revision revision1) |
---|
133 | (importer *XTM-MERGE1-TM* :xtm-id "merge1" |
---|
134 | :tm-id "http://www.isidor.us/unittests/testtm" |
---|
135 | :revision revision2) |
---|
136 | (importer *XTM-MERGE2-TM* :xtm-id "merge2" |
---|
137 | :tm-id "http://www.isidor.us/unittests/testtm" |
---|
138 | :revision revision3) |
---|
139 | (&body) |
---|
140 | (tear-down-test-db))) |
---|
141 | |
---|
142 | (defun init-conf () |
---|
143 | (in-package :atom) |
---|
144 | ;;test configuration |
---|
145 | ;(defparameter *tm-feed* nil) |
---|
146 | (setf atom:*base-url* "http://london.ztt.fh-worms.de:8000") |
---|
147 | (load *atom-conf.lisp*)) |
---|
148 | |
---|
149 | (def-fixture atom-test-db () |
---|
150 | (setf *XTM-TM* *NOTIFICATIONBASE-TM*) |
---|
151 | (init-conf) |
---|
152 | (let* |
---|
153 | ((revision1 (get-revision)) |
---|
154 | (revision2 (+ 200 revision1)) ; some arbitrary differences |
---|
155 | (revision3 (+ 400 revision1))) |
---|
156 | (set-up-test-db revision1) |
---|
157 | |
---|
158 | (importer *XTM-TM* |
---|
159 | ;;aligned with conf.lisp |
---|
160 | :tm-id "http://psi.egovpt.org/tm/worms" |
---|
161 | :xtm-id *TEST-TM* :revision revision1) |
---|
162 | (importer *XTM-MERGE1-TM* :xtm-id "merge1" |
---|
163 | :tm-id "http://psi.egovpt.org/tm/worms" |
---|
164 | :revision revision2) |
---|
165 | (importer *XTM-MERGE2-TM* :xtm-id "merge2" |
---|
166 | :tm-id "http://psi.egovpt.org/tm/worms" |
---|
167 | :revision revision3) |
---|
168 | |
---|
169 | (importer *XTM-ATOM-TM* :xtm-id "atom-tm1" :tm-id "http://psi.egovpt.org/tm/egov-ontology" |
---|
170 | :revision revision1) |
---|
171 | (&body) |
---|
172 | (tear-down-test-db))) |
---|
173 | |
---|
174 | |
---|
175 | (defun rdf-init-db (&key (db-dir "data_base") (start-revision (get-revision))) |
---|
176 | "Deletes the data base files and initializes isidorus for rdf." |
---|
177 | (when elephant:*store-controller* |
---|
178 | (elephant:close-store)) |
---|
179 | (clean-out-db db-dir) |
---|
180 | (elephant:open-store (xml-importer:get-store-spec db-dir)) |
---|
181 | (xml-importer:init-isidorus start-revision) |
---|
182 | (rdf-importer:init-rdf-module start-revision)) |
---|
183 | |
---|
184 | |
---|
185 | (def-fixture rdf-test-db () |
---|
186 | (let ((db-dir "data_base") |
---|
187 | (tm-id "http://test-tm/") |
---|
188 | (document-id "doc-id")) |
---|
189 | (clean-out-db db-dir) |
---|
190 | (setf d:*current-xtm* document-id) |
---|
191 | (rdf-importer:setup-rdf-module *poems_light.rdf* db-dir :tm-id tm-id |
---|
192 | :document-id document-id) |
---|
193 | (elephant:open-store (xml-importer:get-store-spec db-dir)) |
---|
194 | (&body) |
---|
195 | (tear-down-test-db))) |
---|
196 | |
---|
197 | |
---|
198 | (def-fixture rdf-exporter-test-db() |
---|
199 | (let ((db-dir "data_base") |
---|
200 | (tm-id "http://test-tm") |
---|
201 | (document-id "doc-id") |
---|
202 | (exported-file-path "./__out__.rdf")) |
---|
203 | (clean-out-db db-dir) |
---|
204 | (handler-case (delete-file exported-file-path) |
---|
205 | (error () )) ;do nothing |
---|
206 | (setf d:*current-xtm* document-id) |
---|
207 | (setup-repository *poems_light.xtm* db-dir :tm-id tm-id |
---|
208 | :xtm-id document-id) |
---|
209 | (elephant:open-store (xml-importer:get-store-spec db-dir)) |
---|
210 | (rdf-exporter:export-rdf exported-file-path :tm-id tm-id) |
---|
211 | (&body) |
---|
212 | (handler-case (delete-file exported-file-path) |
---|
213 | (error () )) ;do nothing |
---|
214 | (tear-down-test-db))) |
---|
215 | |
---|
216 | |
---|
217 | (def-fixture with-empty-db (dir) |
---|
218 | (clean-out-db dir) |
---|
219 | (elephant:open-store (xml-importer:get-store-spec dir)) |
---|
220 | (&body) |
---|
221 | (tear-down-test-db)) |
---|