-- putting auto-commit to 'update' command as well
[bkell-clj.git] / test / helpers_test.clj
blobe2e30f4643baa348212a95540fe7a7986f539773
1 (ns helper-test
2         (:use [helpers] :reload-all)
3         (:use [clojure.test])
4         (:import java.io.ByteArrayInputStream) 
5         (:require clojure.contrib.str-utils)
9 (def configs (load-file "etc/config/config.test.clj"))
12 ;; test HTTP GET 
13 (deftest test-http-get 
14         
15         (let [result-GET (execute-http-call 
16                 (str (:url-test configs) "/thing") 
17                 "GET"
18                 { "Content-Type" "text/xml" } 
19                 nil)]
20                 
21                 (println "test result [" result-GET "]") 
22                 (is (not (nil? result-GET)) "GET result should not be nil") 
23                 (is (. (:msg result-GET ) equals "OK")) 
24                 (is (. (:code result-GET ) equals 200)) 
25                 
26                 (let [ parsed-test (clojure.xml/parse (ByteArrayInputStream. (.getBytes 
27                         (clojure.contrib.str-utils/str-join nil (:body-seq result-GET ))                ;; get the XML string  
28                         "UTF-8")))] 
29                         
30                         (is     ;; test that there is a 'thing' keyword , that can evaluate on a hash 
31                                 (. ((:tag parsed-test) {:thing "result" }) equals 
32                                 "result")
33                         )
34                         
35                 )
36         )
40 ;; test HTTP PUT 
41 (deftest test-http-put 
42         
43         ;; test good request 
44         (let [result-PUT (execute-http-call 
45                 (str (:url-test configs) "/test/test-good-http-put") 
46                 "PUT" 
47                 {       "Content-Type" "text/xml" "Authorization" (str "Basic " (:passwdBase64 configs)) } 
48                 "<test-good-http-put/>" 
49                 )]
50                 
51                 (println "test result [" result-PUT "]")
52                 (is (not (nil? result-PUT)) "PUT result should not be nil") 
53                 (is (. (:code result-PUT ) equals 201) "response code SHOULD be 201" )
54                 (is (. (:msg result-PUT ) equals "Created") "test xml should have been 'Created'" )
55         )
56         
57         ;; test bad passwd 
58         (let [result-PUT (execute-http-call 
59                 (str (:url-test configs) "/test/test-bad-passwd") 
60                 "PUT" 
61                 {       "Content-Type" "text/xml" "Authorization" "Basic badpasswd" } 
62                 "<test-bad-passwd/>" 
63                 )]
64                 
65                 (println "test result [" result-PUT "]")
66                 (is (not (nil? result-PUT)) "PUT result should not be nil") 
67                 (is (. (:code result-PUT ) equals 500) "response code SHOULD be 500" )
68                 (is (. (:msg result-PUT ) equals "Error") "test PUT should return 'Error'" )
69         )
70         
71         ;; test no Authorization        TODO - this should fail 
72         (comment (let [result-PUT (execute-http-call 
73                 (str (:url-test configs) "/test/test-no-authorization" ) 
74                 "PUT" 
75                 {       "Content-Type" "text/xml" } 
76                 "<test-no-authorization/>" 
77                 )]
78                 
79                 (println "test result [" result-PUT "]")
80                 (is (not (nil? result-PUT)) "PUT result should not be nil") 
81                 (is (. (:code result-PUT ) equals 401) "response code SHOULD be 201" )
82                 (is (. (:msg result-PUT ) equals "Created") "test xml should have been 'Created'" )
83         ))
84