export pact json from consumer
pact jvmで定義したコンシューマーのpactを他の環境で使いたい場合があり、jsonでエキスポートしたい
toMapを呼んでjsonでシリアライズすれば良い
code:clojure
(ns app
(:require clojure.test :refer :all
aleph.http :as http
manifold.deferred :as d)
(:import au.com.dius.pact.consumer ConsumerPactBuilder PactTestRun
au.com.dius.pact.consumer.model MockProviderConfig
au.com.dius.pact.core.model PactSpecVersion
au.com.dius.pact.consumer ConsumerPactRunnerKt))
(.toMap
(-> (ConsumerPactBuilder/consumer "Consumer")
(.hasPactWith "Provider")
(.uponReceiving "a request to say Hello")
(.path "/hello")
(.method "POST")
(.body "{\"name\": \"harry\"}")
(.willRespondWith)
(.status 200)
(.body "{\"hello\": \"harry\"}")
(.toPact))
PactSpecVersion/V4)
=> {"provider" {"name" "Provider"}, "consumer" {"name" "Consumer"}, "interactions" {"description" "a request to say Hello", "request" {"method" "POST", "path" "/hello", "body" {"name" "harry"}}, "response" {"status" 200, "body" {"hello" "harry"}}}, "metadata" {"pactSpecification" {"version" "4.0"}, "pact-jvm" {"version" "4.6.0"}}}
Supposedly you need to add "type": "Synchronous/HTTP", to interaction entries, else PactReader complains
code:clojure
{
"provider": {
"name": "Provider"
},
"consumer": {
"name": "Consumer"
},
"interactions": [
{
"description": "a request to say Hello",
"type": "Synchronous/HTTP",
"request": {
"method": "POST",
"path": "/hello",
"body": {
"name": "harry"
}
},
"response": {
"status": 200,
"body": {
"hello": "harry"
}
}
}
],
"metadata": {
"pactSpecification": {
"version": "4.0"
},
"pact-jvm": {
"version": "4.6.0"
}
}
}