ChronosController { @RequestMapping(value="/job/{id}", method=RequestMethod.GET) public @ResponseBody JobSpec getJob(@PathVariable("id") Long id) throws NotFoundException { JobSpec aJob = jobDao.getJob(id); if (aJob == null) { throw new NotFoundException( String.format("Job with id \"%d\" was not found", id)); } return aJob; } @Autowired  ChronosController(JobDao jobDao, AgentDriver agentDriver, AgentConsumer agentConsumer,
                           ArrayList<SupportedDriver> drivers, String reportRootPath); @ExceptionHandler(Exception.class) @ResponseBody Response internalExceptionHandler(Exception  exception,
    HttpServletRequest request, HttpServletResponse response); @RequestMapping(value="/jobs", method=RequestMethod.GET) @ResponseBody List<JobSpec> getJobs(); @RequestMapping(value="/jobs/history", method=RequestMethod.GET) @ResponseBody List<CallableJob> history(@RequestParam(value="id", required=false) Long id,
          @RequestParam(value="limit", required=true, defaultValue="100") Integer limit); @RequestMapping(value="/jobs/future", method=RequestMethod.GET) @ResponseBody List<FutureRunInfo> future(@RequestParam(value="id", required=false) Long id,
         @RequestParam(value="limit", required=true, defaultValue="100") Integer limit); static DateTime calcNextRunTime(final DateTime from, JobSpec job); void innerJobFuture(List<FutureRunInfo> toRet,
                             DateTime from, List<JobSpec> iterJobs); List<FutureRunInfo> getJobFuture(Long id, int limit); @RequestMapping(value="/job/{id}", method=RequestMethod.GET) @ResponseBody JobSpec getJob(@PathVariable("id") Long id); @RequestMapping(value="/job/{id}/children", method=RequestMethod.GET) @ResponseBody List<JobSpec> getChildren(@PathVariable("id") Long id); @RequestMapping(value="/job/{id}/tree", method=RequestMethod.GET) @ResponseBody JobNode getTree(@PathVariable("id") Long id); @RequestMapping(value="/job/version/{id}", method=RequestMethod.GET) @ResponseBody List<JobSpec> getJobVersions(@PathVariable("id") Long id); @RequestMapping(value="/sources", method=RequestMethod.GET) @ResponseBody ArrayList<SupportedDriver> getDataSources(); static Map<String, Long> assembleIdResp(long id); @RequestMapping(value="/job", method=RequestMethod.POST) @ResponseBody Map<String, Long> createJob(@RequestBody final JobSpec aJob); @RequestMapping(value="/job/{id}", method=RequestMethod.PUT) @ResponseBody Response updateJob(@PathVariable("id") Long id,
      @RequestBody final JobSpec aJob); @RequestMapping(value="/job/{id}", method=RequestMethod.DELETE) @ResponseBody Response deleteJob(@PathVariable("id") Long id); @ResponseBody List<Map<String,String>> getJobResults(
      @RequestParam("id") Long id,
      @RequestParam("limit") int limit); @RequestMapping(value="/running", method=RequestMethod.GET) @ResponseBody List<PlannedJob> getRunning(
      @RequestParam(value="id", required=false) Long id); @RequestMapping(value="/queue", method=RequestMethod.GET) @ResponseBody List<PlannedJob> getQueue(
      @RequestParam(value="id", required=false) Long id); @RequestMapping(value="/queue", method=RequestMethod.POST) @ResponseBody Response queueJob(@RequestBody final PlannedJob aJob); @RequestMapping(value="/queue", method=RequestMethod.DELETE) @ResponseBody Response cancelJob(@RequestBody final PlannedJob aJob); List<String> getReportsList(String root, Long id); @RequestMapping(value="/report-list", method=RequestMethod.GET) @ResponseBody List<String> getReportsList(
    @RequestParam(value="id", required=false) Long id); static Logger LOG; }
@Test public void testGetQueueRunning() throws Exception { List<PlannedJob> twoJobs = new ArrayList<>(); Map<Long, CallableJob> runs = new ConcurrentSkipListMap<>(); Mockito.reset(agentConsumer); for (int i = 0; i < 2; i++) { JobSpec aJob = getTestJob("bleep bloop"); aJob.setName("job" + i); PlannedJob plannedJob = new PlannedJob(aJob, new DateTime()); twoJobs.add(plannedJob); when(jobDao.getJob(i)).thenReturn(aJob); CallableQuery cq = new CallableQuery(plannedJob, jobDao, reporting, null, null, null, null, null, 1); runs.put(new Long(i), cq); } when(jobDao.getJobRuns(null, AgentConsumer.LIMIT_JOB_RUNS)).thenReturn(runs); mockMvc.perform(get("/api/running")) .andExpect(status().isOk()) .andExpect(content().string(OM.writeValueAsString(twoJobs))); }
@Test public void testJobHistory() throws Exception { JobSpec aJob = getTestJob("4 8 15 16 23 42"); when(jobDao.getJob(aJob.getId())).thenReturn(aJob); PlannedJob plannedJob = new PlannedJob(aJob, new DateTime()); CallableQuery cq = new CallableQuery(plannedJob, jobDao, reporting, null, null, null, null, null, 1); Map<Long, CallableJob> runs = new ConcurrentSkipListMap<>(); runs.put(new Long(1), cq); when(jobDao.getJobRuns(aJob.getId(), AgentConsumer.LIMIT_JOB_RUNS)).thenReturn(runs); when(jobDao.getJobRuns(null, AgentConsumer.LIMIT_JOB_RUNS)).thenReturn(runs); List<CallableQuery> expected = new ArrayList<>(); expected.add(cq); MockHttpServletRequestBuilder request = get(String.format("/api/jobs/history?id=%s", aJob.getId())); mockMvc.perform(request) .andExpect(content().string(OM.writeValueAsString(expected))) .andExpect(status().isOk()); request = get("/api/jobs/history"); mockMvc.perform(request) .andExpect(content().string(OM.writeValueAsString(expected))) .andExpect(status().isOk()); Long anId = 4815162342L; expected.clear(); request = get(String.format("/api/jobs/history?id=%s", anId)); mockMvc.perform(request) .andExpect(content().string(OM.writeValueAsString(expected))) .andExpect(status().isOk()); when(jobDao.getJobRuns(aJob.getId(), 1)).thenReturn(runs); expected.add(cq); request = get(String.format("/api/jobs/history?id=%s&limit=1", aJob.getId())); mockMvc.perform(request) .andExpect(content().string(OM.writeValueAsString(expected))) .andExpect(status().isOk()); verify(jobDao, times(1)).getJobRuns(aJob.getId(), AgentConsumer.LIMIT_JOB_RUNS); verify(jobDao, times(1)).getJobRuns(anId, AgentConsumer.LIMIT_JOB_RUNS); verify(jobDao, times(1)).getJobRuns(null, AgentConsumer.LIMIT_JOB_RUNS); verify(jobDao, times(1)).getJobRuns(aJob.getId(), 1); }
@Test public void testGetJob() throws Exception { JobSpec aJob = getTestJob("Some job"); when(jobDao.getJob(aJob.getId())).thenReturn(aJob); mockMvc.perform(get(String.format("/api/job/%s", aJob.getId()))) .andExpect(status().isOk()) .andExpect(content().string(OM.writeValueAsString(aJob))); verify(jobDao, times(1)).getJob(aJob.getId()); }
@Test public void testGetJobByNameNotFound() throws Exception { JobSpec aJob = getTestJob("Some job"); when(jobDao.getJob(aJob.getId())).thenReturn(null); mockMvc.perform(get(String.format("/api/job/%s", aJob.getId()))) .andExpect(status().isNotFound()) .andExpect(content().string( String.format("{\"response\":\"Job with id \\\"%d\\\" was not found\"}", aJob.getId()))); verify(jobDao, times(1)).getJob(aJob.getId()); }