AggregateReportsService { public List<AggregatorResponseDTO> getAggregatedReports(String anmIdentifier, int month, int year) { String queryParams = URLEncodedUtils.format( asList(whereClauseParam(anmIdentifier, month, year)) , "UTF-8"); String url = MessageFormat.format("{0}?{1}", aggregatedDataSetUrl, queryParams); HttpResponse response = httpAgent.get(url); return new Gson().fromJson(response.body(), new TypeToken<List<AggregatorResponseDTO>>() { }.getType()); } protected  AggregateReportsService(); @Autowired  AggregateReportsService(@Value("#{drishti['aggregator.dataset.url']}") String aggregatorDataSetUrl,
                                   @Value("#{drishti['aggregated.dataset.url']}") String aggregatedDataSetUrl,
                                   @Value("#{drishti['number.of.reports.sent.in.a.batch']}") int numberOfReportsSentInABatch,
                                   HttpAgent httpAgent, AllTokensRepository tokenRepository,
                                   ServicesProvidedRepository servicesProvidedRepository, ReportMonth reportMonth); @Transactional("service_provided") void sendReportsToAggregator(); List<AggregatorResponseDTO> getAggregatedReports(String anmIdentifier, int month, int year);  }
@Test public void shouldCallAggregatorToGetAggregatedReports() throws Exception { when(httpAgent.get("bamboo.aggregated.url?query=%7B%22anm_identifier%22%3A+%22demo1%22%2C%22nrhm_report_year%22%3A2013%2C+%22nrhm_report_month%22%3A10%7D")) .thenReturn(new HttpResponse(true, "[{\"nrhm_report_month\": 10, \"indicator\": \"OCP\", \"nrhm_report_indicator_count\": 2, \"nrhm_report_year\": 2013, \"anm_identifier\": \"demo1\"}, {\"nrhm_report_month\": 10, \"indicator\": \"OPV_1\", \"nrhm_report_indicator_count\": 1, \"nrhm_report_year\": 2013, \"anm_identifier\": \"demo1\"}]")); List<AggregatorResponseDTO> aggregatorResponse = aggregateReportsService.getAggregatedReports("demo1", 10, 2013); assertEquals(asList(new AggregatorResponseDTO("OCP", 2), new AggregatorResponseDTO("OPV_1", 1)), aggregatorResponse); }