Skip to content

Commit

Permalink
Merge branch 'contrib-removal'
Browse files Browse the repository at this point in the history
  • Loading branch information
mefesto committed Nov 8, 2011
2 parents 093d3ff + c553b7b commit 0c777c3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions project.clj
Expand Up @@ -3,7 +3,7 @@
:url "https://github.com/mefesto/wabbitmq"
:license {:name "Eclipse Public License - v 1.0"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
:dependencies [[org.clojure/clojure "1.2.1"]
[cheshire "2.0.2"]
[com.rabbitmq/amqp-client "2.2.0"]]
:dev-dependencies [[swank-clojure "1.3.0-SNAPSHOT"]])
:dev-dependencies [[swank-clojure "1.3.3"]])
10 changes: 5 additions & 5 deletions src/com/mefesto/wabbitmq/content_type.clj
@@ -1,5 +1,5 @@
(ns com.mefesto.wabbitmq.content-type
(:use [clojure.contrib.json :only (json-str read-json)]))
(:use [cheshire.core :only [generate-string parse-string]]))

(defn- charset [type]
(second (re-find #"charset=([^;]+)" type)))
Expand Down Expand Up @@ -29,14 +29,14 @@
(defn application-json-encode [content-type data]
(when data
(if-let [charset (charset content-type)]
(-> (json-str data) (.getBytes charset))
(-> (json-str data) (.getBytes)))))
(-> (generate-string data) (.getBytes charset))
(-> (generate-string data) (.getBytes)))))

(defn application-json-decode [content-type data]
(when data
(if-let [charset (charset content-type)]
(-> (String. data charset) (read-json))
(-> (String. data) (read-json)))))
(-> (String. data charset) (parse-string true))
(-> (String. data) (parse-string true)))))

(def application-json [application-json? application-json-encode application-json-decode])

Expand Down
10 changes: 5 additions & 5 deletions test/com/mefesto/wabbitmq/test_content_type.clj
@@ -1,5 +1,5 @@
(ns com.mefesto.wabbitmq.test-content-type
(:use [clojure.contrib.json :only (json-str)]
(:use [cheshire.core :only (generate-string)]
[clojure.test]
[com.mefesto.wabbitmq.content-type])
(:import [java.util Arrays]))
Expand Down Expand Up @@ -27,18 +27,18 @@
(is (false? (application-json? "application/other"))))

(deftest application-json-encoding
(is (Arrays/equals (-> (json-str [1 2 3]) (.getBytes))
(is (Arrays/equals (-> (generate-string [1 2 3]) (.getBytes))
(application-json-encode "application/json" [1 2 3])))
(is (Arrays/equals (-> (json-str [1 2 3]) (.getBytes "utf16"))
(is (Arrays/equals (-> (generate-string [1 2 3]) (.getBytes "utf16"))
(application-json-encode "application/json; charset=UTF-16" [1 2 3]))))

(deftest application-json-decoding
(is (= [1 2 3]
(application-json-decode "application/json"
(-> (json-str [1 2 3]) (.getBytes)))))
(-> (generate-string [1 2 3]) (.getBytes)))))
(is (= [1 2 3]
(application-json-decode "application/json; charset=UTF-16"
(-> (json-str [1 2 3]) (.getBytes "utf16"))))))
(-> (generate-string [1 2 3]) (.getBytes "utf16"))))))

(deftest application-clojure-supported?
(is (true? (application-clojure? "application/clojure")))
Expand Down

0 comments on commit 0c777c3

Please sign in to comment.