I am doing unit test and I need to add header to my url:
@Test
public void getData() throws URISyntaxException, Exception{
RestTemplate restTemplate = new RestTemplate();
final String baseUrl = "http://localhost:8080/data?id=sampleID";
URI uri = new URI(baseUrl);
ResponseEntity<String> result = restTemplate.getForEntity(uri, String.class);
//Verify request succeed
Assert.assertEquals(200, result.getStatusCodeValue());
Assert.assertEquals(true, result.getBody().contains("sampleName"));
}
I am getting "400 null" response and I believe it's because I am missing header, I am passing header through postman and it is working fine.
How do I pass header?
UPDATE: Eamon Scullion provided link. It solved the problem.