ReportDataController { @RequestMapping(headers = {"Accept=application/json"}, value = "/report/delete", method = RequestMethod.POST) @ResponseBody public String deleteReports(@RequestBody ReportDataDeleteRequest request) throws DristhiEntityIdMissingException { logger.info(MessageFormat.format("Deleting {0} reports for entity with entity id: {1}", request.type(), request.dristhiEntityId())); throwExceptionIfDristhiEntityIdIsNotPresent(request); if (ReportDataParameters.SERVICE_PROVIDED_DATA_TYPE.equals(request.type())) { servicesProvidedRepository.delete(request); } else if (ReportDataParameters.ANM_REPORT_DATA_TYPE.equals(request.type())) { anmReportsRepository.delete(request); } 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 shouldDeleteAllServiceProvidedReportsGivenAnEntityID() throws Exception { ReportDataDeleteRequest deleteRequest = new ReportDataDeleteRequest() .withType("serviceProvided") .withDristhiEntityId("entity id 1"); String result = controller.deleteReports(deleteRequest); verify(servicesProvidedRepository).delete(deleteRequest); verifyZeroInteractions(anmReportsRepository); assertEquals("Success.", result); }
@Test public void shouldDeleteAllANMReportsGivenAnEntityID() throws Exception { ReportDataDeleteRequest deleteRequest = new ReportDataDeleteRequest() .withType("anmReportData") .withDristhiEntityId("entity id 1"); String result = controller.deleteReports(deleteRequest); verify(anmReportsRepository).delete(deleteRequest); verifyZeroInteractions(servicesProvidedRepository); assertEquals("Success.", result); }
@Test(expected = DristhiEntityIdMissingException.class) public void shouldThrowExceptionWhenDristhiEntityIdIsNotPresent() throws Exception { ReportDataDeleteRequest deleteRequestWithoutDristhiEntityId = new ReportDataDeleteRequest() .withType("serviceProvided"); controller.deleteReports(deleteRequestWithoutDristhiEntityId); }