return purgeJobsResult;
}
}
public void testRun() throws Exception {
final Framework framework = getFrameworkInstance();
{
//test list action
//test null result
final JobsTool tool = new JobsTool(framework);
final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
framework.setCentralDispatcherMgr(centralDispatcher1);
try {
tool.run(new String[]{"list","-p","test"});
fail("run should fail");
} catch (JobsToolException e) {
assertTrue(e.getMessage().startsWith("List request returned null"));
}
}
{
//test list action missing -p flag
//test 0 items result
final JobsTool tool = new JobsTool(framework);
final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
framework.setCentralDispatcherMgr(centralDispatcher1);
final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
centralDispatcher1.listJobsResult = jobs;
try {
tool.run(new String[]{"list"});
fail("run should fail");
} catch (CLIToolOptionsException e) {
assertTrue(e.getMessage().startsWith("list action: -p/--project option is required"));
}
}
{
//test list action
//test 0 items result
final JobsTool tool = new JobsTool(framework);
final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
framework.setCentralDispatcherMgr(centralDispatcher1);
final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
centralDispatcher1.listJobsResult = jobs;
tool.run(new String[]{"list", "-p", "test"});
assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
assertNotNull(centralDispatcher1.listStoredJobsQuery);
assertNull(centralDispatcher1.listStoredJobsOutput);
assertEquals(JobDefinitionFileFormat.xml,centralDispatcher1.listFormat);
}
{
//test list action with output file
//test 0 items result
final JobsTool tool = new JobsTool(framework);
final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
framework.setCentralDispatcherMgr(centralDispatcher1);
File t = File.createTempFile("TestJobsTool", "xml");
t.deleteOnExit();
final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
centralDispatcher1.listJobsResult = jobs;
tool.run(new String[]{"list", "-f", t.getAbsolutePath(), "-p", "test"});
assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
assertNotNull(centralDispatcher1.listStoredJobsQuery);
assertNotNull(centralDispatcher1.listStoredJobsOutput);
assertEquals(JobDefinitionFileFormat.xml, centralDispatcher1.listFormat);
}
{
//test list action with output file, yaml format
//test 0 items result
final JobsTool tool = new JobsTool(framework);
final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
framework.setCentralDispatcherMgr(centralDispatcher1);
File t = File.createTempFile("TestJobsTool", "xml");
t.deleteOnExit();
final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
centralDispatcher1.listJobsResult = jobs;
tool.run(new String[]{"list", "-f", t.getAbsolutePath(), "-" + JobsTool.FORMAT_OPTION,
JobDefinitionFileFormat.yaml.getName(), "-p", "test"});
assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
assertNotNull(centralDispatcher1.listStoredJobsQuery);
assertNotNull(centralDispatcher1.listStoredJobsOutput);
assertEquals(JobDefinitionFileFormat.yaml, centralDispatcher1.listFormat);
}
{
//test list action with query params, -n
final JobsTool tool = new JobsTool(framework);
final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
framework.setCentralDispatcherMgr(centralDispatcher1);
final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
centralDispatcher1.listJobsResult = jobs;
tool.run(new String[]{"list", "-" + JobsTool.NAME_OPTION, "name1", "-p", "test"});
assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
assertNull(centralDispatcher1.listStoredJobsOutput);
assertNotNull(centralDispatcher1.listStoredJobsQuery);
assertEquals("name1", centralDispatcher1.listStoredJobsQuery.getNameMatch());
assertEquals(JobDefinitionFileFormat.xml, centralDispatcher1.listFormat);
}
{
//test list action with query params, --name
final JobsTool tool = new JobsTool(framework);
final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
framework.setCentralDispatcherMgr(centralDispatcher1);
final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
centralDispatcher1.listJobsResult = jobs;
tool.run(new String[]{"list", "--" + JobsTool.NAME_OPTION_LONG, "name1", "-p", "test"});
assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
assertNull(centralDispatcher1.listStoredJobsOutput);
assertNotNull(centralDispatcher1.listStoredJobsQuery);
assertEquals("name1", centralDispatcher1.listStoredJobsQuery.getNameMatch());
assertEquals(JobDefinitionFileFormat.xml, centralDispatcher1.listFormat);
}
{
//test list action with query params, -g
final JobsTool tool = new JobsTool(framework);
final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
framework.setCentralDispatcherMgr(centralDispatcher1);
final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
centralDispatcher1.listJobsResult = jobs;
tool.run(new String[]{"list", "-" + JobsTool.GROUP_OPTION, "group1", "-p", "test"});
assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
assertNull(centralDispatcher1.listStoredJobsOutput);
assertNotNull(centralDispatcher1.listStoredJobsQuery);
assertEquals("group1", centralDispatcher1.listStoredJobsQuery.getGroupMatch());
assertEquals(JobDefinitionFileFormat.xml, centralDispatcher1.listFormat);
}
{
//test list action with query params, --group
final JobsTool tool = new JobsTool(framework);
final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
framework.setCentralDispatcherMgr(centralDispatcher1);
final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
centralDispatcher1.listJobsResult = jobs;
tool.run(new String[]{"list", "--" + JobsTool.GROUP_OPTION_LONG, "group2", "-p", "test"});
assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
assertNull(centralDispatcher1.listStoredJobsOutput);
assertNotNull(centralDispatcher1.listStoredJobsQuery);
assertEquals("group2", centralDispatcher1.listStoredJobsQuery.getGroupMatch());
assertEquals(JobDefinitionFileFormat.xml, centralDispatcher1.listFormat);
}
{
//test list action with query params, -i
final JobsTool tool = new JobsTool(framework);
final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
framework.setCentralDispatcherMgr(centralDispatcher1);
final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
centralDispatcher1.listJobsResult = jobs;
tool.run(
new String[]{"list", "-" + JobsTool.IDLIST_OPTION, "1,2", "-p", "test"});
assertTrue("list action was not called", centralDispatcher1.listStoredJobsCalled);
assertFalse("load action should not be called", centralDispatcher1.loadJobsCalled);
assertNull(centralDispatcher1.listStoredJobsOutput);
assertNotNull(centralDispatcher1.listStoredJobsQuery);
assertEquals("1,2", centralDispatcher1.listStoredJobsQuery.getIdlist());
assertEquals(JobDefinitionFileFormat.xml, centralDispatcher1.listFormat);
}
{
//test list action with query params, --idlist
final JobsTool tool = new JobsTool(framework);
final testCentralDispatcher1 centralDispatcher1 = new testCentralDispatcher1();
framework.setCentralDispatcherMgr(centralDispatcher1);
final ArrayList<IStoredJob> jobs = new ArrayList<IStoredJob>();
centralDispatcher1.listJobsResult = jobs;
tool.run(