JobsController { @RequestMapping(value = "${edison.application.management.base-path:/internal}/jobs", method = GET, produces = "application/json") @ResponseBody public List<JobRepresentation> getJobsAsJson(@RequestParam(name = "type", required = false) String type, @RequestParam(name = "count", defaultValue = "10") int count, @RequestParam(name = "distinct", defaultValue = "true", required = false) boolean distinct, @RequestParam(name = "humanReadable", defaultValue = "false", required = false) boolean humanReadable, HttpServletRequest request) { return getJobInfos(type, count, distinct) .stream() .map((j) -> representationOf(j, getJobMeta(j.getJobType()), humanReadable, baseUriOf(request), applicationProperties.getManagement().getBasePath())) .collect(toList()); } @Autowired  JobsController(final JobService jobService,
                   final JobMetaService jobMetaService,
                   final NavBar rightNavBar,
                   final EdisonApplicationProperties applicationProperties); @RequestMapping(value = "${edison.application.management.base-path:/internal}/jobs", method = GET, produces = "text/html") ModelAndView getJobsAsHtml(@RequestParam(value = "type", required = false) String type,
                                      @RequestParam(value = "count", defaultValue = "100") int count,
                                      @RequestParam(value = "distinct", defaultValue = "true", required = false) boolean distinct,
                                      HttpServletRequest request); @RequestMapping(value = "${edison.application.management.base-path:/internal}/jobs", method = GET, produces = "application/json") @ResponseBody List<JobRepresentation> getJobsAsJson(@RequestParam(name = "type", required = false) String type,
                                                 @RequestParam(name = "count", defaultValue = "10") int count,
                                                 @RequestParam(name = "distinct", defaultValue = "true", required = false) boolean distinct,
                                                 @RequestParam(name = "humanReadable", defaultValue = "false", required = false) boolean humanReadable,
                                                 HttpServletRequest request); @RequestMapping(value = "${edison.application.management.base-path:/internal}/jobs", method = DELETE) void deleteJobs(@RequestParam(value = "type", required = false) String type); @RequestMapping( value = "${edison.application.management.base-path:/internal}/jobs/{jobType}", method = POST) void startJob(final @PathVariable String jobType,
                         final HttpServletRequest request,
                         final HttpServletResponse response); @RequestMapping( value = "${edison.application.management.base-path:/internal}/jobs/{jobType}/disable", method = POST ) String disableJobType(final @PathVariable String jobType,
                                 final @RequestParam(required = false) String disabledComment); @RequestMapping( value = "${edison.application.management.base-path:/internal}/jobs/{jobType}/enable", method = POST ) String enableJobType(final @PathVariable String jobType); @RequestMapping(value = "${edison.application.management.base-path:/internal}/jobs/{id}", method = GET, produces = "text/html") ModelAndView getJobAsHtml(final HttpServletRequest request,
                                     final HttpServletResponse response,
                                     @PathVariable("id") final String jobId); @RequestMapping(value = "${edison.application.management.base-path:/internal}/jobs/{id}", method = GET, produces = "application/json") @ResponseBody JobRepresentation getJob(final HttpServletRequest request,
                                    final HttpServletResponse response,
                                    @PathVariable("id") final String jobId,
                                    @RequestParam(name = "humanReadable", defaultValue = "false", required = false) boolean humanReadable
    );  }
@Test public void shouldReturnAllJobs() throws IOException { JobInfo firstJob = newJobInfo("42", "TEST", fixed(ofEpochMilli(0), systemDefault()), "localhost"); JobInfo secondJob = newJobInfo("42", "TEST", fixed(ofEpochMilli(1), systemDefault()), "localhost"); when(jobService.findJobs(Optional.<String>empty(), 100)).thenReturn(asList(firstJob, secondJob)); Object job = jobsController.getJobsAsJson(null, 100, false, false, mock(HttpServletRequest.class)); assertThat(job, is(asList(representationOf(firstJob, null, false, "", ""), representationOf(secondJob, null, false, "", "")))); }
@Test public void shouldNotReturnAllJobsDistinctIfTypeIsGiven() throws IOException { JobInfo firstJob = newJobInfo("11", "jobType1", fixed(ofEpochMilli(0), systemDefault()), "localhost"); JobInfo secondJob = newJobInfo("12", "jobType2", fixed(ofEpochMilli(1), systemDefault()), "localhost"); JobInfo thirdJob = newJobInfo("13", "jobType3", fixed(ofEpochMilli(2), systemDefault()), "localhost"); JobInfo fourthJob = newJobInfo("14", "jobType2", fixed(ofEpochMilli(2), systemDefault()), "localhost"); when(jobService.findJobs(Optional.of("jobType2"), 100)).thenReturn(asList(secondJob, fourthJob)); Object job = jobsController.getJobsAsJson("jobType2", 100, true, false, mock(HttpServletRequest.class)); assertThat(job, is(asList(representationOf(secondJob, null, false, "", ""), representationOf(fourthJob, null, false, "", "")))); verify(jobService, times(1)).findJobs(Optional.of("jobType2"), 100); verifyNoMoreInteractions(jobService); }
@Test public void shouldReturnAllJobsDistinct() throws IOException { JobInfo firstJob = newJobInfo("42", "jobType1", fixed(ofEpochMilli(0), systemDefault()), "localhost"); JobInfo secondJob = newJobInfo("42", "jobType2", fixed(ofEpochMilli(1), systemDefault()), "localhost"); JobInfo thirdJob = newJobInfo("42", "jobType3", fixed(ofEpochMilli(2), systemDefault()), "localhost"); when(jobService.findJobsDistinct()).thenReturn(asList(firstJob, secondJob, thirdJob)); Object job = jobsController.getJobsAsJson(null, 100, true, false, mock(HttpServletRequest.class)); assertThat(job, is(asList(representationOf(firstJob, null, false, "", ""), representationOf(secondJob, null, false, "", ""), representationOf(thirdJob, null, false, "", "")))); verify(jobService, times(1)).findJobsDistinct(); verifyNoMoreInteractions(jobService); }