MrBlueSky
MrBlueSky

Reputation: 760

Using FitNesse to test RESTful APIs using RestFixture & anonymous namespaces

I'm considering using FitNesse to write some acceptance tests for some extensions to a RESTful API. The GET response includes XML in an anonymous namespace, e.g.

<?xml version="1.0" encoding="utf-8"?>
<things xmlns="http://example.com/ns/">
<thing id="1"/>
<thing id="2"/>
</things>

The FitNesse fixture RestFixture seems a good candidate for this. It should allow me to run an XPath to verify the response, but this does not appear to play nicely with anonymous namespaces. The following test will fail because needs the namespace specifying:

|!-smartrics.rest.fitnesse.fixture.RestFixture-!|http://example.com/v1.0/inbox |
|GET    | /things | 200 | | //thing |

I can find no way of expressing the XPath such that RestFixture will parse it successfully.

A couple of notes:

(a) You can query attributes because they're not in a namespace. The following passes:

|GET    | /things | 200 | | //@id |

(b) An example elsewhere suggested using string matching. This is wrong - the following passes too!

|GET    | /things | 200 | | 'complete and utter nonsense' |

Upvotes: 1

Views: 8156

Answers (1)

smartrics
smartrics

Reputation: 296

RestFixture now support namespaces. You need to define the namespace context as a key value map of alias/namespace uri using the RestFixtureConfig (this must include an alias for the default namespace too).

Then you can use the aliases therein defined in the xpaths that match the response body of a request, or in the let() command, to extract data from the response.

An example is included in the live documentation of the rest-fixture:

https://github.com/smartrics/RestFixture/downloads (check the downloadable html RestFixture-<ver>.html

Upvotes: 4

Related Questions