Skip to content

Instantly share code, notes, and snippets.

@c-spencer
Created August 11, 2010 20:40
Show Gist options
  • Save c-spencer/519704 to your computer and use it in GitHub Desktop.
Save c-spencer/519704 to your computer and use it in GitHub Desktop.
(use 'clojure.test)
(testing "Initialising"
(start "var/test")
(are [x y] (= x y)
(.getClass *neo*) EmbeddedGraphDatabase
(.getClass *lucene* LuceneFullTextIndexService)))
(testing "Homogeneous Nodes"
(register-indices #{"message"})
(let [first-node (node! {:message "FirstNode"})
second-node (node! {:message "SecondNode"})
third-node (node! {:message "ThirdNode"})
relation (relate! first-node :knows second-node {:message "ARelation"})]
(testing "Properties, dereferencing"
(are [x y] (= x y)
{:message "FirstNode"} @first-node
{:message "ARelation"} @relation
first-node (start-node relation)))
(testing "Traversal"
(are [x y] (= x y)
1 (count (related first-node :knows))
0 (count (related first-node :some-label)))
0 (count (related first-node :knows incoming))
1 (count (related first-node :knows outgoing))
1 (count (related second-node :knows incoming))
0 (count (related third-node :knows)))
(testing "Searching"
(let [search (find-nodes "message" "FirstNode")]
(are [x y] (= x y)
1 (count search)
first-node (first search)
0 (count (find-nodes :message "ARelation"))
0 (count (find-nodes :not-an-index "FirstNode")))))
(testing "Invalid Transactions"
(are [x] (thrown? TransactionFailureException x)
(delete! first-node)
(do-tx (failure))))
(testing "Deletion"
(do-tx
(delete! relation)
(delete! first-node))
(is (thrown? Exception @first-node))
(is (thrown? Exception @relation))
(is @second-node)
(delete! second-node)
(is (thrown? Exception @second-node)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment