From f735c1cffeb3cfa9a269a990125726da8412895a Mon Sep 17 00:00:00 2001 From: Delta Alpha Rho Date: Tue, 2 Sep 2014 10:01:41 -0500 Subject: [PATCH 1/8] setup travis-ci --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3ecb9af --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: clojure +lein: lein2 +jdk: + - openjdk7 + - openjdk6 From 3af114581312165c0cca4f9aaaeef5161a4d7c11 Mon Sep 17 00:00:00 2001 From: Delta Alpha Rho Date: Tue, 2 Sep 2014 10:05:45 -0500 Subject: [PATCH 2/8] setup travis-ci status in README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ef74e56..cb7259d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.org/DeltaAlphaRho/groops.svg?branch=master)](https://travis-ci.org/DeltaAlphaRho/groops) + groops ====== From 91a61567bf1562e4d037d889a9189f1364903b5e Mon Sep 17 00:00:00 2001 From: Delta Alpha Rho Date: Tue, 2 Sep 2014 10:09:30 -0500 Subject: [PATCH 3/8] add 'lein server' script to travis yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 3ecb9af..a846aba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: clojure lein: lein2 +script: lein2 server jdk: - openjdk7 - openjdk6 From af9e68cbc7aaab0aeb1720a0dbc24de5447953a4 Mon Sep 17 00:00:00 2001 From: Delta Alpha Rho Date: Tue, 2 Sep 2014 10:13:46 -0500 Subject: [PATCH 4/8] remove jdk6 from travis yml --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a846aba..08aa4be 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,3 @@ lein: lein2 script: lein2 server jdk: - openjdk7 - - openjdk6 From bb262c6a2a10fb1ec72d14cfd8dd06c20804733b Mon Sep 17 00:00:00 2001 From: Delta Alpha Rho Date: Tue, 2 Sep 2014 10:16:59 -0500 Subject: [PATCH 5/8] remove script from travis yml --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 08aa4be..b34f54b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ language: clojure lein: lein2 -script: lein2 server jdk: - openjdk7 From 7de52fabee4dc9da267f2f8befa5346aabd0b7a4 Mon Sep 17 00:00:00 2001 From: Delta Alpha Rho Date: Thu, 4 Sep 2014 15:12:18 -0500 Subject: [PATCH 6/8] merge --- project.clj | 12 ++++++++---- resources/public/intro.html | 6 ++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/project.clj b/project.clj index bd9e3e7..a6ddf28 100644 --- a/project.clj +++ b/project.clj @@ -1,13 +1,12 @@ (defproject groops "0.1.0-SNAPSHOT" :description "Austin Clojure Meetup groops project" :url "https://github.com/AustinClojure/groops" - :dependencies [[org.clojure/clojure "1.6.0"] ;; server [cheshire "5.3.1"] [compojure "1.1.8"] - [http-kit "2.1.16"] + [http-kit "2.1.18"] [ring/ring-devel "1.1.8"] [ring/ring-core "1.1.8"] [ring/ring-json "0.3.1"] @@ -24,11 +23,16 @@ ;; dev [org.clojure/tools.nrepl "0.2.3"] [cider/cider-nrepl "0.7.0"] - [cljs-hash "0.0.2"]] + [cljs-hash "0.0.2"] + + ;; testing + [org.clojure/data.json "0.2.5"] + [http.async.client "0.5.2"]] :plugins [[com.cemerick/austin "0.1.5"] [lein-cljsbuild "1.0.3"] - [lein-ring "0.8.8"]] + [lein-ring "0.8.8"] + [com.cemerick/clojurescript.test "0.3.1"]] :resource-paths ["resources"] :cljsbuild {:builds [{:source-paths ["src-cljs"] diff --git a/resources/public/intro.html b/resources/public/intro.html index 3c1f08c..16bce67 100644 --- a/resources/public/intro.html +++ b/resources/public/intro.html @@ -20,6 +20,12 @@ + + Fork me on GitHub +
From dddca6a82a7a6b43f0289afb4a08c6842d5ffcd7 Mon Sep 17 00:00:00 2001 From: Delta Alpha Rho Date: Thu, 4 Sep 2014 15:23:26 -0500 Subject: [PATCH 7/8] basic testing --- .gitignore | 4 +- test/test_groops/api.clj | 93 ++++++++++++++++++++++++++++++++++++++ test/test_groops/async.clj | 37 +++++++++++++++ test/test_groops/web.clj | 21 +++++++++ 4 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 test/test_groops/api.clj create mode 100644 test/test_groops/async.clj create mode 100644 test/test_groops/web.clj diff --git a/.gitignore b/.gitignore index 1bf8a0a..dd37f27 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ pom.xml pom.xml.asc *.jar *.class +*# +*~ /.lein-* /.nrepl-port -resources/generated/ \ No newline at end of file +resources/generated/ diff --git a/test/test_groops/api.clj b/test/test_groops/api.clj new file mode 100644 index 0000000..228f00b --- /dev/null +++ b/test/test_groops/api.clj @@ -0,0 +1,93 @@ +(ns test-groops.api + (:require [groops.api :as api] + [groops.data :as data] + [clojure.data.json :as json]) + (:use clojure.test + ring.mock.request)) + +(comment + (ns test-groops.api) + (require '[groops.api :as api]) + (require '[groops.data :as data]) + (require '[clojure.data.json :as json]) + (use 'clojure.test) + (use 'ring.mock.request)) + +#_(defn request [method params] + (hash-map :request-method method :headers {} :params params)) + +(defn user-map [name email twitter] + (hash-map :name name :email email :twitter twitter)) + +(def test-users #{(user-map "John McCarthy" "john@lisp.com" "@JohnMcCarthy") + (user-map "Steve Russell" "steverussell@ibm.com" "@SteveRussell") + (user-map "Guy Steele" "guysteele@mit.edu" "@GuySteele") + (user-map "Rich Hickey" "rich@clojure.com" " @RickHickey")}) + +(defn post-test-user [user] + (api/api-routes (-> (request :post "/api/user") + (assoc :params user)))) + +(doall (map post-test-user test-users)) + +(deftest test-post-user-count + (is (= 4 (count (deref data/registry-set))))) + +(comment + (api/post-room (request :post {:room-name "Alpha"})) + (api/post-room (request :post {:room-name "Beta"})) + (api/post-room (request :post {:room-name "Gamma"})) + (api/post-room (request :post {:room-name "Delta"}))) + +(defn post-test-room [room] + (api/api-routes (-> (request :post "/api/room") + (assoc :params {:room-name room})))) + +(def test-rooms #{"Alpha" "Beta" "Gamma" "Delta"}) + +(doall (map post-test-room test-rooms)) + +(deftest test-post-room-count + (is (= 4 (count (deref data/room-set))))) + + +(defn get-user-in-room-count [] + (let [room-count-map (json/read-str + (:body + (api/api-routes (request :get "/api/rooms"))))] + (apply + (vals (first (vals room-count-map)))))) + +(deftest test-get-rooms-initially-zero + (is (= 0 (get-user-in-room-count)))) + +(defn get-message-vect-from-room [room] + (first + (vals + (json/read-str + (:body (api/api-routes + (request :get (str "/api/room/messages/" room)))))))) + +(defn message-map [room user message gravatar-url] + (hash-map :room room :user user :message message + :gravatar-url gravatar-url)) + +(def test-messages #{(message-map "Alpha" "John McCarthy" + "This is the first room" + nil) + (message-map "Alpha" "Steve Russell" + "This is the second message in the first room" + nil)}) + +(defn post-test-message [message] + (api/api-routes (-> (request :post "/api/room/message") + (assoc :params message)))) + +(doall (map post-test-message test-messages)) + +(deftest two-count-message-vect + (is (= 2 (count (get-message-vect-from-room "Alpha")))) + (is (empty? (get-message-vect-from-room "Beta"))) + (is (empty? (get-message-vect-from-room "Gamma"))) + (is (empty? (get-message-vect-from-room "Delta")))) + + diff --git a/test/test_groops/async.clj b/test/test_groops/async.clj new file mode 100644 index 0000000..9fee8e8 --- /dev/null +++ b/test/test_groops/async.clj @@ -0,0 +1,37 @@ +(ns test-groops.async + (:require [groops.async :as async] + [http.async.client :as http]) + (:use clojure.test + ring.mock.request) + ) + +(comment + (ns test-groops.async) + (require '[groops.async :as async]) + (require '[http.async.client :as http]) + (use 'clojure.test) + (use 'ring.mock.request)) + +(comment + (def basic-req (request :get "/")) + + (def client (http/create-client)) + + (def latch (promise)) + + (def received-msg (atom nil)) + (def connection (atom nil)) + + (def ws (http/websocket client "ws://localhost:8080/chat-ws" + :text (fn [con msg] + (println "ws text:" con msg)) + :close (fn [con status] + (println "ws close:" con status)) + :open (fn [con] + (println "ws opened:" con)))) + + (http/send ws :text (pr-str {:name "Rich Hickey" :email "rich@clojure.com" :room "Alpha"})) + + +;;;(def response (http:/GET client "http://localhost:8080/chat-ws")) + ) diff --git a/test/test_groops/web.clj b/test/test_groops/web.clj new file mode 100644 index 0000000..7155e8f --- /dev/null +++ b/test/test_groops/web.clj @@ -0,0 +1,21 @@ +(ns test-groops.web + (:require [groops.web :as web]) + (:use clojure.test + ring.mock.request)) + +(comment + (ns test-groops.web) + (require '[groops.web :as web]) + (use 'clojure.test) + (use 'ring.mock.request)) + +(def basic-req {:get "/"}) + +(deftest landing-template-not-blank + (is (< 0 (count (web/landing-page basic-req))))) + +(deftest landing-template-contains-groops-js + (is (some #(.contains % "groops.js") (web/landing-page basic-req)))) + +(deftest root-route-okay + (is (= 200 (:status (web/app-routes (request :get "/")))))) From 47bd4ac1727833f909fa6096073a70882f865d66 Mon Sep 17 00:00:00 2001 From: Delta Alpha Rho Date: Thu, 4 Sep 2014 22:46:50 -0500 Subject: [PATCH 8/8] basic async testing --- project.clj | 2 +- src/groops/async.clj | 4 +--- test/test_groops/api.clj | 5 ++-- test/test_groops/async.clj | 49 +++++++++++++++++++++++++------------- 4 files changed, 37 insertions(+), 23 deletions(-) diff --git a/project.clj b/project.clj index a6ddf28..e74a77a 100644 --- a/project.clj +++ b/project.clj @@ -6,7 +6,7 @@ ;; server [cheshire "5.3.1"] [compojure "1.1.8"] - [http-kit "2.1.18"] + [http-kit "2.1.16"] [ring/ring-devel "1.1.8"] [ring/ring-core "1.1.8"] [ring/ring-json "0.3.1"] diff --git a/src/groops/async.clj b/src/groops/async.clj index 8718c9b..6e1c151 100644 --- a/src/groops/async.clj +++ b/src/groops/async.clj @@ -27,9 +27,7 @@ (swap! chat-clients dissoc channel) (println channel "disconnected. status: " status))) (on-receive channel (fn [data] - (println "on-receive channel:" channel " data:" data) - (swap! chat-clients assoc-in [channel] (read-string data)) - (println "chat-ws chat-clients" @chat-clients))))) + (swap! chat-clients assoc-in [channel] (read-string data)))))) (defn send-level [] (let [level (int (rand 100)) diff --git a/test/test_groops/api.clj b/test/test_groops/api.clj index 228f00b..dd977eb 100644 --- a/test/test_groops/api.clj +++ b/test/test_groops/api.clj @@ -84,9 +84,10 @@ (doall (map post-test-message test-messages)) -(deftest two-count-message-vect +(deftest count-message-vect (is (= 2 (count (get-message-vect-from-room "Alpha")))) - (is (empty? (get-message-vect-from-room "Beta"))) + ;; messages loaded into Beta froom in async testing + (is (= 1 (count (get-message-vect-from-room "Beta")))) (is (empty? (get-message-vect-from-room "Gamma"))) (is (empty? (get-message-vect-from-room "Delta")))) diff --git a/test/test_groops/async.clj b/test/test_groops/async.clj index 9fee8e8..4102336 100644 --- a/test/test_groops/async.clj +++ b/test/test_groops/async.clj @@ -1,6 +1,9 @@ (ns test-groops.async (:require [groops.async :as async] - [http.async.client :as http]) + [groops.server :as server] + [http.async.client :as http] + [clojure.data.json :as json] + [test-groops.api :as api-test :only post-test-message]) (:use clojure.test ring.mock.request) ) @@ -9,29 +12,41 @@ (ns test-groops.async) (require '[groops.async :as async]) (require '[http.async.client :as http]) + (require '[clojure.data.json :as json]) + (require '[test-groops.api :as api-test :only post-test-message]) (use 'clojure.test) (use 'ring.mock.request)) -(comment - (def basic-req (request :get "/")) +(server/start-webserver) - (def client (http/create-client)) +(def client (http/create-client)) - (def latch (promise)) +(def received-msg (atom nil)) - (def received-msg (atom nil)) - (def connection (atom nil)) +(def ws (http/websocket client "ws://localhost:8080/chat-ws" + :text (fn [con msg] + (reset! received-msg msg) + (println "test-groops.async: ws text: connection " con) + (println "test-groops.async: ws text: message " msg)) + :close (fn [con status] + (println "test-groops.async: ws close:" con status)) + :open (fn [con] + (println "test-groops.async: ws opened:" con)))) - (def ws (http/websocket client "ws://localhost:8080/chat-ws" - :text (fn [con msg] - (println "ws text:" con msg)) - :close (fn [con status] - (println "ws close:" con status)) - :open (fn [con] - (println "ws opened:" con)))) +(http/send ws :text (pr-str {:name "Rich Hickey" :email "rich@clojure.com" :room "Beta"})) - (http/send ws :text (pr-str {:name "Rich Hickey" :email "rich@clojure.com" :room "Alpha"})) +(deftest websocket-populates-chat-client + (let [chat-client (deref async/chat-clients) + ws-msg (first (vals chat-client))] + (is (> (count chat-client) 0)) + (is (= "Rich Hickey" (:name ws-msg))) + (is (= "rich@clojure.com" (:email ws-msg))) + (is (= "Beta" (:room ws-msg))))) +(api-test/post-test-message {:room "Beta" :user "Rich Hickey" :message "You're doing it wrong." :gravatar-url nil}) -;;;(def response (http:/GET client "http://localhost:8080/chat-ws")) - ) +(deftest websocket-sends-to-client + (let [msg-rec (first (vals (json/read-str @received-msg)))] + (println "websocket-sends-to-client msg:" ) + (is (= "Rich Hickey" (get-in msg-rec ["author"]))) + (is (= "You're doing it wrong." (get-in msg-rec ["message"])))))