ANMController { @RequestMapping(method = {RequestMethod.GET, RequestMethod.OPTIONS}, value = "/anm-details") @ResponseBody public ResponseEntity<List<ANMDTO>> all(@RequestParam("anm-id") String anmIdentifier) { HttpResponse response; try { response = httpAgent.get(dristhiUserDetailsUrl + "?anm-id=" + anmIdentifier); UserDetail userDetail = new Gson().fromJson(response.body(), new TypeToken<UserDetail>() { }.getType() ); ANMDetailsFetcher anmDetailsFetcher = detailsFetcherFactory.detailsFetcher(userDetail.roles()); List<ANMDTO> anmDTOList = convertToDTO(anmDetailsFetcher.fetchDetails(anmIdentifier)); return new ResponseEntity<>(anmDTOList, allowOrigin(drishtiSiteUrl), OK); } catch (Exception e) { e.printStackTrace(); } return new ResponseEntity<>(null, allowOrigin(drishtiSiteUrl), OK); } @Autowired  ANMController(@Value("#{drishti['drishti.site.url']}") String drishtiSiteUrl,
                         @Value("#{drishti['drishti.user.details.url']}") String dristhiUserDetailsUrl,
                         ANMService anmService, HttpAgent httpAgent, DetailsFetcherFactory detailsFetcherFactory); @RequestMapping(method = {RequestMethod.GET, RequestMethod.OPTIONS}, value = "/anm-details") @ResponseBody ResponseEntity<List<ANMDTO>> all(@RequestParam("anm-id") String anmIdentifier);  }
@Test public void shouldReturnListOfANMs() throws Exception { List<String> roles = asList("ROLE_USER"); when(httpAgent.get("http: thenReturn(new HttpResponse(true, new Gson().toJson(new UserDetail("username1", roles)))); when(detailsFetcherFactory.detailsFetcher(roles)).thenReturn(anmDetailsFetcher); when(anmDetailsFetcher.fetchDetails("username1")).thenReturn(asList( new SP_ANM("username1", "user1 name", "Sub Center 1", 0), new SP_ANM("username2", "user2 name", "Sub Center 1", 0) )); when(location.district()).thenReturn("district"); when(location.phcName()).thenReturn("phc"); when(location.state()).thenReturn("state"); when(location.taluka()).thenReturn("taluka"); when(location.village()).thenReturn("village"); when(location.subCenter()).thenReturn("subcenter"); when(anmService.getLocation("username1")).thenReturn(location); when(anmService.getLocation("username2")).thenReturn(location); ResponseEntity<List<ANMDTO>> response = controller.all("username1"); LocationDTO locationDTO = new LocationDTO(location.subCenter(), location.phcName(), location.taluka(), location.district(), location.state()); assertEquals(asList(new ANMDTO("username1", "user1 name", locationDTO), new ANMDTO("username2", "user2 name", locationDTO)), response.getBody()); }