Permalink
Browse files

Some services don't correctly provide content-type headers, allow the

contract to direct Janus to the proper serialization verification method.
  • Loading branch information...
1 parent 82d06b4 commit 85991291d0db98d66f560ab31a60dac4aaa5e902 @gga committed Jun 21, 2012
Showing with 9 additions and 5 deletions.
  1. +3 −0 src/janus/dsl.clj
  2. +6 −5 src/janus/verify.clj
View
@@ -14,6 +14,9 @@
(defn method [kw-method]
[:property {:name "method" :value kw-method}])
+(defn serialization [s11n]
+ [:property {:name "serialization" :value s11n}])
+
(defn body [& args]
[:body
(if (keyword? (nth args 0))
View
@@ -25,6 +25,10 @@
(= :equal-to comparison) (if (not= expected actual)
(str "Expected header '" header-name "' to equal '" expected "'. Got '" actual "'.")))))
+(defn property [prop-name contract context]
+ (:value (first (filter #(= prop-name (:name %))
+ (concat (:properties contract) (:properties context))))))
+
(defn errors-in-envelope [response contract context]
(concat
(map (partial check-clause response)
@@ -38,13 +42,10 @@
clauses (concat (:clauses contract) (:clauses context))]
(cond
(or (re-seq #"^application/json" doc-type)
- (re-seq #"\+json" doc-type)) (janus.json-response/verify-document body clauses)
+ (re-seq #"\+json" doc-type)
+ (= (property "serialization" contract context) :json)) (janus.json-response/verify-document body clauses)
:else [(str "Unable to verify documents of type '" doc-type "'")])))
-(defn property [prop-name contract context]
- (:value (first (filter #(= prop-name (:name %))
- (concat (:properties contract) (:properties context))))))
-
(defn headers-from [contract context]
(reduce (fn [acc v] (conj acc {(:name v) (:value v)}))
{}

0 comments on commit 8599129

Please sign in to comment.