Skip to content

Commit

Permalink
Cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelklishin committed May 1, 2012
1 parent 9146cf7 commit 2b4328e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 87 deletions.
4 changes: 1 addition & 3 deletions test/clojurewerkz/neocons/rest/test_connection.clj
Original file line number Diff line number Diff line change
@@ -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*))
Expand Down
24 changes: 11 additions & 13 deletions test/clojurewerkz/neocons/rest/test_indexing.clj
Original file line number Diff line number Diff line change
@@ -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/")
Expand All @@ -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
Expand All @@ -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")]
Expand All @@ -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")
Expand All @@ -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))
Expand Down
21 changes: 9 additions & 12 deletions test/clojurewerkz/neocons/rest/test_nodes.clj
Original file line number Diff line number Diff line change
@@ -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]]))

Expand All @@ -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)))
Expand All @@ -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))
Expand All @@ -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))))
Expand All @@ -56,26 +54,25 @@


(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))]
(is (= new-value (-> updated-node :data :age)))))


(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))))))

45 changes: 21 additions & 24 deletions test/clojurewerkz/neocons/rest/test_relationships.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]]))
Expand All @@ -15,7 +13,6 @@
[xs]
(map :id xs))


;;
;; Working with relationships
;;
Expand Down Expand Up @@ -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])))
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -170,33 +167,33 @@


(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)))
(is (= new-data (:data fetched-rel)))))


(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)))))
Expand All @@ -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)))
Expand All @@ -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)))))
Loading

0 comments on commit 2b4328e

Please sign in to comment.