Author: lgiessmann Date: Tue Sep 8 06:54:19 2009 New Revision: 137
Log: rdf-importer: added some unit-tests
Modified: trunk/src/unit_tests/full_mapping.rdf trunk/src/unit_tests/rdf_importer_test.lisp trunk/src/unit_tests/unittests-constants.lisp
Modified: trunk/src/unit_tests/full_mapping.rdf ============================================================================== --- trunk/src/unit_tests/full_mapping.rdf (original) +++ trunk/src/unit_tests/full_mapping.rdf Tue Sep 8 06:54:19 2009 @@ -31,7 +31,7 @@ </rdf:Description>
- <rdf:Description rdf:nodeID="id_285"> + <rdf:Description rdf:nodeID="id_283"> <isi:variant rdf:parseType="Resource"> <rdf:type rdf:resource="http://isidorus/tm2rdf_mapping/types/Variant%22/%3E <isi:scope rdf:resource="http://simpsons/display%22/%3E @@ -121,13 +121,13 @@ <isi:itemIdentity rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI%22%3Ehttp://simpsons/role-wife/ii</isi:itemIdentity> </rdf:Description>
- rdf:Description + <rdf:Description rdf:nodeID="id_291"> <rdf:type rdf:resource="http://isidorus/tm2rdf_mapping/types/Association%22/%3E <isi:itemIdentity rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI%22%3Ehttp://simpsons/married/ii-1</isi:itemIdentity> <isi:itemIdentity rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI%22%3Ehttp://simpsons/married/ii-2</isi:itemIdentity> <isi:associationtype rdf:resource="http://simpsons/married%22/%3E isi:role - rdf:Description + <rdf:Description rdf:nodeID="id_295"> <isi:itemIdentity rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI%22%3Ehttp://simpsons/role-wife/ii</isi:itemIdentity> <rdf:type rdf:resource="http://isidorus/tm2rdf_mapping/types/Role%22/%3E <isi:roletype rdf:resource="http://simpsons/wife%22/%3E @@ -135,7 +135,7 @@ </rdf:Description> </isi:role> isi:role - rdf:Description + <rdf:Description rdf:nodeID="id_292"> <rdf:type rdf:resource="http://isidorus/tm2rdf_mapping/types/Role%22/%3E <isi:roletype rdf:resource="http://simpsons/husband%22/%3E <isi:player rdf:resource="http://simpsons/homer%22/%3E
Modified: trunk/src/unit_tests/rdf_importer_test.lisp ============================================================================== --- trunk/src/unit_tests/rdf_importer_test.lisp (original) +++ trunk/src/unit_tests/rdf_importer_test.lisp Tue Sep 8 06:54:19 2009 @@ -66,7 +66,10 @@ :test-poems-rdf-topics :test-empty-collection :test-collection - :test-xml-base)) + :test-xml-base + :test-full-mapping-marge + :test-full-mapping-homer + :test-full-mapping-association))
(declaim (optimize (debug 3) (speed 0) (safety 3) (space 0) (compilation-speed 0)))
@@ -79,6 +82,14 @@ (in-suite rdf-importer-test)
+(defun empty-p (top) + (declare (TopicC top)) + (and (not (d:item-identifiers top)) + (not (d:locators top)) + (not (d:names top)) + (not (d:occurrences top)))) + + (test test-get-literals-of-node "Tests the helper function get-literals-of-node." (let ((doc-1 @@ -3060,6 +3071,306 @@ "/test") "http://base-3/test")))))))
+ +(test test-full-mapping-marge + "Tests the entire importer module." + (let ((dir "data_base") + (rdf-file unittests-constants:*full_mapping.rdf*) + (tm-id "http://full-mapping/") + (document-id "http://full_mapping.rdf")) + (when elephant:*store-controller* + (elephant:close-store)) + (fixtures::clean-out-db dir) + (rdf-importer:rdf-importer rdf-file dir + :tm-id tm-id + :document-id document-id) + (elephant:open-store (xml-importer:get-store-spec dir)) + (is (= (length (elephant:get-instances-by-class 'd:TopicC)) 15)) + (is (= (length (elephant:get-instances-by-class 'd:AssociationC)) 1)) + (is (= (length (elephant:get-instances-by-class 'd:NameC)) 4)) + (is (= (length (elephant:get-instances-by-class 'd:RoleC)) 2)) + (is (= (length (elephant:get-instances-by-class 'd:OccurrenceC)) 2)) + (is (= (length (elephant:get-instances-by-class 'd:VariantC)) 2)) + (setf d:*current-xtm* document-id) + (let ((firstName (get-item-by-id "http://simpsons/firstName")) + (lastName (get-item-by-id "http://simpsons/lastName")) + (display (get-item-by-id "http://simpsons/display")) + (profession (get-item-by-id "http://simpsons/profession")) + (married (get-item-by-id "http://simpsons/married")) + (husband (get-item-by-id "http://simpsons/husband")) + (wife (get-item-by-id "http://simpsons/wife")) + (en (get-item-by-id "http://simpsons/en")) + (type (get-item-by-psi *type-psi*)) + (instance (get-item-by-psi *instance-psi*)) + (type-instance (get-item-by-psi *type-instance-psi*)) + (isi-object (get-item-by-psi *rdf2tm-object*)) + (isi-subject (get-item-by-psi *rdf2tm-subject*)) + (marge (get-item-by-id "http://simpsons/marge")) + (homer (get-item-by-id "http://simpsons/homer")) + (role-husband + (find-if #'(lambda(x) + (let ((iis (d:item-identifiers x))) + (when (= (length iis) 1) + (string= (d:uri (first iis)) + "http://simpsons/role-husband/ii")))) + (elephant:get-instances-by-class 'd:RoleC))) + (role-wife + (find-if #'(lambda(x) + (let ((iis (d:item-identifiers x))) + (when (= (length iis) 1) + (string= (d:uri (first iis)) + "http://simpsons/role-wife/ii")))) + (elephant:get-instances-by-class 'd:RoleC)))) + (is-true firstName) + (is-true (empty-p firstName)) + (is-true lastName) + (is-true (empty-p lastName)) + (is-true display) + (is-true (empty-p display)) + (is-true profession) + (is-true (empty-p profession)) + (is-true married) + (is-true (empty-p married)) + (is-true husband) + (is-true (empty-p husband)) + (is-true wife) + (is-true (empty-p wife)) + (is-true en) + (is-true (empty-p en)) + (is-true type) + (is-true (empty-p type)) + (is-true instance) + (is-true (empty-p instance)) + (is-true type-instance) + (is-true (empty-p type-instance)) + (is-true isi-object) + (is-true (empty-p isi-object)) + (is-true isi-subject) + (is-true (empty-p isi-subject)) + (is-true role-husband) + (is-true role-wife) + (is-true homer) + (is (= (length (d:psis marge)) 2)) + (is-true (find-if #'(lambda(x) + (string= (d:uri x) "http://simpsons/marjorie")) + (d:psis marge))) + (is (= (length (d:names marge)) 2)) + (let ((marge-fn (find-if #'(lambda(x) + (eql (instance-of x) firstName)) + (d:names marge))) + (marge-ln (find-if #'(lambda(x) + (eql (instance-of x) lastName)) + (d:names marge))) + (marge-occ (find-if #'(lambda(x) + (eql (instance-of x) profession)) + (d:occurrences marge)))) + (is-true marge-fn) + (is-true marge-ln) + (is (string= (d:charvalue marge-fn) "Marjorie")) + (is (string= (d:charvalue marge-ln) "Simpson")) + (is (= (length (d:variants marge-fn)) 1)) + (is (= (length (d:themes (first (d:variants marge-fn)))) 1)) + (is (eql (first (d:themes (first (d:variants marge-fn)))) display)) + (is (string= (d:charvalue (first (d:variants marge-fn))) "Marge")) + (is (string= (d:datatype (first (d:variants marge-fn))) *xml-string*)) + (is-true marge-occ) + (is (string= (d:charvalue marge-occ) "Housewife")) + (is (string= (d:datatype marge-occ) *xml-string*)) + (is (= (length (d:themes marge-occ)) 0)) + (is (= (length (d:psis marge)) 2)))))) + + +(test test-full-mapping-homer + "Tests the entire importer module." + (let ((dir "data_base") + (rdf-file unittests-constants:*full_mapping.rdf*) + (tm-id "http://full-mapping/") + (document-id "http://full_mapping.rdf")) + (when elephant:*store-controller* + (elephant:close-store)) + (fixtures::clean-out-db dir) + (rdf-importer:rdf-importer rdf-file dir + :tm-id tm-id + :document-id document-id) + (elephant:open-store (xml-importer:get-store-spec dir)) + (is (= (length (elephant:get-instances-by-class 'd:TopicC)) 15)) + (is (= (length (elephant:get-instances-by-class 'd:AssociationC)) 1)) + (is (= (length (elephant:get-instances-by-class 'd:NameC)) 4)) + (is (= (length (elephant:get-instances-by-class 'd:RoleC)) 2)) + (is (= (length (elephant:get-instances-by-class 'd:OccurrenceC)) 2)) + (is (= (length (elephant:get-instances-by-class 'd:VariantC)) 2)) + (setf d:*current-xtm* document-id) + (let ((firstName (get-item-by-id "http://simpsons/firstName")) + (lastName (get-item-by-id "http://simpsons/lastName")) + (display (get-item-by-id "http://simpsons/display")) + (profession (get-item-by-id "http://simpsons/profession")) + (married (get-item-by-id "http://simpsons/married")) + (husband (get-item-by-id "http://simpsons/husband")) + (wife (get-item-by-id "http://simpsons/wife")) + (en (get-item-by-id "http://simpsons/en")) + (type (get-item-by-psi *type-psi*)) + (instance (get-item-by-psi *instance-psi*)) + (type-instance (get-item-by-psi *type-instance-psi*)) + (isi-object (get-item-by-psi *rdf2tm-object*)) + (isi-subject (get-item-by-psi *rdf2tm-subject*)) + (marge (get-item-by-id "http://simpsons/marge")) + (homer (get-item-by-id "http://simpsons/homer")) + (role-husband + (find-if #'(lambda(x) + (let ((iis (d:item-identifiers x))) + (when (= (length iis) 1) + (string= (d:uri (first iis)) + "http://simpsons/role-husband/ii")))) + (elephant:get-instances-by-class 'd:RoleC))) + (role-wife + (find-if #'(lambda(x) + (let ((iis (d:item-identifiers x))) + (when (= (length iis) 1) + (string= (d:uri (first iis)) + "http://simpsons/role-wife/ii")))) + (elephant:get-instances-by-class 'd:RoleC)))) + (is-true firstName) + (is-true (empty-p firstName)) + (is-true lastName) + (is-true (empty-p lastName)) + (is-true display) + (is-true (empty-p display)) + (is-true profession) + (is-true (empty-p profession)) + (is-true married) + (is-true (empty-p married)) + (is-true husband) + (is-true (empty-p husband)) + (is-true wife) + (is-true (empty-p wife)) + (is-true en) + (is-true (empty-p en)) + (is-true type) + (is-true (empty-p type)) + (is-true instance) + (is-true (empty-p instance)) + (is-true type-instance) + (is-true (empty-p type-instance)) + (is-true isi-object) + (is-true (empty-p isi-object)) + (is-true isi-subject) + (is-true (empty-p isi-subject)) + (is-true role-husband) + (is-true role-wife) + (is-true marge) + (is-true (find-if #'(lambda(x) + (string= (d:uri x) "http://simpsons/homer_simpson")) + (d:psis homer))) + (is (= (length (d:locators homer)) 1)) + (is-true (find-if #'(lambda(x) + (string= (d:uri x) "http://some.where/resource")) + (d:locators homer))) + (is (= (length (d:item-identifiers homer)) 1)) + (is-true (find-if #'(lambda(x) + (string= (d:uri x) "http://simpsons/ii/homer")) + (d:item-identifiers homer))) + (is (= (length (d:names homer)) 2)) + (let ((homer-fn (find-if #'(lambda(x) + (eql (instance-of x) firstName)) + (d:names homer))) + (homer-ln (find-if #'(lambda(x) + (eql (instance-of x) lastName)) + (d:names homer))) + (homer-occ (find-if #'(lambda(x) + (eql (instance-of x) profession)) + (d:occurrences homer)))) + (is-true homer-fn) + (is-true homer-ln) + (is (string= (d:charvalue homer-fn) "Homer J.")) + (is (string= (d:charvalue homer-ln) "Simpson")) + (is (= (length (d:variants homer-fn)) 1)) + (is (= (length (d:themes (first (d:variants homer-fn)))) 1)) + (is (eql (first (d:themes (first (d:variants homer-fn)))) display)) + (is (string= (d:charvalue (first (d:variants homer-fn))) "Homer")) + (is (string= (d:datatype (first (d:variants homer-fn))) *xml-string*)) + (is-true homer-occ) + (is (string= (d:charvalue homer-occ) "Safety Inspector")) + (is (string= (d:datatype homer-occ) *xml-string*)) + (is (= (length (d:themes homer-occ)) 1)) + (is (eql (first (d:themes homer-occ)) en)))))) + + +(test test-full-mapping-association + "Tests the entire importer module." + (let ((dir "data_base") + (rdf-file unittests-constants:*full_mapping.rdf*) + (tm-id "http://full-mapping/") + (document-id "http://full_mapping.rdf")) + (when elephant:*store-controller* + (elephant:close-store)) + (fixtures::clean-out-db dir) + (rdf-importer:rdf-importer rdf-file dir + :tm-id tm-id + :document-id document-id) + (elephant:open-store (xml-importer:get-store-spec dir)) + (is (= (length (elephant:get-instances-by-class 'd:TopicC)) 15)) + (is (= (length (elephant:get-instances-by-class 'd:AssociationC)) 1)) + (is (= (length (elephant:get-instances-by-class 'd:NameC)) 4)) + (is (= (length (elephant:get-instances-by-class 'd:RoleC)) 2)) + (is (= (length (elephant:get-instances-by-class 'd:OccurrenceC)) 2)) + (is (= (length (elephant:get-instances-by-class 'd:VariantC)) 2)) + (setf d:*current-xtm* document-id) + (let ((married (get-item-by-id "http://simpsons/married")) + (husband (get-item-by-id "http://simpsons/husband")) + (wife (get-item-by-id "http://simpsons/wife")) + (marge (get-item-by-id "http://simpsons/marge")) + (homer (get-item-by-id "http://simpsons/homer")) + (assoc (first (elephant:get-instances-by-class 'd:AssociationC))) + (role-husband + (find-if #'(lambda(x) + (let ((iis (d:item-identifiers x))) + (when (= (length iis) 1) + (string= (d:uri (first iis)) + "http://simpsons/role-husband/ii")))) + (elephant:get-instances-by-class 'd:RoleC))) + (role-wife + (find-if #'(lambda(x) + (let ((iis (d:item-identifiers x))) + (when (= (length iis) 1) + (string= (d:uri (first iis)) + "http://simpsons/role-wife/ii")))) + (elephant:get-instances-by-class 'd:RoleC)))) + (is-true married) + (is-true (empty-p married)) + (is-true husband) + (is-true (empty-p husband)) + (is-true wife) + (is-true (empty-p wife)) + (is-true role-husband) + (is-true role-wife) + (is-true marge) + (is-true homer) + (is (= (length (intersection (list role-husband role-wife) + (d:roles assoc))) + 2)) + (is (eql (d:instance-of assoc) married)) + (is (= (length (d:item-identifiers assoc)) 2)) + (is (= (length + (intersection + (list + (elephant:get-instance-by-value + 'd:ItemIdentifierC 'd:uri "http://simpsons/married/ii-1") + (elephant:get-instance-by-value + 'd:ItemIdentifierC 'd:uri "http://simpsons/married/ii-2")) + (d:item-identifiers assoc))) + 2)) + (is (eql (d:instance-of role-husband) husband)) + (is (eql (d:instance-of role-wife) wife)) + (is (eql (d:player role-husband) homer)) + (is (eql (d:player role-wife) marge)) + (is (= (length (d:item-identifiers role-husband)) 1)) + (is (= (length (d:item-identifiers role-wife)) 1)) + (is (string= (d:uri (first (d:item-identifiers role-husband))) + "http://simpsons/role-husband/ii")) + (is (string= (d:uri (first (d:item-identifiers role-wife))) + "http://simpsons/role-wife/ii"))))) + + (defun run-rdf-importer-tests() "Runs all defined tests." (when elephant:*store-controller* @@ -3082,4 +3393,7 @@ (it.bese.fiveam:run! 'test-poems-rdf-topics) (it.bese.fiveam:run! 'test-empty-collection) (it.bese.fiveam:run! 'test-collection) - (it.bese.fiveam:run! 'test-xml-base)) \ No newline at end of file + (it.bese.fiveam:run! 'test-xml-base) + (it.bese.fiveam:run! 'test-full-mapping-marge) + (it.bese.fiveam:run! 'test-full-mapping-homer) + (it.bese.fiveam:run! 'test-full-mapping-association)) \ No newline at end of file
Modified: trunk/src/unit_tests/unittests-constants.lisp ============================================================================== --- trunk/src/unit_tests/unittests-constants.lisp (original) +++ trunk/src/unit_tests/unittests-constants.lisp Tue Sep 8 06:54:19 2009 @@ -30,7 +30,8 @@ :*atom_test.xtm* :*atom-conf.lisp* :*poems_light.rdf* - :*poems_light.xtm*)) + :*poems_light.xtm* + :*full_mapping.rdf*))
(in-package :unittests-constants)
@@ -99,3 +100,7 @@ (defparameter *poems_light.xtm* (asdf:component-pathname (asdf:find-component *unit-tests-component* "poems_light.xtm"))) + +(defparameter *full_mapping.rdf* + (asdf:component-pathname + (asdf:find-component *unit-tests-component* "full_mapping.rdf"))) \ No newline at end of file