Wednesday, June 08, 2011

REST-assured Tricks How to test custom content type?

The .contentType(ContentType.JSON) supports limited set of contentypes.ie,. ANY,TEXT,JSON,XML,HTML,URLENC and BINARY.
In RestFul applications we also create custom types. for Eg I created application/vnd.useraccountprofile+json
REST-assured can be used to test any content. The trick is the use .header()
result= given().contentType(ContentType.JSON)
    .body(userAccountProfile.toString())
    .header("accept", "application/vnd.useraccountprofile+json")                
    .header("Content-Type", "application/vnd.useraccountprofile+json")               
    .when()
    .put("/RestFullDayTrader/resources/acct/"+useraccountid+";profile")
    .expect().body("openbalance", equalTo(121),"useraccountid",notNullValue())
    .asString();

No comments: