Skip to content

Instantly share code, notes, and snippets.

@iamvickyav
Created June 18, 2020 17:03
Show Gist options
  • Select an option

  • Save iamvickyav/497c33d0dd64cf57e00ac313a39537a3 to your computer and use it in GitHub Desktop.

Select an option

Save iamvickyav/497c33d0dd64cf57e00ac313a39537a3 to your computer and use it in GitHub Desktop.
@GetMapping(value = "/mockService/{serviceName}")
ResponseEntity fetchMockValue(@PathVariable("serviceName") String serviceName) throws IOException {
LOGGER.info("fetchMockValue called for serviceName={}", serviceName);
ResponseEntity responseEntity;
File mockServiceJsonFile = getFile(serviceName);
if(mockServiceJsonFile.exists()) {
String timeoutValue = environment.getProperty(serviceName + ".delay");
String ttValue = (timeoutValue != null) ? timeoutValue : System.getenv(serviceName + ".delay");
if(ttValue != null) {
long timeout = Long.parseLong(ttValue);
try {
Thread.sleep(timeout);
} catch (InterruptedException e) {
LOGGER.error("Mock Data Sleep Interrupted");
}
}
LOGGER.info("Mock Data Exist for serviceName={}", serviceName);
JsonNode jsonNode = objectMapper.readValue(mockServiceJsonFile, JsonNode.class);
responseEntity = new ResponseEntity(jsonNode, HttpStatus.OK);
}
else {
LOGGER.info("Mock Data not available for serviceName={}", serviceName);
Map responseMap = new HashMap();
responseMap.put(MESSAGE, "Mock data not available for " + serviceName);
responseEntity = new ResponseEntity(responseMap, HttpStatus.NOT_FOUND);
}
return responseEntity;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment