diff --git a/.gitignore b/.gitignore index 8dfa3b08..c096c0a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,9 @@ *.o *.py[co] +*.class +*.jar /uwsgi /uwsgibuild.* + +/t/ring/target diff --git a/t/ring/README.md b/t/ring/README.md new file mode 100644 index 00000000..27b507b3 --- /dev/null +++ b/t/ring/README.md @@ -0,0 +1,21 @@ +Ring Test Suite +================ + +how to build and run +--------------------- + +* cd UWSGIROOT +* cd t/ring +* lein uberjar +* cd ../.. +* uwsgi t/ring/config.ini +* open http://localhost:9090 in your browser + +run cases in jetty +------------------- + +* lein ring server +* open http://localhost:3000 in your browser + + + diff --git a/t/ring/config.ini b/t/ring/config.ini new file mode 100644 index 00000000..fcb819bf --- /dev/null +++ b/t/ring/config.ini @@ -0,0 +1,9 @@ +[uwsgi] +http = :9090 +http-modifier1 = 8 +http-modifier2 = 1 + +jvm-classpath = plugins/jvm/uwsgi.jar +jvm-classpath = t/ring/target/uwsgi-ring-tests-0.0.1-standalone.jar + +ring-app = uwsgi.ring.tests.app:app diff --git a/t/ring/project.clj b/t/ring/project.clj new file mode 100644 index 00000000..f3036710 --- /dev/null +++ b/t/ring/project.clj @@ -0,0 +1,10 @@ +(defproject unbit/uwsgi-ring-tests "0.0.1" + :description "uwsgi-ring-tests: test cases for uwsgi ring server" + :dependencies [[org.clojure/clojure "1.4.0"] + [compojure "1.1.3"] + [ring/ring "1.1.0"]] + + :source-paths ["src"] + + :plugins [[lein-ring "0.7.5"]] + :ring {:handler uwsgi.ring.tests.app/app}) diff --git a/t/ring/src/uwsgi/ring/tests/app.clj b/t/ring/src/uwsgi/ring/tests/app.clj new file mode 100644 index 00000000..77cd493e --- /dev/null +++ b/t/ring/src/uwsgi/ring/tests/app.clj @@ -0,0 +1,29 @@ +(ns uwsgi.ring.tests.app + (:use compojure.core) + (:use [ring.middleware params + keyword-params + nested-params + multipart-params]) + (:require [compojure.route :as route] + [uwsgi.ring.tests.basic :as basic] + [uwsgi.ring.tests.body :as body] + [uwsgi.ring.tests.simple :as simple] + [uwsgi.ring.tests.upload :as upload]) + (:gen-class + :main true)) + +(defn app-routes [req] + (if (= (get req :uri) "/") + (basic/index-page req) + ((routes simple/app-routes body/app-routes upload/app-routes) req))) + +(def app + (-> app-routes + wrap-keyword-params + wrap-nested-params + wrap-params + wrap-multipart-params)) + +(defn -main [& args] + (println "uwsgi ring tests app loaded")) + diff --git a/t/ring/src/uwsgi/ring/tests/basic.clj b/t/ring/src/uwsgi/ring/tests/basic.clj new file mode 100644 index 00000000..b95b6576 --- /dev/null +++ b/t/ring/src/uwsgi/ring/tests/basic.clj @@ -0,0 +1,30 @@ +(ns uwsgi.ring.tests.basic) + +(defn index-page [req] {:status 200 + :headers { "Content-Type" "text/html" , "Server" "uWSGI" } + :body (str "

Ring test suites

" + "

Simple tests

" + "" + "

Body type tests

" + "" + "

Upload tests

" + "
" + "

" + "Please select a file
" + "" + "

" + "" + "
" + "

Other tests

" + "")}) + diff --git a/t/ring/src/uwsgi/ring/tests/body.clj b/t/ring/src/uwsgi/ring/tests/body.clj new file mode 100644 index 00000000..7847cf47 --- /dev/null +++ b/t/ring/src/uwsgi/ring/tests/body.clj @@ -0,0 +1,20 @@ +(ns uwsgi.ring.tests.body + (:use [compojure.core])) + +; generating primary numbers +; http://clojuredocs.org/clojure_core/clojure.core/lazy-seq#example_1000 +(defn sieve [s] + (cons (first s) + (lazy-seq (sieve (filter #(not= 0 (mod % (first s))) + (rest s)))))) + +(defn sequence [] (take 20 (sieve (iterate inc 2)))) + +(defn file [] (java.io.File. "CONTRIBUTORS")) + +(defn stream [] (java.io.FileInputStream. (java.io.File. "CONTRIBUTORS"))) + +(defroutes app-routes + (GET "/sequence" [] (sequence)) + (GET "/file" [] (file)) + (GET "/stream" [] (stream))) diff --git a/t/ring/src/uwsgi/ring/tests/simple.clj b/t/ring/src/uwsgi/ring/tests/simple.clj new file mode 100644 index 00000000..b151498c --- /dev/null +++ b/t/ring/src/uwsgi/ring/tests/simple.clj @@ -0,0 +1,13 @@ +(ns uwsgi.ring.tests.simple + (:use [compojure.core])) + +(defn hello [] "Hello, World!") + +(defn echo [msg] msg) + +(defn palindrome [msg] (clojure.string/reverse msg)) + +(defroutes app-routes + (GET "/hello" [] (hello)) + (GET "/echo" [msg] (echo msg)) + (GET "/palindrome" [msg] (palindrome msg))) diff --git a/t/ring/src/uwsgi/ring/tests/upload.clj b/t/ring/src/uwsgi/ring/tests/upload.clj new file mode 100644 index 00000000..c36e13ea --- /dev/null +++ b/t/ring/src/uwsgi/ring/tests/upload.clj @@ -0,0 +1,20 @@ +(ns uwsgi.ring.tests.upload + (:use [compojure.core])) + +(defn upload-file [fname fsize fbody] { + :status 200 + :headers { "Content-Type" "text/html" , "Server" "uWSGI" } + :body (str "

Uploaded file

" + "")}) + +(defroutes app-routes + (POST "/upload" {params :params} + (let [file (params :file) + file-name (file :filename) + file-size (file :size) + file-body (file :tempfile)] + (upload-file file-name file-size file-body)))) +