I am using restassured with junit4. In my testing method, I create an object in mongodb, and when I run the test, it is saved successfully. But I need to save the created identifier so that I try to get the response body. But response.getBody().asString() empty.
@Test public void testA() throws JSONException { Map<String,Object> createVideoAssignmentParm = new HashMap<String,Object>(); createVideoAssignmentParm.put("test1", "123"); Response response = expect().statusCode(201).when().given().contentType("application/json;charset=UTF-8") .headers(createVideoAssignmentParm).body(assignment).post("videoAssignments"); JSONObject jsonObject = new JSONObject(response.getBody().asString()); id= (String)jsonObject.getString("assignmentId"); }
When I call the external endpoint from the outside, it returns the response body also with the corresponding fields, so there is no problem with the rest of the API.
If there is no answer for the above question, then how do you guys check the message with the return body using the rest so that I can try this.
My controller method looks like
@RequestMapping(value = "/videoAssignment", produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE, method = RequestMethod.POST) @ResponseBody public HttpEntity<VideoAssignment> createVideoAssingnment( //@ApiParam are there..){ //other methods return new ResponseEntity<>(va, HttpStatus.CREATED); }
source share