I have a method which returns data from a third party rest service. I don't have access to third party service from Local machine. I tried to implement MockRestServiceServer and WireMock to test the same but not successful.
Below is the code
public String callRestClient() throws IOException {
RestTemplate restTemplate = new RestTemplate();
Map<String, String> reqMap = new HashMap<String, String>();
reqMap.put(----, ----);
try {
reqMap.put(----, -----);
JSONObject reqJSON = new JSONObject(reqMap);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> entityH = new HttpEntity<String>(reqJSON.toString());
ResponseEntity<String> result = restTemplate.exchange(vaultUri, HttpMethod.POST, entityH, String.class);
JSONParser parser = new JSONParser();
JSONObject resultJsonObj;
resultJsonObj = (JSONObject) parser.parse(result.getBody());
JSONObject authObj = (JSONObject) resultJsonObj.get("auth");
String client_token = (String) authObj.get("client_token");
return client_token;
} catch (ParseException e) {
log.error(e.getMessage());
}
return null;
}
Application is being developed using spring boot. Thanks in Advance.