JobRestController extends HerdBaseController { @RequestMapping(value = "/jobs", method = RequestMethod.GET) @Secured(SecurityFunctions.FN_JOBS_GET) public JobSummaries getJobs(@RequestParam(value = "namespace", required = false) String namespace, @RequestParam(value = "jobName", required = false) String jobName, @RequestParam(value = "status", required = false) JobStatusEnum status, @RequestParam(value = "startTime", required = false) String startTime, @RequestParam(value = "endTime", required = false) String endTime) throws Exception { return jobService.getJobs(namespace, jobName, status, getDateTime(startTime), getDateTime(endTime)); }  @RequestMapping(value = "/jobs", method = RequestMethod.POST, consumes = {"application/xml", "application/json"}) @Secured(SecurityFunctions.FN_JOBS_POST) Job createJob(@RequestBody JobCreateRequest request); @RequestMapping(value = "/jobs", method = RequestMethod.GET) @Secured(SecurityFunctions.FN_JOBS_GET) JobSummaries getJobs(@RequestParam(value = "namespace", required = false) String namespace,
        @RequestParam(value = "jobName", required = false) String jobName, @RequestParam(value = "status", required = false) JobStatusEnum status,
        @RequestParam(value = "startTime", required = false) String startTime, @RequestParam(value = "endTime", required = false) String endTime); @RequestMapping(value = "/jobs/ids/{id}", method = RequestMethod.GET) @Secured(SecurityFunctions.FN_JOBS_GET_BY_ID) Job getJob(@PathVariable("id") String id, @RequestParam(value = "verbose", required = false, defaultValue = "false") Boolean verbose); @RequestMapping(value = "/jobs/signal", method = RequestMethod.POST, consumes = {"application/xml", "application/json"}) @Secured(SecurityFunctions.FN_JOBS_SIGNAL_POST) Job signalJob(@RequestBody JobSignalRequest request); @RequestMapping(value = "/jobs/ids/{id}", method = RequestMethod.PUT, consumes = {"application/xml", "application/json"}) @Secured(SecurityFunctions.FN_JOBS_PUT) Job updateJob(@PathVariable("id") String id, @RequestBody JobUpdateRequest jobUpdateRequest); @RequestMapping(value = "/jobs/ids/{id}", method = RequestMethod.DELETE) @Secured(SecurityFunctions.FN_JOBS_DELETE) Job deleteJob(@PathVariable("id") String id, @RequestBody JobDeleteRequest jobDeleteRequest);  }
@Test public void testGetJobs() throws Exception { JobSummary jobSummary = new JobSummary(); jobSummary.setId(JOB_ID); jobSummary.setNamespace(JOB_NAMESPACE); jobSummary.setJobName(JOB_NAME); JobSummaries jobSummaries = new JobSummaries(Arrays.asList(jobSummary)); when(jobService.getJobs(JOB_NAMESPACE, JOB_NAME, JobStatusEnum.RUNNING, START_TIME, END_TIME)).thenReturn(jobSummaries); JobSummaries result = jobRestController.getJobs(JOB_NAMESPACE, JOB_NAME, JobStatusEnum.RUNNING, START_TIME.toString(), END_TIME.toString()); verify(jobService).getJobs(JOB_NAMESPACE, JOB_NAME, JobStatusEnum.RUNNING, START_TIME, END_TIME); verifyNoMoreInteractionsHelper(); assertEquals(jobSummaries, result); }
@Test(expected = IllegalArgumentException.class) public void testGetJobsYearOutOfRange() throws Exception { JobSummary jobSummary = new JobSummary(); jobSummary.setId(JOB_ID); jobSummary.setNamespace(JOB_NAMESPACE); jobSummary.setJobName(JOB_NAME); JobSummaries jobSummaries = new JobSummaries(Arrays.asList(jobSummary)); when(jobService.getJobs(JOB_NAMESPACE, JOB_NAME, JobStatusEnum.RUNNING, START_TIME, END_TIME)).thenReturn(jobSummaries); jobRestController.getJobs(JOB_NAMESPACE, JOB_NAME, JobStatusEnum.RUNNING, "20190606", "20190707"); }
@Test(expected = IllegalArgumentException.class) public void testGetJobsWrongDatFormat() throws Exception { JobSummary jobSummary = new JobSummary(); jobSummary.setId(JOB_ID); jobSummary.setNamespace(JOB_NAMESPACE); jobSummary.setJobName(JOB_NAME); JobSummaries jobSummaries = new JobSummaries(Arrays.asList(jobSummary)); when(jobService.getJobs(JOB_NAMESPACE, JOB_NAME, JobStatusEnum.RUNNING, START_TIME, END_TIME)).thenReturn(jobSummaries); jobRestController.getJobs(JOB_NAMESPACE, JOB_NAME, JobStatusEnum.RUNNING, "adgwgsfg", "201907070948035049583045"); }
@Test public void testGetJobsDateIsEmpty() throws Exception { JobSummary jobSummary = new JobSummary(); jobSummary.setId(JOB_ID); jobSummary.setNamespace(JOB_NAMESPACE); jobSummary.setJobName(JOB_NAME); JobSummaries jobSummaries = new JobSummaries(Arrays.asList(jobSummary)); when(jobService.getJobs(JOB_NAMESPACE, JOB_NAME, JobStatusEnum.RUNNING, START_TIME, END_TIME)).thenReturn(jobSummaries); jobRestController.getJobs(JOB_NAMESPACE, JOB_NAME, JobStatusEnum.RUNNING, null, null); }