Skip to content

Commit

Permalink
1.2.2 merges across fix for github issue #4 and additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brehaut committed Oct 6, 2011
1 parent b3c23ff commit 1ac8c51
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion project.clj
@@ -1,4 +1,4 @@
(defproject necessary-evil "1.2.1"
(defproject necessary-evil "1.2.2"
:description "An implementation of XML-RPC for the Clojure Ring HTTP stack"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
Expand Down
2 changes: 1 addition & 1 deletion src/necessary_evil/methodcall.clj
Expand Up @@ -35,7 +35,7 @@

(defn parse-params
"returns a vector containing one element for each param in the method call"
[x] (vec (map parse-value (xml-> x :params :param :value first-child))))
[x] (vec (map (comp parse-value first-child) (xml-> x :params :param :value))))

(defn parse
"Takes xml structure representing an RPC method call and returns a new
Expand Down
4 changes: 2 additions & 2 deletions src/necessary_evil/value.clj
Expand Up @@ -80,7 +80,7 @@
(defn parse-array [v] (vec (map parse-value
(xml-> v :array :data :value first-child))))

(defmulti parse-value #(:tag (zip/node %)))
(defmulti parse-value #(when % (:tag (zip/node %))))

(defmethod parse-value :i4 [v] (parse-int v))
(defmethod parse-value :int [v] (parse-int v))
Expand All @@ -94,7 +94,7 @@
(defmethod parse-value :base64 [v] (-> (text v) Base64/decodeBase64))
(defmethod parse-value :struct [v] (parse-struct v))
(defmethod parse-value :array [v] (parse-array v))
(defmethod parse-value :default [v] (text v))
(defmethod parse-value :default [v] (if v (text v) ""))

(defmethod parse-value :nil [v]
(if *allow-nils* nil
Expand Down
42 changes: 39 additions & 3 deletions test/necessary_evil/test/core.clj
@@ -1,9 +1,12 @@
(ns necessary-evil.test.core
(:use [necessary-evil.core] :reload)
(:require [necessary-evil.methodcall :as methodcall] :reload)
(:require [necessary-evil.methodcall :as methodcall]
[necessary-evil.methodresponse :as methodresponse]
:reload)
(:use [necessary-evil.value] :reload)
(:use [clojure.test]
[necessary-evil.xml-utils :only [to-xml emit]])
(:use [ring.adapter.jetty :only [run-jetty]])
(:require [clj-time.core :as time]
[clojure.xml :as xml])
(:import org.apache.commons.codec.binary.Base64))
Expand Down Expand Up @@ -35,6 +38,15 @@
<params><param><value>string</value></param></params>
</methodCall>")

(defxml method-call-empty-default-arg xml-prolog
"<methodCall>
<methodName>test.method.name</methodName>
<params><param><value></value></param></params>
</methodCall>")

(defxml github-issue-4-xml xml-prolog
"<methodResponse><params><param><value><struct><member><name>foo</name><value></value></member><member><name>bar</name><value>xyz</value></member></struct></value></param></params></methodResponse>")

(defxml method-call-string-arg xml-prolog
"<methodCall>
<methodName>test.method.name</methodName>
Expand Down Expand Up @@ -230,6 +242,8 @@
(deftest params
(is (= (methodcall/parse-params method-call-default-arg) ["string"])
"did not parse untyped string correctly")
(is (= (methodcall/parse-params method-call-empty-default-arg) [""])
"did not parse untyped empty string correctly")
(is (= (methodcall/parse-params method-call-string-arg) ["string"])
"did not parse string correctly")
(is (= (methodcall/parse-params method-call-int-arg)
Expand Down Expand Up @@ -275,5 +289,27 @@
(deftest emit-method-call-test
(is (= (to-xml (with-out-str (emit (methodcall/unparse (necessary-evil.methodcall.MethodCall. :test.method.name [])))))
method-call-test-method-name)))




(defn- ping-server [port]
(let [ep (end-point {"method" (fn [argument] {"argument" argument})})]
(run-jetty ep {:port port :join? false})))

(deftest chars-rountrip
(let [port 12254
jetty-server (ping-server port)
non-US-ASCII "Eléonore"]
(try
;; test non-US-ASCII chars roundtrip
(is (= non-US-ASCII
(:argument (call (str "http://localhost:" port)
"method"
non-US-ASCII))))
(finally (.stop jetty-server)))))


(deftest github-issue-4
(is (methodresponse/parse github-issue-4-xml)
{:foo ""
:bar "xyz"}))

0 comments on commit 1ac8c51

Please sign in to comment.