Tuesday, June 14, 2011

REST-assured Tricks How to test HTTP 201 Created ?

How to test HTTP 201 Created ?

This is two testcases a) Status Code b) Location header

// Prepare data to be posted    
 String xmlBody = "<orderData><orderType>BUY</orderType><quantity>44</quantity><symbol>YHO</symbol></orderData>";  
String location = given()  
  .body(xmlBody)  
  .contentType(ContentType.XML).body(xmlBody)  
 // a) test status code  
   .expect().statusCode(307)  
   .when()  
   .post("/RestFullDayTrader/resources/pending_orders/100").getHeader("Location");  
 // b) test Location Header  
 assertTrue(location.contains("pending_orders/100")); 

No comments: