I've a service class, write in spring, with some methods. One of this acts as a resful consumer like below:
.....
HttpEntity request = new HttpEntity<>(getHeadersForRequest());
RestTemplate restTemplate = new RestTemplate();
String url = ENDPOINT_URL.concat(ENDPOINT_API1);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url)
.queryParam("param1", parameter1);
ReportModel infoModel = null;
try{
infoModel = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, request, ReportModel.class).getBody();
}catch (HttpClientErrorException | HttpServerErrorException e){
e.printStackTrace();
}
How can I write a test which mock a resttemplate?
Aucun commentaire:
Enregistrer un commentaire