Monday 9 May 2011

RestFixture v2.0

I just completed the release of the RestFixture v2.0.
With spare time to dedicate to it (courtesy of National Railways who has increased the number of carriages in the train to London to 12, so I can sit!), I took the opportunity to finish off the unfinished business.

The new codebase includes few new features (plus some bug fixes and improvements to the fixture APIs). The RestFixture code is available on GitHub.

This is the list of the main additions. Further details are available in the generated documentation file.

SliM support
It's now possible to run the fixtures with the SLIM runner.
To do so, it's sufficient to specify in the root page of the suites to be run with SliM the following line:

!define TEST_SYSTEM {slim}

then, as each fixture is implemented as a TableTable, the first row of each fixture should be written as

| !-Table:smartrics.rest.fitnesse.fixture.RestFixture-! base_host_uri |


Setting custom content-type to adapter map
Up until version 1.1.1, the way of interpreting the expectations in each response body cell was dictated by the content type of the response.
Now, it's possible to override the default behaviour by specifying a config property that maps the content type of a response to a body handler. The name of the property is restfixture.content.handlers.map; and the available body handlers are

  • XML to interpret the body as an xml string and the expectations as a list of \n separated XPath expressions

  • JSON to interpret the body as a JSON string and the expectations as either a list of JavaScript lines to be evaluated in AND or as a block of JavaScript, if the first line of the cell is the string /* javascript */

  • TEXT to interpre the body as a string and expectations as a list of regular expressions to be matched against the body


The 'comment' command
A new command to inject comments in a fixture; useful to evaluate labels

|comment| the value of 'replaceme' is %replaceme% |


The LET handler
Let now can evaluate JavaScript strings and assign the result to labels. This allows greater expressiveness in extracting data from a REST response.

Other additions

  • labels containing a null value are rendered by default with the string 'null'. It's possible now to override this behaviour by defining the config 'restfixture.null.value.representation'

  • body cells with large content can be rendered in a folding tag. A button is provided to toggle the visibility of the content.

8 comments:

Anonymous said...

Does RestFixture offer any support for basic pre-authentication?

I begin my test with:
|!-smartrics.rest.fitnesse.fixture.RestFixtureConfig-!|
|http.basicauth.username|'admin'|
|http.basicauth.password|'admin'|
|restfixure.default.headers|!-Accept: application/xml
Accept-Charset: utf-8
Keep-Alive: 300
Connection: keep-alive-!|

This does not seem to work.

smartrics said...

please post the issue here https://github.com/smartrics/restfixture/issues

explaining what result you get from a fixture with the config you have tried

Unknown said...

Thanks for creating the RestFixture.

In our resources we frequently have fields whose values are URIs referring to other resources (e.g. http://sfftcpod:8080/account/1234). I want to use those URIs in subsequent requests, but that is not possible (or doesn't seem so) because the URI is going to be appended to the base URL that is specified in the smartrics.rest.fitnesse.fixture.RestFixture

The RestFixture instance declaration requires a non-null base URL.

Is there a way to avoid that?

Unknown said...

Also, I haven't figured out how to get the sequence diagrams to work. When I go to the smartrics/RestFixture/RestFixture-2.0.beta.2.html page, none of the sequence diagrams appear. Should they?

And when I try to use RestFixtureWithSeq on my own pages either nothing happens (I don't see a diagram), or I get an exception on the POST:

Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:571)
at java.util.ArrayList.get(ArrayList.java:349)
at smartrics.rest.fitnesse.fixture.RestFixtureWithSeq.POST(RestFixtureWithSeq.java:216)

smartrics said...

Jon, I'll check the sequence diagrams

as for the URI issue, can you post an example and the intended behaviour?

please use the github issue tracker for the rest fixture

thanks

Anonymous said...

smartrics, I found it difficult to find a place to post the question. Hope this is OK-place to do it. Had started using RestFixture in Fitnesse last week. I felt like writing js, uploading it to Fitnesse, and then importing .js file from URL. I modified your code and with few changes was able to add the functionality. I would like to share / merge the code with yours so it can be maintained with future releases. Also, added functionality to report error conditions from js better (more detail that current 'not found'). Please contact me and / or let me know how to better contact u about this.
Cheers,
Mike

smartrics said...

Mike the best thing to do is a pull request on github... We can discuss your changes there. I am happy to merge if the change is fully implemented (including unit tests and if necessary updates to the cat/live docs )

Anonymous said...

Thank you for developing RestFixture for FitNesse. It looks to be a highly versatile tool. Unfortunately, I have only been able to get it to successfully execute GET and DELETE requests. My attempts to execute PUT requests have failed with the error (... displayed in the body 'expectation' cell):

...
body>
Bad request


For request 'PUT /organisation' [Invalid XML]


</body
...


The 'edit' view of my test:

!define TEST_SYSTEM {slim}

!path C:\workspace\fitnesse\TestREST\lib\*


|Table:smartrics.rest.fitnesse.fixture.RestFixture | http://yellowtest-vm.yonder.hubbub.com.au:9000 |
|GET | /organisation | 200 | Content-Type : text/plain | "Yarris Pty Ltd" |
|setBody | {"_typeHint":"models.party.Organisation","names":[{"_typeHint":"models.party.PartyName","id":1,"surName":"Peter Test 5","nameType":"","validFrom":"2012-10-18T05:19:43Z","validTo":"2012-10-18T05:19:43Z"}],"externalIdentifiers":[{"_typeHint":"models.party.identifiers.ABN","abnNumber":0}],"contacts":[{"_typeHint":"models.locator.Address","floor":1,"room":"Back Room","unitNumber":3,"streetNumber":0,"streetName":"","suburb":"","city":"Melbourne","state":"","country":"Australia","postCode":3068,"lat":0,"long":0}]}|
|PUT | /organisation ||| no-body |