Here's a simple mock for a REST service - a basic "status" service which returns a JSON.
The rules below that implement it are defined in the "specs" realm, so we need to point to that project:
val HOST ="http://specs.dieselapps.com"
="http://specs.dieselapps.com"
Testing the default binding:
send::
msg snakk.json (url)
expect:: (payload[="status"] is "ok"
)
send::
msg snakk.json (url, snakkHttpOptions:JSON)
expect:: (snakk[="response"][="code"] is 501
)
This is a custom binding:
send::
msg snakk.json (url)
expect:: (payload[="status"] is "ok"
)
send::
msg snakk.json (url)
expect:: (payload[="someStats"] is "456"
)
send::
msg snakk.json (url)
expect:: (payload[="accountId"] is "67"
)
send::
msg snakk.text (url, snakkHttpOptions:JSON)
expect:: (snakk[="response"][="code"] is 501
)
Match an explicit diesel.flow.return
send::
msg snakk.text (url, snakkHttpOptions:JSON)
expect:: (snakk[="response"][="code"] is 404
)
expect:: (snakk[="response"][="headers"][="myheader"] is "mine"
)
send::
msg ctx.echo (snakk.response.headers)
Not match anything - payload is empty
send::
msg snakk.text (url, snakkHttpOptions:JSON)
expect:: (payload is empty
)
expect:: (snakk[="response"][="code"] is 501
)
send::
msg snakk.text (url, snakkHttpOptions:JSON)
expect:: (payload is empty
)
expect:: (snakk[="response"][="code"] is 501
)
send::
msg snakk.json (url)
expect:: (payload[="accountId"] is "78"
)
send::
msg snakk.json (url)
expect:: (payload[="accountId"] is "path1/path2/89"
)
Testing a POST with a JSON body to a service mock:
send::
msg snakk.json (url, verb="POST"
, body:JSON)
send::
msg ctx.echo (payload.status)
expect:: (payload[="status"] is "ok"
)
Testing these directly - without going through an http request (we simulate the initial message):
send::
msg diesel.rest (path="/getAccount/45"
)
You need to log in to post a comment!