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