ReportingEventListener { @MotechListener(subjects = ReportEvent.SUBJECT) public void submitReportingData(MotechEvent event) { String data = new Gson().toJson(event.getParameters().get("data")); HttpResponse response = httpAgent.post(url + "/" + SUBMIT_REPORT_ACTION, data, MediaType.APPLICATION_JSON_VALUE); if (!response.isSuccess()) { logger.error("Reporting data post failed. URL: " + url + "/" + SUBMIT_REPORT_ACTION + ". Data: " + data + ". Response: " + response.body()); } } @Autowired  ReportingEventListener(ANMReportingService anmReportService, HttpAgent httpAgent,
                                  @Value("#{drishti['drishti.reporting.url']}") String url); @MotechListener(subjects = ReportEvent.SUBJECT) void submitReportingData(MotechEvent event); @MotechListener(subjects = ReportUpdateEvent.SUBJECT) void updateReportingData(MotechEvent event); @MotechListener(subjects = ReportDeleteEvent.SUBJECT) void deleteReportingData(MotechEvent event); @MotechListener(subjects = SUBJECT) void fetchANMReports(MotechEvent event); static final String FETCH_REPORTS_FOR_ALL_ANMS_ACTION; static final String SUBMIT_REPORT_ACTION; static final String UPDATE_REPORT_ACTION; static final String DELETE_REPORT_ACTION; }
@Test public void shouldSubmitReportingData() throws Exception { Map<String, Object> data = new HashMap<>(); data.put("data", new ReportingData("Boo").with("abc", "def")); when(agent.post(eq("http: listener.submitReportingData(new MotechEvent("SUBJECT", data)); verify(agent).post("http: }