JobsController { @RequestMapping(value = "/jobs", method = RequestMethod.GET) @ResponseBody public JobsRecords retrieveJobInfo(JobsSearchSettings jobsSearchSettings) throws SchedulerException, SQLException { List<JobBasicInfo> jobs = motechSchedulerDatabaseService.getScheduledJobsBasicInfo(jobsSearchSettings); int rowCount = jobs.size() == 0 ? 0 : motechSchedulerDatabaseService.countJobs(jobsSearchSettings); if (jobsSearchSettings.getRows() == null) { int defaultRowsNumber = 10; jobsSearchSettings.setRows(defaultRowsNumber); } if (jobsSearchSettings.getPage() == null) { int defaultPage = 1; jobsSearchSettings.setPage(defaultPage); } previousJobsRecords = new JobsRecords( jobsSearchSettings.getPage(), jobsSearchSettings.getRows(), rowCount, jobs ); return previousJobsRecords; }  @RequestMapping(value = "/jobs", method = RequestMethod.GET) @ResponseBody JobsRecords retrieveJobInfo(JobsSearchSettings jobsSearchSettings); @RequestMapping(value = "/job/details", method = RequestMethod.POST) @ResponseBody JobDetailedInfo retrieveJobDetailedInfo(@RequestBody JobBasicInfo jobInfo); @RequestMapping(value = "/job/pause", method = RequestMethod.POST) @ResponseBody JobBasicInfo pauseJob(@RequestBody JobBasicInfo jobInfo); @RequestMapping(value = "/job/resume", method = RequestMethod.POST) @ResponseBody JobBasicInfo resumeJob(@RequestBody JobBasicInfo jobInfo); @RequestMapping(value = "/job/delete", method = RequestMethod.POST) @ResponseBody void deleteJob(@RequestBody JobBasicInfo jobInfo); @RequestMapping(value = "/jobs/new", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) void createJob(@RequestBody SchedulableJob job); @RequestMapping(value = "/jobs/edit", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) void editJob(@RequestBody SchedulableJob job); @RequestMapping(value = "/job", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) @ResponseBody SchedulableJob getJob(JobBasicInfo jobInfo); @ExceptionHandler(MotechSchedulerException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseBody Message handleException(MotechSchedulerException e);  }
@Test public void shouldGetJobsRecords() throws SchedulerException, SQLException { List<JobBasicInfo> jobBasicInfos = getTestJobBasicInfos(); JobsSearchSettings jobsSearchSettings = getDefaultGridSettings(); when(motechSchedulerDatabaseService.getScheduledJobsBasicInfo(jobsSearchSettings)).thenReturn(jobBasicInfos); JobsRecords result = jobsController.retrieveJobInfo(jobsSearchSettings); assertEquals(jobBasicInfos, result.getRows()); verify(motechSchedulerDatabaseService).getScheduledJobsBasicInfo(jobsSearchSettings); }
@Test public void shouldGetAllJobsRecordsWhenNoFiltersSet() throws SchedulerException, SQLException { List<JobBasicInfo> jobBasicInfos = getTestJobBasicInfos(); JobsSearchSettings jobsSearchSettings = new JobsSearchSettings(); when(motechSchedulerDatabaseService.getScheduledJobsBasicInfo(jobsSearchSettings)).thenReturn(jobBasicInfos); JobsRecords result = jobsController.retrieveJobInfo(jobsSearchSettings); assertEquals(jobBasicInfos, result.getRows()); verify(motechSchedulerDatabaseService).getScheduledJobsBasicInfo(jobsSearchSettings); }