Created
March 24, 2010 18:35
-
-
Save youngnh/342603 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns revelytix.test-triplestore | |
(:use [reveltix.triplestore :only (*connection* connect-to dispose execute-command resultMessage= create-graph drop-graph insert-triple load-file)])) | |
(def *HOST* "rmi://australia/server1") | |
(def *FAMILY* "family") | |
(def *N3_FAMILY_FILE* "test/data/family.n3") | |
(def *SELECT-ALL* "select ?s ?p ?o where { ?s ?p ?o }") | |
;; Connection Fixture, establishes a connection for all execute-command calls to use | |
(defn connection-fixture [f] | |
(binding [*connection* (connect-to *HOST*)] | |
(try | |
(f) | |
(finally | |
(dispose *connection*))))) | |
;; Family Graph Fixture, sets up and tears down the family graph for tests | |
(defn family-graph-fixture [f] | |
(try | |
(execute-command (create-graph *FAMILY*)) | |
(f) | |
(finally | |
(execute-command (drop-graph *FAMILY*))))) | |
;; Family Data Fixture, populates the family graph with data to query | |
(defn family-data-fixture [f] | |
(execute-command (load-file *FAMILY* *N3_FAMILY_FILE*)) | |
(f)) | |
(deftest test-create-graph | |
(is (resultMessage= "Successfully created graph rmi://australia/server1#family" | |
(execute-command (create-graph *FAMILY*))))) | |
(deftest test-drop-graph | |
(is (resultMessage= "Successfully dropped graph rmi://australia/server1#products" | |
(execute-command (drop-graph *PRODUCTS*)))))) | |
(deftest test-create-and-drop-graph | |
(test-create-graph) | |
(test-drop-graph)) | |
(deftest test-insert-triple | |
(is (resultMessage= "Successfully inserted statements into rmi://australia/server1#family" | |
(execute-command (insert-triple *FAMILY* "Joe" "father_of" "Billy"))))) | |
(deftest test-load-file | |
(is (resultMessage= "Successfully inserted statements into rmi://australia/server1#family" | |
(execute-command (load-file *FAMILY* *N3_FAMILY_FILE*))))) | |
(deftest test-query | |
(is (= 72 (count (execute-command (query *FAMILY* *SELECT-ALL*)))))) | |
(deftest test-suite | |
(test-create-and-drop-graph) | |
(family-graph-fixture test-insert-triple) | |
(family-graph-fixture test-load-file) | |
(family-graph-fixture #(family-data-fixture test-query))) | |
(defn test-ns-hook [] | |
(connection-fixture test-suite)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment