I am using restTemplate within a @services in spring boot. That service is making a rest call to an external api's. But during testing can I mock a restTemplate so that instead of calling a external api's it will return a certain file from the resources directory.
This is so far I am using, but not working..
byte[] responseBody = readAllBytes(get("src", "test", "resources", "templates", "content", "xxx.txt"));
Mockito.doReturn(ResponseEntity.ok(new String(responseBody, StandardCharsets.UTF_8)))
.when(restTemplate).exchange("https://xxxxxxx.xxxx",
HttpMethod.GET,
entity,
String.class);
Thank you..
Aucun commentaire:
Enregistrer un commentaire