Complete the code to create a TestRestTemplate instance.
TestRestTemplate restTemplate = new [1]();The TestRestTemplate class is used to create a test client for API testing in Spring Boot.
Complete the code to send a GET request to '/api/users' and get the response as a String.
ResponseEntity<String> response = restTemplate.[1]("/api/users", String.class);
The getForEntity method sends a GET request and returns the response wrapped in a ResponseEntity.
Fix the error in the assertion to check if the response status code is 200 OK.
assertEquals(HttpStatus.[1], response.getStatusCode());The status code HttpStatus.OK corresponds to HTTP 200, which means the request was successful.
Fill both blanks to send a POST request with a User object and receive a User response.
ResponseEntity<User> response = restTemplate.[1]("/api/users", [2], User.class);
The postForEntity method sends a POST request. The second argument is the User object to send in the request body.
Fill all three blanks to assert the response body has the expected user's email.
assertTrue(response.getBody().[1]().[2]("[3]"));
We call getEmail() on the User object, then check if it equals the expected email string.