JobDefinitionsController { @RequestMapping(value = "${edison.application.management.base-path:/internal}/jobdefinitions/{jobType}", method = GET, produces = "application/json") @ResponseBody public JobDefinitionRepresentation getJobDefinition(final @PathVariable String jobType, final HttpServletRequest request, final HttpServletResponse response) throws IOException { Optional<JobDefinition> jobDefinition = jobDefinitionService.getJobDefinition(jobType); if (jobDefinition.isPresent()) { return representationOf(jobDefinition.get(), baseUriOf(request), applicationProperties.getManagement().getBasePath()); } else { response.sendError(SC_NOT_FOUND, "Job not found"); return null; } } @Autowired  JobDefinitionsController(final JobDefinitionService definitionService,
                                    final JobMetaService jobMetaService,
                                    final NavBar rightNavBar,
                                    final EdisonApplicationProperties applicationProperties); @RequestMapping(value = "${edison.application.management.base-path:/internal}/jobdefinitions", method = GET, produces = "application/json") @ResponseBody Map<String, List<Link>> getJobDefinitionsAsJson(final HttpServletRequest request); @RequestMapping(value = "${edison.application.management.base-path:/internal}/jobdefinitions", method = GET, produces = "*/*") ModelAndView getJobDefinitionsAsHtml(final HttpServletRequest request); @RequestMapping(value = "${edison.application.management.base-path:/internal}/jobdefinitions/{jobType}", method = GET, produces = "application/json") @ResponseBody JobDefinitionRepresentation getJobDefinition(final @PathVariable String jobType,
                                                        final HttpServletRequest request,
                                                        final HttpServletResponse response); @RequestMapping(value = "${edison.application.management.base-path:/internal}/jobdefinitions/{jobType}", method = GET, produces = "*/*") ModelAndView getJobDefinitionAsHtml(final @PathVariable String jobType,
                                               final HttpServletRequest request,
                                               final HttpServletResponse response);  }
@Test public void shouldReturn404IfJobDefinitionIsUnknown() throws Exception { when(jobDefinitionService.getJobDefinition("FooJob")).thenReturn(Optional.empty()); mockMvc.perform(get(MANAGEMENT_CONTEXT + "/jobdefinitions/FooJob")) .andExpect(status().is(404)); }
@Test public void shouldReturnJobDefinitionIfJobExists() throws Exception { final String jobType = "FooJob"; final JobDefinition expectedDef = jobDefinition(jobType, "Foo"); when(jobDefinitionService.getJobDefinition(jobType)).thenReturn(Optional.of(expectedDef)); mockMvc.perform( get(MANAGEMENT_CONTEXT + "/jobdefinitions/FooJob") .accept("application/json") ) .andExpect(status().is(200)) .andExpect(content().json("{\n" + " \"type\": \"FooJob\",\n" + " \"name\": \"Foo\",\n" + " \"retries\": 0,\n" + " \"fixedDelay\": 3600,\n" + " \"links\": [\n" + " {\n" + " \"href\": \"" + MANAGEMENT_CONTEXT + "/jobsdefinitions/FooJob\",\n" + " \"rel\": \"self\"\n" + " },\n" + " {\n" + " \"href\": \"" + MANAGEMENT_CONTEXT + "/jobdefinitions\",\n" + " \"rel\": \"collection\"\n" + " },\n" + " {\n" + " \"href\": \"" + MANAGEMENT_CONTEXT + "/jobs/FooJob\",\n" + " \"rel\": \"http: " }\n" + " ]\n" + "}")); }