RestFixtureTests.OverrideContentHandlers

Included page: .RestFixtureTests.SetUp (edit)

script smartrics.rest.test.fitnesse.fixture.HttpServerFixture
check is started true
reset resources database

.RestFixture uses three content handlers to parse and set expectations used to verify the behaviour of HTTP calls.
These are the handlers currently available:

These are the defaults


Note: unrecognised content types.

Content types not recogised will be mapped to the default content handler (XML).

For example, XML handler is used for for content types of application/xml; hence XPaths can be used to set expectations:

Table: Rest Fixture http://localhost:9876
GET
200
Content-Type : application/xml;.+
expected

Set-Cookie : JID="ABC.${a.y}";
Content-Type : application/xml;charset=ISO-8859-1
Content-Length : 183
Server : Jetty(6.0.2)
actual

 /resource/name[text()='a funky name'] <br/>
 /resource/data[text()='an important message']

expected

<resource>
    <name>a funky name</name>
    <data>an important message</data>
    <nstag xmlns:ns1='http://smartrics/ns1'>
        <ns1:number>3</ns1:number>
    </nstag>
</resource>
actual

Bespoke mapping can be defined in the config using the config key restfixture.content.handlers.map

Table: Rest Fixture Config overridesContentHandlerConfig
restfixture.content.handlers.map <br/>application/xml=TEXT<br/>

Table: Rest Fixture http://localhost:9876 overridesContentHandlerConfig
GET
200
Content-Type : application/xml;.+
expected

Set-Cookie : JID="ABC.${a.y}";
Content-Type : application/xml;charset=ISO-8859-1
Content-Length : 183
Server : Jetty(6.0.2)
actual
<resource>[\s.]*<name>a funky name</name>[\s\w\d<>/=\:'.]*</resource>[\s]*
expected

<resource>
    <name>a funky name</name>
    <data>an important message</data>
    <nstag xmlns:ns1='http://smartrics/ns1'>
        <ns1:number>3</ns1:number>
    </nstag>
</resource>
actual