diff --git a/test/clojurewerkz/neocons/rest/test_connection.clj b/test/clojurewerkz/neocons/rest/test_connection.clj index f762a72..cb7c538 100644 --- a/test/clojurewerkz/neocons/rest/test_connection.clj +++ b/test/clojurewerkz/neocons/rest/test_connection.clj @@ -1,7 +1,5 @@ (ns clojurewerkz.neocons.rest.test-connection - (:require [clojurewerkz.neocons.rest :as neorest] - [slingshot.slingshot :as slingshot]) - (:import [slingshot ExceptionInfo]) + (:require [clojurewerkz.neocons.rest :as neorest]) (:use clojure.test)) (println (str "Using Clojure version " *clojure-version*)) diff --git a/test/clojurewerkz/neocons/rest/test_indexing.clj b/test/clojurewerkz/neocons/rest/test_indexing.clj index 2d57694..f5c60eb 100644 --- a/test/clojurewerkz/neocons/rest/test_indexing.clj +++ b/test/clojurewerkz/neocons/rest/test_indexing.clj @@ -1,8 +1,6 @@ (ns clojurewerkz.neocons.rest.test-indexing (:require [clojurewerkz.neocons.rest :as neorest] - [clojurewerkz.neocons.rest.nodes :as nodes] - [slingshot.slingshot :as slingshot]) - (:import [slingshot ExceptionInfo]) + [clojurewerkz.neocons.rest.nodes :as nodes]) (:use clojure.test)) (neorest/connect! "http://localhost:7474/db/data/") @@ -17,7 +15,7 @@ (deftest ^{:indexing true} test-create-a-new-node-index-with-explicit-configuration (let [name "node-index-2" - conf { :type "fulltext" :provider "lucene" }] + conf {:type "fulltext" :provider "lucene"}] (nodes/create-index name conf))) (deftest ^{:indexing true} test-listing-node-indexes @@ -37,32 +35,32 @@ (deftest ^{:indexing true} test-adding-a-node-to-index (let [idx (nodes/create-index "uris") uri "http://arstechnica.com" - home (nodes/create { :uri uri })] + home (nodes/create {:uri uri})] (nodes/add-to-index (:id home) (:name idx) "uri" uri))) (deftest ^{:indexing true} test-removing-a-node-from-index (let [idx (nodes/create-index "uris") uri "http://arstechnica.com" - home (nodes/create { :uri uri })] + home (nodes/create {:uri uri})] (nodes/add-to-index (:id home) (:name idx) "uri" uri) (nodes/delete-from-index (:id home) (:name idx)))) (deftest ^{:indexing true} test-removing-a-node-and-key-from-index (let [idx (nodes/create-index "uris, urls and so on") uri "http://arstechnica.com" - home (nodes/create { :uri uri })] + home (nodes/create {:uri uri})] (nodes/add-to-index (:id home) (:name idx) "uri" uri) (nodes/delete-from-index (:id home) (:name idx) "uri"))) (deftest ^{:indexing true} test-removing-a-node-key-and-value-from-index (let [idx (nodes/create-index "locations") - home (nodes/create { :lat 20.0 })] + home (nodes/create {:lat 20.0})] (nodes/add-to-index (:id home) (:name idx) "lat" 20.0) (nodes/delete-from-index (:id home) (:name idx) "lat" 20.0))) (deftest ^{:indexing true} test-finding-nodes-using-an-index - (let [node1 (nodes/create { :name "Wired" }) - node2 (nodes/create { :name "Craigslist" }) + (let [node1 (nodes/create {:name "Wired"}) + node2 (nodes/create {:name "Craigslist"}) url1 "http://wired.com" url2 "http://craigslist.org" idx (nodes/create-index "by-url")] @@ -75,7 +73,7 @@ (is (not (ids (:id node2))))))) (deftest ^{:indexing true} test-removing-a-node-removes-it-from-indexes - (let [node1 (nodes/create { :name "Wired" }) + (let [node1 (nodes/create {:name "Wired"}) url1 "http://wired.com" idx (nodes/create-index "by-url")] (nodes/delete-from-index (:id node1) (:name idx) "url") @@ -85,8 +83,8 @@ (is (not (ids (:id node1))))))) (deftest ^{:indexing true} test-finding-nodes-using-full-text-search-queries-over-index - (let [puma (nodes/create { :name "Puma" :hq-location "Herzogenaurach, Germany"}) - apple (nodes/create { :name "Apple" :hq-location "Cupertino, CA, USA"}) + (let [puma (nodes/create {:name "Puma" :hq-location "Herzogenaurach, Germany"}) + apple (nodes/create {:name "Apple" :hq-location "Cupertino, CA, USA"}) idx (nodes/create-index "companies")] (nodes/delete-from-index (:id puma) (:name idx)) (nodes/delete-from-index (:id apple) (:name idx)) diff --git a/test/clojurewerkz/neocons/rest/test_nodes.clj b/test/clojurewerkz/neocons/rest/test_nodes.clj index 1e7790d..cb0f4e1 100644 --- a/test/clojurewerkz/neocons/rest/test_nodes.clj +++ b/test/clojurewerkz/neocons/rest/test_nodes.clj @@ -1,8 +1,6 @@ (ns clojurewerkz.neocons.rest.test-nodes - (:require [clojurewerkz.neocons.rest :as neorest] - [clojurewerkz.neocons.rest.nodes :as nodes] - [slingshot.slingshot :as slingshot]) - (:import [slingshot ExceptionInfo]) + (:require [clojurewerkz.neocons.rest :as neorest] + [clojurewerkz.neocons.rest.nodes :as nodes]) (:use clojure.test [clojurewerkz.neocons.rest.records :only [instantiate-node-from]])) @@ -19,7 +17,7 @@ (is (= (:id created-node) (:id fetched-node))))) (deftest test-creating-and-immediately-accessing-a-node-with-properties - (let [data { :key "value" } + (let [data {:key "value"} created-node (nodes/create data) fetched-node (nodes/get (:id created-node))] (is (= (:id created-node) (:id fetched-node))) @@ -32,7 +30,7 @@ (deftest test-creating-and-deleting-a-node-with-properties - (let [data { :key "value" } + (let [data {:key "value"} created-node (nodes/create data) [deleted-id status] (nodes/delete (:id created-node))] (is (= 204 status)) @@ -44,7 +42,7 @@ (deftest test-creating-and-getting-properties-of-one-node - (let [data { :key "value" } + (let [data {:key "value"} created-node (nodes/create data) fetched-data (nodes/get-properties (:id created-node))] (is (= data fetched-data)))) @@ -56,7 +54,7 @@ (deftest test-updating-a-single-node-property - (let [node (nodes/create { :age 26 }) + (let [node (nodes/create {:age 26}) fetched-node (nodes/get (:id node)) new-value (nodes/set-property (:id node) :age 27) updated-node (nodes/get (:id fetched-node))] @@ -64,18 +62,17 @@ (deftest test-updating-node-properties - (let [node (nodes/create { :age 26 }) + (let [node (nodes/create {:age 26}) fetched-node (nodes/get (:id node)) - new-data (nodes/update (:id node) { :age 27 :gender "male" }) + new-data (nodes/update (:id node) {:age 27 :gender "male"}) updated-node (nodes/get (:id fetched-node))] (is (= new-data (-> updated-node :data))))) (deftest test-deleting-all-properties-from-a-node - (let [data { :key "value" } + (let [data {:key "value"} created-node (nodes/create data) fetched-data (nodes/get-properties (:id created-node))] (is (= data fetched-data)) (nodes/delete-properties (:id created-node)) (is (= {} (nodes/get-properties (:id created-node)))))) - diff --git a/test/clojurewerkz/neocons/rest/test_relationships.clj b/test/clojurewerkz/neocons/rest/test_relationships.clj index 63304cb..a0a0c8a 100644 --- a/test/clojurewerkz/neocons/rest/test_relationships.clj +++ b/test/clojurewerkz/neocons/rest/test_relationships.clj @@ -2,9 +2,7 @@ (:require [clojurewerkz.neocons.rest :as neorest] [clojurewerkz.neocons.rest.nodes :as nodes] [clojurewerkz.neocons.rest.relationships :as relationships] - [clojurewerkz.neocons.rest.paths :as paths] - [slingshot.slingshot :as slingshot]) - (:import [slingshot ExceptionInfo]) + [clojurewerkz.neocons.rest.paths :as paths] ) (:use clojure.test [clojure.set :only [subset?]] [clojurewerkz.neocons.rest.records :only [instantiate-node-from instantiate-rel-from]])) @@ -15,7 +13,6 @@ [xs] (map :id xs)) - ;; ;; Working with relationships ;; @@ -55,7 +52,7 @@ (let [from-node (nodes/create) to-node (nodes/create) created-rel (relationships/create from-node to-node :links) - rt { :type "links" :direction "out" }] + rt {:type "links" :direction "out"}] (is (relationships/first-outgoing-between from-node to-node [:links])) (is (nil? (relationships/first-outgoing-between from-node to-node [:loves]))) (is (= created-rel (relationships/first-outgoing-between from-node to-node [:links]))) @@ -66,7 +63,7 @@ (relationships/maybe-delete-outgoing from-node to-node [:links]))) (deftest test-creating-and-immediately-accessing-a-relationship-with-properties - (let [data { :one "uno" :two "due" } + (let [data {:one "uno" :two "due"} from-node (nodes/create) to-node (nodes/create) created-rel (relationships/create from-node to-node :links data) @@ -84,7 +81,7 @@ (deftest test-creating-and-deleting-a-non-existent-relationship ;; this should be slingshot.ExceptionInfo on 1.3 but - ;; clojure.lang.ExceptionInfo on 1.4.0[-beta1]. This Slingshot shit is annoying. MK. + ;; clojure.lang.ExceptionInfo on 1.4.0+. This Slingshot shit is annoying. MK. (is (thrown? Exception (relationships/delete 87238467666))) (try @@ -170,11 +167,11 @@ (deftest test-updating-relationship-properties - (let [data { :one "uno" :two "due" } + (let [data {:one "uno" :two "due"} from-node (nodes/create) to-node (nodes/create) created-rel (relationships/create from-node to-node :links data) - new-data (relationships/update (:id created-rel) { :one "eine" :two "deux" }) + new-data (relationships/update (:id created-rel) {:one "eine" :two "deux"}) fetched-rel (relationships/get (:id created-rel))] (is (= (:id created-rel) (:id fetched-rel))) (is (= (:type created-rel) (:type fetched-rel))) @@ -182,21 +179,21 @@ (deftest test-deleting-a-specific-relationship-property - (let [data { :cost "high" :legendary true } - from-node (nodes/create { :name "Romeo" }) - to-node (nodes/create { :name "Juliet" }) + (let [data {:cost "high" :legendary true} + from-node (nodes/create {:name "Romeo"}) + to-node (nodes/create {:name "Juliet"}) created-rel (relationships/create from-node to-node :loves data) _ (relationships/delete-property (:id created-rel) :cost) fetched-rel (relationships/get (:id created-rel))] (is (= (:id created-rel) (:id fetched-rel))) (is (= (:type created-rel) (:type fetched-rel))) - (is (= { :legendary true } (:data fetched-rel))))) + (is (= {:legendary true} (:data fetched-rel))))) (deftest test-deleting-a-non-existent-relationship-property - (let [data { :cost "high" :legendary true } - from-node (nodes/create { :name "Romeo" }) - to-node (nodes/create { :name "Juliet" }) + (let [data {:cost "high" :legendary true} + from-node (nodes/create {:name "Romeo"}) + to-node (nodes/create {:name "Juliet"}) created-rel (relationships/create from-node to-node :loves data)] (is (thrown? Exception (relationships/delete-property (:id created-rel) :a-non-existent-rel-property))))) @@ -212,12 +209,12 @@ ;; (deftest test-deletion-of-nodes-with-relationships - (let [john (nodes/create { :name "John" :age 28 :location "New York City, NY" }) - beth (nodes/create { :name "Elizabeth" :age 30 :location "Chicago, IL" }) - gael (nodes/create { :name "Gaël" :age 31 :location "Montpellier" }) + (let [john (nodes/create {:name "John" :age 28 :location "New York City, NY"}) + beth (nodes/create {:name "Elizabeth" :age 30 :location "Chicago, IL"}) + gael (nodes/create {:name "Gaël" :age 31 :location "Montpellier"}) rel1 (relationships/create john beth :knows) rel5 (relationships/create beth gael :knows) - rt { :type "knows" :direction "out" }] + rt {:type "knows" :direction "out"}] (is (paths/exists-between? (:id john) (:id gael) :relationships [rt] :max-depth 3)) (is (set (nodes/all-connected-out (:id john))) (:id beth)) (is (nodes/connected-out? (:id john) (:id beth))) @@ -232,12 +229,12 @@ (is (not (paths/exists-between? (:id john) (:id gael) :relationships [rt] :max-depth 3))))) (deftest test-purging-of-all-outgoing-relationships - (let [john (nodes/create { :name "John" :age 28 :location "New York City, NY" }) - beth (nodes/create { :name "Elizabeth" :age 30 :location "Chicago, IL" }) - gael (nodes/create { :name "Gaël" :age 31 :location "Montpellier" }) + (let [john (nodes/create {:name "John" :age 28 :location "New York City, NY"}) + beth (nodes/create {:name "Elizabeth" :age 30 :location "Chicago, IL"}) + gael (nodes/create {:name "Gaël" :age 31 :location "Montpellier"}) rel1 (relationships/create john beth :knows) rel5 (relationships/create beth gael :knows) - rt { :type "knows" :direction "out" }] + rt {:type "knows" :direction "out"}] (is (paths/exists-between? (:id john) (:id gael) :relationships [rt] :max-depth 3)) (relationships/purge-outgoing beth) (is (not (paths/exists-between? (:id john) (:id gael) :relationships [rt] :max-depth 3))))) diff --git a/test/clojurewerkz/neocons/rest/test_traversal.clj b/test/clojurewerkz/neocons/rest/test_traversal.clj index d6e67c1..d0c1581 100644 --- a/test/clojurewerkz/neocons/rest/test_traversal.clj +++ b/test/clojurewerkz/neocons/rest/test_traversal.clj @@ -2,10 +2,7 @@ (:require [clojurewerkz.neocons.rest :as neorest] [clojurewerkz.neocons.rest.nodes :as nodes] [clojurewerkz.neocons.rest.relationships :as relationships] - [clojurewerkz.neocons.rest.paths :as paths] - [clojurewerkz.neocons.rest.cypher :as cypher] - [slingshot.slingshot :as slingshot]) - (:import [slingshot ExceptionInfo]) + [clojurewerkz.neocons.rest.paths :as paths]) (:use clojure.test [clojure.set :only [subset?]] [clojure.pprint :only [pprint]] @@ -18,68 +15,68 @@ ;; (deftest test-traversing-nodes-using-all-return-filter-all-relationships-and-no-pagination - (let [john (nodes/create { :name "John" }) - adam (nodes/create { :name "Alan" }) - pete (nodes/create { :name "Peter" }) + (let [john (nodes/create {:name "John"}) + adam (nodes/create {:name "Alan"}) + pete (nodes/create {:name "Peter"}) _ (relationships/create john adam :friend) _ (relationships/create john pete :friend) _ (relationships/create adam pete :friend) - xs1 (nodes/traverse (:id john) :relationships [{ :direction "all" :type "friend" }]) + xs1 (nodes/traverse (:id john) :relationships [{:direction "all" :type "friend"}]) ids1 (vec (map :id xs1)) - xs2 (nodes/traverse (:id john) :relationships [{ :direction "all" :type "enemy" }]) + xs2 (nodes/traverse (:id john) :relationships [{:direction "all" :type "enemy"}]) ids2 (map :id xs2)] (is (= [(:id john) (:id adam) (:id pete)] ids1)) (is (= [(:id john)] ids2)))) (deftest test-traversing-relationships-using-all-return-filter-all-relationships-and-no-pagination - (let [john (nodes/create { :name "John" }) - adam (nodes/create { :name "Alan" }) - pete (nodes/create { :name "Peter" }) + (let [john (nodes/create {:name "John"}) + adam (nodes/create {:name "Alan"}) + pete (nodes/create {:name "Peter"}) rel1 (relationships/create john adam :friend) rel2 (relationships/create john pete :friend) rel3 (relationships/create adam pete :friend) - xs1 (relationships/traverse (:id john) :relationships [{ :direction "all" :type "friend" }]) + xs1 (relationships/traverse (:id john) :relationships [{:direction "all" :type "friend"}]) ids1 (vec (map :id xs1)) - xs2 (relationships/traverse (:id john) :relationships [{ :direction "all" :type "enemy" }]) + xs2 (relationships/traverse (:id john) :relationships [{:direction "all" :type "enemy"}]) ids2 (map :id xs2)] (is (= [(:id rel1) (:id rel2)] ids1)) (is (empty? ids2)))) (deftest test-traversing-nodes-using-all-but-start-node-return-filter-out-relationships-and-no-pagination - (let [john (nodes/create { :name "John" }) - adam (nodes/create { :name "Alan" }) - pete (nodes/create { :name "Peter" }) + (let [john (nodes/create {:name "John"}) + adam (nodes/create {:name "Alan"}) + pete (nodes/create {:name "Peter"}) _ (relationships/create john adam :friend) _ (relationships/create adam pete :friend) - xs1 (nodes/traverse (:id john) :relationships [{ :direction "out" :type "friend" }] :return-filter { :language "builtin" :name "all_but_start_node" }) + xs1 (nodes/traverse (:id john) :relationships [{:direction "out" :type "friend"}] :return-filter {:language "builtin" :name "all_but_start_node"}) ids1 (vec (map :id xs1)) - xs2 (nodes/traverse (:id adam) :relationships [{ :direction "out" :type "friend" }] :return-filter { :language "builtin" :name "all_but_start_node" }) + xs2 (nodes/traverse (:id adam) :relationships [{:direction "out" :type "friend"}] :return-filter {:language "builtin" :name "all_but_start_node"}) ids2 (vec (map :id xs2))] (is (= [(:id adam) (:id pete)] ids1)) (is (= [(:id pete)] ids2)))) (deftest test-traversing-nodes-using-all-but-start-node-return-filter-in-relationships-and-no-pagination - (let [john (nodes/create { :name "John" }) - adam (nodes/create { :name "Alan" }) - pete (nodes/create { :name "Peter" }) + (let [john (nodes/create {:name "John"}) + adam (nodes/create {:name "Alan"}) + pete (nodes/create {:name "Peter"}) _ (relationships/create john adam :friend) _ (relationships/create adam pete :friend) - xs (nodes/traverse (:id john) :relationships [{ :direction "in" :type "friend" }] :return-filter { :language "builtin" :name "all_but_start_node" }) + xs (nodes/traverse (:id john) :relationships [{:direction "in" :type "friend"}] :return-filter {:language "builtin" :name "all_but_start_node"}) ids (vec (map :id xs))] (is (empty? ids)))) (deftest test-traversing-paths-using-all-return-filter-all-relationships-and-no-pagination - (let [john (nodes/create { :name "John" }) - adam (nodes/create { :name "Alan" }) - pete (nodes/create { :name "Peter" }) + (let [john (nodes/create {:name "John"}) + adam (nodes/create {:name "Alan"}) + pete (nodes/create {:name "Peter"}) rel1 (relationships/create john adam :friend) rel2 (relationships/create adam pete :friend) - xs1 (paths/traverse (:id john) :relationships [{ :direction "all" :type "friend" }]) - xs2 (paths/traverse (:id john) :relationships [{ :direction "all" :type "enemy" }])] + xs1 (paths/traverse (:id john) :relationships [{:direction "all" :type "friend"}]) + xs2 (paths/traverse (:id john) :relationships [{:direction "all" :type "enemy"}])] (is (= 3 (count xs1))) (is (= 1 (count xs2))) (let [path1 (first xs1) @@ -107,12 +104,12 @@ ;; (deftest test-shortest-path-algorithm-1 - (let [john (nodes/create { :name "John" :age 28 :location "New York City, NY" }) - liz (nodes/create { :name "Liz" :age 27 :location "Buffalo, NY" }) - beth (nodes/create { :name "Elizabeth" :age 30 :location "Chicago, IL" }) - bern (nodes/create { :name "Bernard" :age 33 :location "Zürich" }) - gael (nodes/create { :name "Gaël" :age 31 :location "Montpellier" }) - alex (nodes/create { :name "Alex" :age 24 :location "Toronto, ON" }) + (let [john (nodes/create {:name "John" :age 28 :location "New York City, NY"}) + liz (nodes/create {:name "Liz" :age 27 :location "Buffalo, NY"}) + beth (nodes/create {:name "Elizabeth" :age 30 :location "Chicago, IL"}) + bern (nodes/create {:name "Bernard" :age 33 :location "Zürich"}) + gael (nodes/create {:name "Gaël" :age 31 :location "Montpellier"}) + alex (nodes/create {:name "Alex" :age 24 :location "Toronto, ON"}) rel1 (relationships/create john liz :knows) rel2 (relationships/create liz beth :knows) rel3 (relationships/create liz bern :knows) @@ -120,7 +117,7 @@ rel5 (relationships/create gael beth :knows) rel6 (relationships/create beth gael :knows) rel7 (relationships/create john gael :knows) - rt { :type "knows" :direction "out" } + rt {:type "knows" :direction "out"} xs1 (paths/all-shortest-between (:id john) (:id liz) :relationships [rt] :max-depth 1) path1 (first xs1) xs2 (paths/all-shortest-between (:id john) (:id beth) :relationships [rt] :max-depth 1)