Wednesday, June 08, 2011

REST-assured Tricks How to test for 307 Temporary Redirect ?

Testing for 307 has two parts a) test http status code b) test http header Location
String xmlBody = "<orderData><orderType>BUY</orderType><quantity>44</quantity><useraccountid>10</useraccountid></orderData>";
//xml payload
String location = given()
        .body(xmlBody)
        .contentType(ContentType.XML).body(xmlBody)
 // a) test http status code 307
 .expect().statusCode(307)
       .when()
       .post("/RestFullDayTrader/resources/pending_orders/100").getHeader("Location");
        System.out.println(" Location " + location);      
 // b) test http header Location   
  assertTrue(location1.contains("pending_orders/100"));

No comments: