ReportDataController { @RequestMapping(value = "/report/submit", method = RequestMethod.POST) @ResponseBody public String submit(@RequestBody ReportingData reportingData) throws ReportDataMissingException { logger.info("Reporting on: " + reportingData); if (ReportDataParameters.SERVICE_PROVIDED_DATA_TYPE.equals(reportingData.type())) { throwExceptionIfMandatoryDataIsNotPresentForServiceProvidedReport(reportingData); servicesProvidedRepository.save( reportingData.get(ReportDataParameters.ANM_IDENTIFIER), reportingData.get(ReportDataParameters.SERVICE_PROVIDER_TYPE), reportingData.get(ReportDataParameters.EXTERNAL_ID), reportingData.get(ReportDataParameters.INDICATOR), reportingData.get(ReportDataParameters.SERVICE_PROVIDED_DATE), reportingData.get(ReportDataParameters.VILLAGE), reportingData.get(ReportDataParameters.SUB_CENTER), reportingData.get(ReportDataParameters.PHC), reportingData.get(ReportDataParameters.QUANTITY), reportingData.get(ReportDataParameters.DRISTHI_ENTITY_ID)); } else if (ReportDataParameters.ANM_REPORT_DATA_TYPE.equals(reportingData.type())) { throwExceptionIfMandatoryDataIsNotPresentForANMReport(reportingData); anmReportsRepository.save( reportingData.get(ReportDataParameters.ANM_IDENTIFIER), reportingData.get(ReportDataParameters.EXTERNAL_ID), reportingData.get(ReportDataParameters.INDICATOR), reportingData.get(ReportDataParameters.SERVICE_PROVIDED_DATE), reportingData.get(ReportDataParameters.QUANTITY)); } return "Success."; } @Autowired  ReportDataController(ServicesProvidedRepository servicesProvidedRepository,
                                ANMReportsRepository anmReportsRepository); @RequestMapping(value = "/report/submit", method = RequestMethod.POST) @ResponseBody String submit(@RequestBody ReportingData reportingData); @RequestMapping(headers = {"Accept=application/json"}, value = "/report/update", method = RequestMethod.POST) @ResponseBody String updateReports(@RequestBody ReportDataUpdateRequest request); @RequestMapping(headers = {"Accept=application/json"}, value = "/report/delete", method = RequestMethod.POST) @ResponseBody String deleteReports(@RequestBody ReportDataDeleteRequest request); @RequestMapping(value = "/report/fetchForAllANMs", method = RequestMethod.GET) @ResponseBody List<ANMReport> getAllANMsIndicatorSummaries();  }
@Test public void shouldSaveServiceProvidedInDB() throws Exception { ReportingData data = serviceProvidedData("ANM X", "TC 1", BCG, "2012-01-01", new Location("bherya", "Sub Center", "PHC X"), "entity id 1").withQuantity("40"); controller.submit(data); verify(servicesProvidedRepository).save("ANM X", "ANM", "TC 1", "BCG", "2012-01-01", "bherya", "Sub Center", "PHC X", "40", "entity id 1"); }
@Test public void shouldSaveANMReportDataInDB() throws Exception { ReportingData data = anmReportData("ANM X", "EC Number 1", FP_IUD, "2012-01-01").withQuantity("40"); controller.submit(data); verify(anmReportsRepository).save("ANM X", "EC Number 1", "IUD", "2012-01-01", "40"); }
@Test(expected = ReportDataMissingException.class) public void shouldThrowExceptionWhenANMReportDataDoesNotHaveAllTheNecessaryInformation() throws Exception { ReportingData data = anmReportData(null, null, FP_CONDOM, null); controller.submit(data); }
@Test(expected = ReportDataMissingException.class) public void shouldThrowExceptionWhenServiceProvidedReportDataDoesNotHaveAllTheNecessaryInformation() throws Exception { ReportingData data = serviceProvidedData("", null, BCG, null, new Location(null, null, null), null); controller.submit(data); }