From 08b7f8b2b0085287b20f47b8bd2fb7869dd62869 Mon Sep 17 00:00:00 2001 From: Timothy Washington Date: Mon, 27 Sep 2010 20:20:41 -0400 Subject: [PATCH] -- adding test/{login_test.clj,add_test.clj} to the project -- some refactorings; trying to use more unit tests --- bkell.clj | 7 +++-- etc/config/config.test.clj | 5 ++-- src/commands/add.clj | 11 +++++-- test/add_test.clj | 55 ++++++++++++++++++++++++++++++++++ test/helpers_test.clj | 8 ++--- test/login_test.clj | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 149 insertions(+), 10 deletions(-) create mode 100644 test/add_test.clj create mode 100644 test/login_test.clj diff --git a/bkell.clj b/bkell.clj index ce07040..19f3414 100644 --- a/bkell.clj +++ b/bkell.clj @@ -13,10 +13,13 @@ (Parser. (Lexer. (PushbackReader. (InputStreamReader. java.lang.System/in) 1024))) ) +(defn init-shell [] + (def shell (ref { :active true })) ;; the shell and memory +) + (defn bkell [handler] - - (def shell (ref { :active true })) ;; the shell and memory + (init-shell) (loop [ dfadapter handler ] ;; binds 'handler' to 'dfadapter' diff --git a/etc/config/config.test.clj b/etc/config/config.test.clj index b931233..d79946b 100644 --- a/etc/config/config.test.clj +++ b/etc/config/config.test.clj @@ -1,6 +1,7 @@ { - :url-test "http://localhost:8080/exist/rest" - :passwdBase64 "YWRtaW4=" + :url-test "http://localhost:8080/exist/rest/" + :system-dir "testDB/" + :passwdBase64 "YWRtaW4=" } diff --git a/src/commands/add.clj b/src/commands/add.clj index 652a48d..c7109a7 100644 --- a/src/commands/add.clj +++ b/src/commands/add.clj @@ -1,4 +1,7 @@ (require 'clojure.contrib.string) +(use 'helpers) +(require 'bkell) + (defn add-user [db-base-URL db-system-DIR working-USER] @@ -27,8 +30,12 @@ (println "check-user[" check-user "]") ;; TODO - if , ADD user; user exists otherwise - (if (not (= (:msg check-user) "Error")) - + (if (and + ;; (not (= (:msg check-user) "Error")) + (= (:msg check-user) "OK") + (= (:code check-user) 200) + ) + (println "user ALREADY exists") ;; TODO - throw error to user (do diff --git a/test/add_test.clj b/test/add_test.clj new file mode 100644 index 0000000..6d29213 --- /dev/null +++ b/test/add_test.clj @@ -0,0 +1,55 @@ +(ns add-test + + (:use [helpers] :reload-all) + (:use [clojure.test]) + (:use [depth_adapter]) + + (:import java.io.ByteArrayInputStream) + (:require clojure.contrib.str-utils) +) + + +(def configs (load-file "etc/config/config.test.clj")) + + +;; -------- +;; TESTs for Registering a user + + +;; test adding against an existing user +(deftest test-add-existing-user + + + ;;(bkell (get-depth-adapter)) + + ;; check for failure (we should NOT be able to add) + + +) + + +;; test adding a new user +(deftest test-add-existing-user + + ;; check for add to aauth.groups + ;; check for add to aauth.users + ;; check for Associated Bookkeeping to Group + +) + + + +;; -------- +;; TESTs for adding an account + + + + +;; -------- +;; TESTs for adding an entry + + + + + + diff --git a/test/helpers_test.clj b/test/helpers_test.clj index b497d16..e2e30f4 100644 --- a/test/helpers_test.clj +++ b/test/helpers_test.clj @@ -18,10 +18,10 @@ { "Content-Type" "text/xml" } nil)] - (println "test result [" result-GET "]") - (is (not (nil? result-GET)) "GET result should not be nil") - (is (. (:msg result-GET ) equals "OK")) - (is (. (:code result-GET ) equals 200)) + (println "test result [" result-GET "]") + (is (not (nil? result-GET)) "GET result should not be nil") + (is (. (:msg result-GET ) equals "OK")) + (is (. (:code result-GET ) equals 200)) (let [ parsed-test (clojure.xml/parse (ByteArrayInputStream. (.getBytes (clojure.contrib.str-utils/str-join nil (:body-seq result-GET )) ;; get the XML string diff --git a/test/login_test.clj b/test/login_test.clj new file mode 100644 index 0000000..c7f436f --- /dev/null +++ b/test/login_test.clj @@ -0,0 +1,73 @@ +(ns login-test + + (:use [helpers] :reload-all) + (:use [clojure.test]) + (:use [depth_adapter]) + (:require [bkell]) + + (:import java.io.ByteArrayInputStream) + (:require clojure.contrib.str-utils) + (:require commands.add) +) + + +(def configs (load-file "etc/config/config.test.clj")) + + +;; FIXTUREs +(defn test-fixture-shell + "Initialize the shell" + [test] + + (bkell/init-shell) +) +(defn test-fixture-db + "test to clear out shell memory before a test is run" + [test] + + ;; make the shell active + (dosync + (alter bkell/shell conj + { :active true })) + + ;; create a basic user in the DB + (add-user (:url-test configs) (:system-dir configs) { :tag "user" :attrs { :id "test.user" } } ) + + ;; ** execute the TEST function + (test) + + ;; make the shell inactive + (dosync + (alter bkell/shell conj + { :active false })) + +) + +(use-fixtures :once test-fixture-shell) +(use-fixtures :each test-fixture-db) + +;; test basic login +(deftest test-login [] + + (is (= 5 5)) +) + + +;; test result when already logged in +(deftest test-existing-login [] + +) + + +;; test a login with a bad password +(deftest test-bad-password [] + +) + + +;; test logging out +(deftest test-logout [] + +) + + -- 2.11.4.GIT