Complete the code to autowire TestRestTemplate in a Spring Boot test class.
@Autowired
private [1] restTemplate;TestRestTemplate is the correct class to autowire for integration testing in Spring Boot.
Complete the code to send a GET request to '/api/items' using TestRestTemplate.
ResponseEntity<String> response = restTemplate.[1]("/api/items");
getForEntity sends a GET request and returns a ResponseEntity.
Fix the error in the assertion to check if the response status is 200 OK.
assertEquals(HttpStatus.[1], response.getStatusCode());HttpStatus.OK represents the 200 status code for successful GET requests.
Fill both blanks to send a POST request with a JSON body and receive a response as a String.
ResponseEntity<String> response = restTemplate.[1]("/api/items", [2], String.class);
postForEntity sends a POST request. Pass the request body (newItem) directly as an object or JSON string.
Fill all three blanks to create a TestRestTemplate with basic authentication and send a GET request.
TestRestTemplate restTemplate = new TestRestTemplate().withBasicAuth("[1]", "[2]"); ResponseEntity<String> response = restTemplate.[3]("/api/secure");
Use new TestRestTemplate().withBasicAuth(username, password) for basic auth. getForEntity sends a GET request.