HsacExamples.SlimTests.MockXmlServerTest


Here we use FitNesse as a HTTP server so we can control which responses the application being tested receives.

No Messages


The messages report table does not fail a test, it just shows the current status. It will be have an 'ignored' status when no messages were expected nor served.


table: Mock Server Message Report
No requests expected or received at: /FitNesseMock

Too Few Messages


script mock xml server setup
add response
<dag/>
add response
<dag2/>
with status 201
$url<-[http://127.0.0.1:8000/FitNesseMock] get mock server url

script xml http test
post
<Hallo/>
to $url->[http://127.0.0.1:8000/FitNesseMock]
check response status 200
show response
<dag/>

The messages report table does not fail a test, it just shows the current status. It will show red lines for expected requests that never came, or extra requests received.


table: Mock Server Message Report
1 (of 2) request(s) did not match expectation
1

request

<Hallo/>

response

<dag/>
2No request received

response

<dag2/>

Messages As Expected


script xml http test
post
<Hallo2/>            
to $url->[http://127.0.0.1:8000/FitNesseMock]
check response status 201
show response
<dag2/>

The messages report table does not fail a test, it just shows the current status. It will show red lines for expected requests that never came, or extra requests received.


table: Mock Server Message Report
Expected and received 2 requests
1

request

<Hallo/>

response

<dag/>
2

request

<Hallo2/>

response

<dag2/>

script mock xml server setup
verify all responses served
verify no extra requests
stop

Extra Messages


script mock xml server setup
add response
<bye/>
$url<-[http://127.0.0.1:8000/FitNesseMock] get mock server url

script xml http test
post
<Hallo/>
to $url->[http://127.0.0.1:8000/FitNesseMock]
check response status 200
note Posting an extra message will cause a 404 response, normally this fails a test, but we prevent this by using a 'show' line below
show post
<Hallo2/>
to $url->[http://127.0.0.1:8000/FitNesseMock] false
check response status 404
show response

The messages report table does not fail a test, it just shows the current status. It will show red lines for expected requests that never came, or extra requests received.


table: Mock Server Message Report
1 (of 2) request(s) did not match expectation
1

request

<Hallo/>

response

<bye/>
2

request

<Hallo2/>
Unexpected request, no response set up

script mock xml server setup
stop

Use a file as the response


script file fixture
set directory http://files/test
$responseFile<-[response.xml] create response.xml containing

script mock xml server setup
add response file $responseFile->[response.xml]
add response file $responseFile->[response.xml] with status 201
$url<-[http://127.0.0.1:8000/FitNesseMock] get mock server url

script xml http test
get from $url->[http://127.0.0.1:8000/FitNesseMock]
check response status 200
show response
<responseFromFile/>
get from $url->[http://127.0.0.1:8000/FitNesseMock]
check response status 201
show response
<responseFromFile/>


Headers


script mock xml server setup
add response bye with headers
Content-type application/xml
My-header abc-Ë
add response bye2 with headers
Content-type text/html; charset=iso-8859-1
My-header xyz-Ë
add response bye3 with status 201 and headers
Content-Type text/html; charset=UTF-16
My-header x-Ë
$url<-[http://127.0.0.1:8000/FitNesseMock] get mock server url

script http test
get from $url->[http://127.0.0.1:8000/FitNesseMock]
check response header Content-type application/xml
check response header My-header abc-Ë
check response status 200
check response bye
get from $url->[http://127.0.0.1:8000/FitNesseMock]
check response header Content-type text/html; charset=iso-8859-1
check response header My-header xyz-Ë
check response status 200
check response bye2
get from $url->[http://127.0.0.1:8000/FitNesseMock]
check response header Content-type text/html; charset=UTF-16
check response header My-header x-Ë
check response status 201
check response bye3






table: Mock Server Message Report
Expected and received 5 requests
1

request

GET: /FitNesseMock

response

<responseFromFile/>
2

request

GET: /FitNesseMock

response

<responseFromFile/>
3

request

GET: /FitNesseMock

response

bye
4

request

GET: /FitNesseMock

response

bye2
5

request

GET: /FitNesseMock

response

bye3

script mock xml server setup
stop

Controlling server address


The mock server can be customized to control the address, port and path it listens on.
This is done by adding extra columns to the first row (constructor parameters).
One can specify either a single port number, or a range (two ports separated by '-').
When specifying a path this path must also be supplied when stopping the server.

script mock xml server setup localhost 58876-58878 /mock
show get mock server url http://127.0.0.1:58876/mock


script mock xml server setup /mock
stop