From 8c5da785076d65c2750d38f4b391ba81ccbd7533 Mon Sep 17 00:00:00 2001 From: Timothy Washington Date: Sun, 3 Oct 2010 19:57:11 -0400 Subject: [PATCH] -- putting a generic 'get-user' function into helpers -- adding src/commands/remove.clj and test/run_tests.clj --- src/com/interrupt/bookkeeping/cc/lexer/Lexer.java | 2 +- src/commands/add.clj | 22 +------- src/commands/remove.clj | 63 +++++++++++++++++++++++ src/helpers.clj | 27 ++++++++++ test/login_test.clj | 37 +++++-------- test/run_tests.clj | 4 ++ 6 files changed, 110 insertions(+), 45 deletions(-) create mode 100644 src/commands/remove.clj create mode 100644 test/run_tests.clj diff --git a/src/com/interrupt/bookkeeping/cc/lexer/Lexer.java b/src/com/interrupt/bookkeeping/cc/lexer/Lexer.java index 16235d1..a525668 100644 --- a/src/com/interrupt/bookkeeping/cc/lexer/Lexer.java +++ b/src/com/interrupt/bookkeeping/cc/lexer/Lexer.java @@ -1,4 +1,4 @@ -/* This file was generated by SableCC (http://www.sablecc.org/). */ + /* This file was generated by SableCC (http://www.sablecc.org/). */ package com.interrupt.bookkeeping.cc.lexer; diff --git a/src/commands/add.clj b/src/commands/add.clj index c7109a7..07fbb76 100644 --- a/src/commands/add.clj +++ b/src/commands/add.clj @@ -6,27 +6,7 @@ (defn add-user [db-base-URL db-system-DIR working-USER] ;; 1. check that there's not an existing user - (let [check-user - (execute-http-call ;; TODO - put in 404 check - (str - db-base-URL - db-system-DIR - (working-dir-lookup (:tag working-USER)) ;; stringing together lookup URL leaf - "/" - (str - (name (:tag working-USER)) - "." - (:id (:attrs working-USER))) - "/" - (str ;; repeating user name as leaf document - (name (:tag working-USER)) - "." - (:id (:attrs working-USER)))) - "GET" - {"Content-Type" "text/xml"} - nil - ) - ] + (let [check-user (get-user db-base-URL db-system-DIR working-USER) ] (println "check-user[" check-user "]") ;; TODO - if , ADD user; user exists otherwise diff --git a/src/commands/remove.clj b/src/commands/remove.clj new file mode 100644 index 0000000..3e02095 --- /dev/null +++ b/src/commands/remove.clj @@ -0,0 +1,63 @@ +(require 'clojure.contrib.string) +(use 'helpers) +(require 'bkell) + + +(defn remove-user [db-base-URL db-system-DIR working-USER] + + ;; 1. check that there's not an existing user + (let [check-user (get-user db-base-URL db-system-DIR working-USER) ] + + (println "check-user[" check-user "]") ;; TODO - if , ADD user; user exists otherwise + + (if (and + (= (:msg check-user) "OK") + (= (:code check-user) 200) + ) + + (do + + (println "REMOVING user[" working-USER "]") + + + ;; PUT to eXist + (println "REMOVing group [" working-USER "]" ) + (execute-http-call + (str db-base-URL db-system-DIR (working-dir-lookup :group) + "/" "group." (:id (:attrs working-USER))) + "DELETE" + { "Content-Type" "text/xml" + "Authorization" "Basic YWRtaW46"} + nil + ) + + ;; 3. add to aauth.users ... PUT to eXist + ;; 4. profile Details ... PUT to eXist ... TODO + (println "REMOVing user [" working-USER "] / XML[" + (with-out-str (clojure.xml/emit working-USER)) "]" ) + (execute-http-call + (str db-base-URL db-system-DIR (working-dir-lookup :user) + "/" "user." (:id (:attrs working-USER))) + "DELETE" + { "Content-Type" "text/xml" + "Authorization" "Basic YWRtaW46"} + nil + ) + + ;; 5. add associated Bookkeeping to Group ... PUT to eXist + (execute-http-call + (str db-base-URL db-system-DIR (working-dir-lookup :bookkeeping) + "/" "group." (:id (:attrs working-USER)) ) + "DELETE" + { "Content-Type" "text/xml" + "Authorization" "Basic YWRtaW46"} + nil + ) + + ) + (println "user DOES NOT exist") ;; TODO - throw error if user does not exist + + ) + ) +) + diff --git a/src/helpers.clj b/src/helpers.clj index bcf053a..ed69d1b 100644 --- a/src/helpers.clj +++ b/src/helpers.clj @@ -128,9 +128,36 @@ (clojure-http.resourcefully/post full-URL header-hash xml-content) (catch Exception e { :msg "Error" :dmsg (. e getMessage ) } ) ) + (. "DELETE" equals http-method) + (try + (clojure-http.resourcefully/delete full-URL header-hash nil) + (catch Exception e { :msg "Error" :dmsg (. e getMessage ) } ) + ) ) ) +(defn get-user [db-base-URL db-system-DIR working-USER] + + (execute-http-call ;; TODO - put in 404 check + (str + db-base-URL + db-system-DIR + (working-dir-lookup (:tag working-USER)) ;; stringing together lookup URL leaf + "/" + (str + (name (:tag working-USER)) + "." + (:id (:attrs working-USER))) + "/" + (str ;; repeating user name as leaf document + (name (:tag working-USER)) + "." + (:id (:attrs working-USER)))) + "GET" + {"Content-Type" "text/xml"} + nil + ) +) diff --git a/test/login_test.clj b/test/login_test.clj index 7fc1385..b40fcfa 100644 --- a/test/login_test.clj +++ b/test/login_test.clj @@ -1,23 +1,16 @@ (ns login-test - ;;(:use [helpers] :reload-all) - ;;(:use [depth_adapter]) - ;;(:require [bkell]) - - ;;(:use [clojure.test]) - ;;(:import java.io.ByteArrayInputStream) - ;;(:require clojure.contrib.str-utils) - ;;(:require commands.add) + (:use [helpers] :reload-all) + (:use [depth_adapter]) + (:require [bkell]) + + (:use [clojure.test]) + (:import java.io.ByteArrayInputStream) + (:require clojure.contrib.str-utils) + (:require commands.add) + (:require commands.remove) ) -(use 'helpers ) -(use 'depth_adapter) -(require 'bkell) - -(use 'clojure.test) -(import 'java.io.ByteArrayInputStream) -(require 'clojure.contrib.str-utils) -(require 'commands.add) (def configs (load-file "etc/config/config.test.clj")) @@ -32,26 +25,24 @@ (test) ) + (defn test-fixture-db "test to clear out shell memory before a test is run" [test] (println "test-fixture-db CALLED") - ;; make the shell active - (dosync - (alter bkell/shell conj - { :active true })) + ;; make the shell active ;; create a basic user in the DB + (dosync (alter bkell/shell conj { :active true })) (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 })) + (dosync (alter bkell/shell conj { :active false })) + (remove-user (:url-test configs) (:system-dir configs) { :tag "user" :attrs { :id "test.user" } } ) ) diff --git a/test/run_tests.clj b/test/run_tests.clj new file mode 100644 index 0000000..be4379a --- /dev/null +++ b/test/run_tests.clj @@ -0,0 +1,4 @@ +(use 'clojure.test) +(require 'login-test) +(run-tests 'login-test) + -- 2.11.4.GIT