JobStatisticsAPIImpl implements JobStatisticsAPI { @Override public Collection<JobBriefInfo> getAllJobsBriefInfo() { List<String> jobNames = registryCenter.getChildrenKeys("/"); List<JobBriefInfo> result = new ArrayList<>(jobNames.size()); for (String each : jobNames) { JobNodePath jobNodePath = new JobNodePath(each); JobBriefInfo jobBriefInfo = new JobBriefInfo(); jobBriefInfo.setJobName(each); jobBriefInfo.setJobClass(registryCenter.get(jobNodePath.getConfigNodePath("jobClass"))); jobBriefInfo.setDescription(registryCenter.get(jobNodePath.getConfigNodePath("description"))); jobBriefInfo.setStatus(getJobStatus(each)); jobBriefInfo.setCron(registryCenter.get(jobNodePath.getConfigNodePath("cron"))); result.add(jobBriefInfo); } Collections.sort(result); return result; }  @Override Collection<JobBriefInfo> getAllJobsBriefInfo(); @Override Collection<ServerInfo> getServers(final String jobName); @Override Collection<ExecutionInfo> getExecutionInfo(final String jobName);  }
@Test public void assertGetAllJobsBriefInfo() { when(registryCenter.getChildrenKeys("/")).thenReturn(Arrays.asList("testJob1", "testJob2")); when(registryCenter.get("/testJob1/config/description")).thenReturn("description1"); when(registryCenter.get("/testJob2/config/description")).thenReturn("description2"); when(registryCenter.get("/testJob1/config/cron")).thenReturn("0/1 * * * * *"); when(registryCenter.get("/testJob2/config/cron")).thenReturn("0/2 * * * * *"); when(registryCenter.getChildrenKeys("/testJob1/servers")).thenReturn(Arrays.asList("ip1", "ip2")); when(registryCenter.getChildrenKeys("/testJob2/servers")).thenReturn(Arrays.asList("ip3", "ip4")); when(registryCenter.get("/testJob1/servers/ip1/status")).thenReturn("RUNNING"); when(registryCenter.get("/testJob1/servers/ip2/status")).thenReturn("READY"); when(registryCenter.isExisted("/testJob1/servers/ip2/disabled")).thenReturn(true); when(registryCenter.isExisted("/testJob2/servers/ip3/paused")).thenReturn(true); when(registryCenter.isExisted("/testJob2/servers/ip4/shutdown")).thenReturn(true); int i = 0; for (JobBriefInfo each : jobStatisticsAPI.getAllJobsBriefInfo()) { i++; assertThat(each.getJobName(), is("testJob" + i)); assertThat(each.getDescription(), is("description" + i)); switch (i) { case 1: assertThat(each.getCron(), is("0/1 * * * * *")); assertThat(each.getStatus(), is(JobBriefInfo.JobStatus.DISABLED)); break; case 2: assertThat(each.getCron(), is("0/2 * * * * *")); assertThat(each.getStatus(), is(JobBriefInfo.JobStatus.ALL_CRASHED)); break; default: fail(); } } }