Friday, January 31, 2014

Multipart Fitnesse fixture for Restful Apis

Fitnesse Fixture to handle Multipart/mixed Requests



Just wrote a fitnesse fixture for multipart mixed content types.
The already existing smartrics rest fixtures can handle only multipart/form-data not multipart/mixed.

It is also strange that the Httpcomponent 3.2  does not support multipart/mixed, but only multipart/form-data. Worse enough, I see no documentation that it does not support multipart/mixed. Going through the source code, I could see that the 'multipart/form-data' content type is hard-coded all over the place.

My fixture is written using :
Http component 4.3 : I have added additional support for multipart/mixed, apart from the already existing multipart/form-data
Smartrics rest fixutre 3.0 : Extended the already existing restfixture class and the partfactory class to support multipart/mixed

See my Google code Repository

Sample request to handle Multipart Mixed :


!|smartrics.rest.fitnesse.fixture.RestFixtureConfig|
|http.client.connection.timeout|55000|
|restfixture.display.actual.on.right|true|
|restfixture.default.headers|defHeader : 1|
|restfixture.xml.namespace.context|!-xsalias=${namespace1}
ysalias=${namespace2}
-!|
|restfixture.content.handlers.map|application/xml=XML|
!|com.goraksh.fitnesse.fixture.FitMultipartRestFixture|http://${BASE_URI}|
|setBody|....|
|uploadFile|D:\testcase\hello.txt|
|setHeader|X-session-header : %sessionId%|
|POST|/${RESOURCE_PATH}?${QUERY_PARAMS}|201|!-Cache-Control : no-cache
pragma : no-cache
Content-Type : application/xml-!||

Sample Request to handle Multipart/form-data


!|smartrics.rest.fitnesse.fixture.RestFixtureConfig|
|http.client.connection.timeout|55000|
|restfixture.display.actual.on.right|true|
|restfixture.default.headers|defHeader : 1|
|restfixture.xml.namespace.context|!-xsalias=${namespace1}
ysalias=${namespace2}
-!|
|restfixture.content.handlers.map|application/x-www-form-urlencoded=FORM-DATA|
!|com.goraksh.fitnesse.fixture.FitMultipartRestFixture|http://${BASE_URI}|
|setBody|....
|uploadFile|D:\testcase\hello.txt|
|setHeader|X-session-header : %sessionId%|
|POST|/${RESOURCE_PATH}?${QUERY_PARAMS}|201|!-Cache-Control : no-cache
pragma : no-cache
Content-Type : application/xml-!||

3 comments:

  1. Nitesh, will the same work for slim fixture?

    ReplyDelete
  2. and i didnot find support for multipart-formdata in smartrics rest fixtures? Can you please tell which version you were talking about? and how can i use the same in my tests?

    ReplyDelete
  3. HI Yogesh.. I used smartrix version = 3.0.
    I am not tested it on slim. It may require minor changes.

    You can browse through the source and see how can you use http component 4.3 with slim. Hope it requires only minor changes

    ReplyDelete