ANMDetailsController { @RequestMapping(method = GET, value = "/anms") @ResponseBody public ResponseEntity<ANMDetailsDTO> allANMs() { HttpResponse response = new HttpResponse(false, null); try { String anmIdentifier = userController.currentUser().getUsername(); response = httpAgent.get(drishtiANMDetailsUrl + "?anm-id=" + anmIdentifier); List<ANMDTO> anmBasicDetails = new Gson().fromJson(response.body(), new TypeToken<List<ANMDTO>>() { }.getType()); ANMDetails anmDetails = anmDetailsService.anmDetails(anmBasicDetails); logger.info("Fetched ANM details with beneficiary count."); return new ResponseEntity<>(mapToDTO(anmDetails), allowOrigin(drishtiSiteUrl), HttpStatus.OK); } catch (Exception exception) { logger.error(MessageFormat.format("{0} occurred while fetching ANM Details. 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(), drishtiANMDetailsUrl)); } return new ResponseEntity<>(INTERNAL_SERVER_ERROR); } @Autowired  ANMDetailsController(ANMDetailsService anmDetailsService,
                                @Value("#{drishti['drishti.site.url']}") String drishtiSiteUrl,
                                @Value("#{drishti['drishti.anm.details.url']}") String drishtiANMDetailsUrl,
                                UserController userController, HttpAgent httpAgent); @RequestMapping(method = GET, value = "/anms") @ResponseBody ResponseEntity<ANMDetailsDTO> allANMs();  }
@Test public void shouldGetANCDetailsForAllANMs() throws Exception { when(httpAgent.get("http: thenReturn(new HttpResponse(true, "[\n" + " {\n" + " \"identifier\": \"bhe1\",\n" + " \"name\": \"Elizebeth D'souza\",\n" + " \"location\": {\n" + " \"sub_center\": \"bherya_a\",\n" + " \"phc\": \"Bherya\",\n" + " \"taluka\": \"K.R. Nagar\",\n" + " \"district\": \"Mysore\",\n" + " \"state\": \"Karnataka\"\n" + " }\n" + " }\n" + "]")); ANMDetails expectedANMDetails = new ANMDetails(asList(new ANMDetail("bhe1", "Elizebeth D'souza", new LocationDTO("bherya_a", "Bherya", "K.R. Nagar", "Mysore", "Karnataka"), 1, 2, 3, 4, 5))); DrishtiUser drishtiUser = new DrishtiUser("bhe1", "1", "salt", asList(""), true); when(userController.currentUser()).thenReturn(drishtiUser); when(service.anmDetails(asList(new ANMDTO("bhe1", "Elizebeth D'souza", new LocationDTO("bherya_a", "Bherya", "K.R. Nagar", "Mysore", "Karnataka"))))) .thenReturn(expectedANMDetails); ResponseEntity<ANMDetailsDTO> response = controller.allANMs(); assertEquals(new ANMDetailsDTO(asList(new ANMDetailDTO("bhe1", "Elizebeth D'souza", new LocationDTO("bherya_a", "Bherya", "K.R. Nagar", "Mysore", "Karnataka"), 1, 2, 3, 4, 5))), response.getBody()); assertEquals(HttpStatus.OK, response.getStatusCode()); assertTrue(response.getHeaders().containsKey("Access-Control-Allow-Origin")); assertEquals("http: }