Post request body doesn't resolve variables

18 views
Skip to first unread message

Fashionette bags

unread,
Aug 17, 2021, 3:05:13 AM8/17/21
to REST assured
I have simple test using rest assured as below.
Case1: If I pass json string as below, it works fine.

@Test
    public void dummyTest throws Exception {

       String newUserEmail = "postOrder" + UUID.randomUUID() + "@gmail.com";
       String json = "{\n" +
                 "    \"name\": \"Marisa\",\n" +
                "    \"birthday\": \"1997-10-06\",\n" +
                "    \"title\": \"Dr.\",\n" +
                "    \"email\": \"postO...@gmail.com\",\n" +
                "  },\n" 
       given()
                .baseUri("my_request_url")
                .header("Content-Type", "application/json")
                .body(json)
                .when()
                .post()
                .then()
                .log().all();
}



Above returns 200 response. 
*******************************************************************************************
But If I write my test as below , passing email as variable, returns 500 
 @Test
    public void dummyTest throws Exception {

       String newUserEmail = "postOrder" + UUID.randomUUID() + "@gmail.com";
       String json = "{\n" +
                 "    \"name\": \"Marisa\",\n" +
                "    \"birthday\": \"1997-10-06\",\n" +
                "    \"title\": \"Dr.\",\n" +
               "    \"email\": \""+newUserEmail+"\",\n" +
               "  },\n" 
       given()
                .baseUri("my_request_url")
                 .header("Content-Type", "application/json")
                .body(json)
                .when()
                .post()
                .then()
                .log().all();
}

*******************************************************************************************
I get 500 error response 

HTTP/1.1 500 Internal Server Error
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Date: Mon, 16 Aug 2021 17:05:36 GMT
Server: Apache
Cache-Control: no-cache, private
X-Cache: Error from cloudfront
X-Amz-Cf-Pop: ZRH50-C1
X-Amz-Cf-Id: xGkO8cJGV0Pq7wAx71YyglWzQNdZzooohqZLZBHkC54iZgiNhGmpEA==


Reply all
Reply to author
Forward
0 new messages