ANMLocationController { @RequestMapping(method = GET, value = "/anm-villages") @ResponseBody public ResponseEntity<VillagesDTO> villagesForANM() { HttpResponse response = new HttpResponse(false, null); try { String anmIdentifier = userController.currentUser().getUsername(); response = httpAgent.get(drishtiANMVillagesURL + "?anm-id=" + anmIdentifier); VillagesDTO villagesDTOs = new Gson().fromJson(response.body(), new TypeToken<VillagesDTO>() { }.getType()); logger.info("Fetched Villages for the ANM"); return new ResponseEntity<>(villagesDTOs, HttpStatus.OK); } catch (Exception exception) { logger.error(MessageFormat.format("{0} occurred while fetching Village Details for anm. StackTrace: \n {1}", exception.getMessage(), ExceptionUtils.getFullStackTrace(exception))); logger.error(MessageFormat.format("Response with status {0} and body: {1} was obtained from {2}", response.isSuccess(), response.body(), drishtiANMVillagesURL)); } return new ResponseEntity<>(INTERNAL_SERVER_ERROR); } @Autowired  ANMLocationController(@Value("#{drishti['drishti.anm.villages.url']}") String drishtiANMVillagesURL,
                                 UserController userController,
                                 HttpAgent httpAgent); @RequestMapping(method = GET, value = "/anm-villages") @ResponseBody ResponseEntity<VillagesDTO> villagesForANM();  }
@Test public void shouldGetANCDetailsForAllANMs() throws Exception { when(httpAgent.get("http: thenReturn(new HttpResponse(true, new Gson().toJson(new VillagesDTO("district", "PHC X", "phc1", "Sub Center 1", asList("village1", "village2", "village3"))))); when(userController.currentUser()).thenReturn(user); when(user.getUsername()).thenReturn("demo1"); when(user.getRoles()).thenReturn(asList("User")); ResponseEntity<VillagesDTO> response = controller.villagesForANM(); assertEquals(new VillagesDTO("district", "PHC X", "phc1", "Sub Center 1", asList("village1", "village2", "village3")), response.getBody()); assertEquals(HttpStatus.OK, response.getStatusCode()); }