return null;
}
}
public void testSerializeScript() throws Exception{
/**
* project property is null
*/
final IDispatchedScript simpleCommand_invalid1 = new testScript() {
public String[] getArgs() {
return new String[]{"some","shell","command"};
}
};
{
//test invalid input: no project
try {
final Document document = JobDefinitionSerializer.serialize(simpleCommand_invalid1);
fail("should not have succeeded");
} catch (IllegalArgumentException e) {
assertNotNull(e);
assertEquals("No project is specified", e.getMessage());
}
}
/**
* Has no script/command/scriptpath
*/
final IDispatchedScript simpleCommand_invalid2 = new testScript() {
public String getFrameworkProject() {
return TEST_PROJECT;
}
public String[] getArgs() {
return new String[0];
}
};
{
//test invalid input: no command/script/scriptpath
try {
final Document document = JobDefinitionSerializer.serialize(simpleCommand_invalid2);
fail("should not have succeeded");
} catch (IllegalArgumentException e) {
assertNotNull(e);
assertEquals("Dispatched script did not specify a command, script or filepath", e.getMessage());
}
}
/**
* Basic shell command
*/
final IDispatchedScript simpleCommand1 = new testScript() {
public String getFrameworkProject() {
return TEST_PROJECT;
}
public String[] getArgs() {
return new String[]{"some","shell","command"};
}
};
{
//test basic components
final Document document = JobDefinitionSerializer.serialize(simpleCommand1);
// p(document);
assertNotNull(document);
assertEquals("incorrect root element", "joblist", document.getRootElement().getName());
final List jobs = document.selectNodes("/joblist/job");
assertNotNull("missing /joblist/job element", jobs);
assertEquals("wrong size for /joblist/job", 1, jobs.size());
assertNotNull("expected /joblist/job/name", document.selectSingleNode("/joblist/job/name"));
assertEquals("dispatch commandline job", document.selectSingleNode("/joblist/job/name").getStringValue());
assertNotNull("expected /joblist/job/description", document.selectSingleNode("/joblist/job/description"));
assertEquals("dispatch commandline job", document.selectSingleNode("/joblist/job/description").getStringValue());
assertNotNull("expected /joblist/job/loglevel", document.selectSingleNode("/joblist/job/loglevel"));
assertEquals("ERROR", document.selectSingleNode("/joblist/job/loglevel").getStringValue());
assertEquals(1, document.selectNodes("/joblist/job/context").size());
assertNotNull(document.selectSingleNode("/joblist/job/context"));
assertNotNull(document.selectSingleNode("/joblist/job/context/project"));
assertEquals(TEST_PROJECT, document.selectSingleNode("/joblist/job/context/project").getStringValue());
assertNull(document.selectSingleNode("/joblist/job/context/type"));
assertNull(document.selectSingleNode("/joblist/job/context/object"));
assertNull(document.selectSingleNode("/joblist/job/context/command"));
assertNotNull(document.selectSingleNode("/joblist/job/dispatch"));
assertNotNull(document.selectSingleNode("/joblist/job/dispatch/threadcount"));
assertEquals("1",document.selectSingleNode("/joblist/job/dispatch/threadcount").getText());
assertNotNull(document.selectSingleNode("/joblist/job/dispatch/keepgoing"));
assertEquals("false", document.selectSingleNode("/joblist/job/dispatch/keepgoing").getText());
}
/**
* Basic shell command, set threadcount=3, keepgoing=true
*/
final IDispatchedScript simpleCommand2 = new testScript() {
private NodeSet nset;
@Override
public int getNodeThreadcount() {
return 3;
}
@Override
public Boolean isKeepgoing() {
return true;
}
public String getFrameworkProject() {
return TEST_PROJECT;
}
public String[] getArgs() {
return new String[]{"some","shell","command"};
}
};
{
//test threadcount/keepgoing change
final Document document = JobDefinitionSerializer.serialize(simpleCommand2);
assertNotNull(document.selectSingleNode("/joblist/job/dispatch"));
assertNotNull(document.selectSingleNode("/joblist/job/dispatch/threadcount"));
assertEquals("3", document.selectSingleNode("/joblist/job/dispatch/threadcount").getText());
assertNotNull(document.selectSingleNode("/joblist/job/dispatch/keepgoing"));
assertEquals("true", document.selectSingleNode("/joblist/job/dispatch/keepgoing").getText());
}
{
//test simple shell command
final Document document = JobDefinitionSerializer.serialize(simpleCommand1);
// p(document);
assertNotNull(document);
assertEquals("incorrect root element", "joblist", document.getRootElement().getName());
final List jobs = document.selectNodes("/joblist/job");
assertNotNull("missing /joblist/job element", jobs);
assertEquals("wrong size for /joblist/job", 1, jobs.size());
assertNotNull(document.selectSingleNode("/joblist/job/sequence/command/exec"));
assertEquals("some shell command", document.selectSingleNode("/joblist/job/sequence/command/exec").getText());
assertNull(document.selectSingleNode("/joblist/job/sequence/command/script"));
assertNull(document.selectSingleNode("/joblist/job/sequence/command/scriptfile"));
assertNull(document.selectSingleNode("/joblist/job/sequence/command/scriptargs"));
}
{
IDispatchedScript script = new testScript() {
public String getFrameworkProject() {
return TEST_PROJECT;
}
public String getScript() {
return "#!/bin/bash\n"
+ "\n"
+ "echo this is a test\n"
+ "uptime\n";
}
public String[] getArgs() {
return new String[0];
}
};
//test simple script with no args
final Document document = JobDefinitionSerializer.serialize(script);
// p(document);
assertNotNull(document);
assertEquals("incorrect root element", "joblist", document.getRootElement().getName());
final List jobs = document.selectNodes("/joblist/job");
assertNotNull("missing /joblist/job element", jobs);
assertEquals("wrong size for /joblist/job", 1, jobs.size());
assertNull(document.selectSingleNode("/joblist/job/sequence/command/exec"));
assertNotNull(document.selectSingleNode("/joblist/job/sequence/command/script"));
assertEquals("#!/bin/bash\n"
+ "\n"
+ "echo this is a test\n"
+ "uptime\n", document.selectSingleNode("/joblist/job/sequence/command/script").getText());
assertNull(document.selectSingleNode("/joblist/job/sequence/command/scriptfile"));
assertNull(document.selectSingleNode("/joblist/job/sequence/command/scriptargs"));
}
{
IDispatchedScript script = new testScript() {
public String getFrameworkProject() {
return TEST_PROJECT;
}
public String getScript() {
return "#!/bin/bash\n"
+ "\n"
+ "echo this is a test\n"
+ "uptime\n";
}
public String[] getArgs() {
return new String[]{"this","is","args"};
}
};
//test simple script with args
final Document document = JobDefinitionSerializer.serialize(script);
// p(document);
assertNotNull(document);
assertEquals("incorrect root element", "joblist", document.getRootElement().getName());
final List jobs = document.selectNodes("/joblist/job");
assertNotNull("missing /joblist/job element", jobs);
assertEquals("wrong size for /joblist/job", 1, jobs.size());
assertNull(document.selectSingleNode("/joblist/job/sequence/command/exec"));
assertNotNull(document.selectSingleNode("/joblist/job/sequence/command/script"));
assertEquals("#!/bin/bash\n"
+ "\n"
+ "echo this is a test\n"
+ "uptime\n", document.selectSingleNode("/joblist/job/sequence/command/script").getText());
assertNull(document.selectSingleNode("/joblist/job/sequence/command/scriptfile"));
assertEquals("this is args", document.selectSingleNode("/joblist/job/sequence/command/scriptargs").getText());
}
{
IDispatchedScript script = new testScript() {
public String getFrameworkProject() {
return TEST_PROJECT;
}
public String getServerScriptFilePath() {
return "/usr/local/scripts/test1.sh";
}
public String[] getArgs() {
return new String[0];
}
};
//test simple script file with no Args
final Document document = JobDefinitionSerializer.serialize(script);
// p(document);
assertNotNull(document);
assertEquals("incorrect root element", "joblist", document.getRootElement().getName());
final List jobs = document.selectNodes("/joblist/job");
assertNotNull("missing /joblist/job element", jobs);
assertEquals("wrong size for /joblist/job", 1, jobs.size());
assertNull(document.selectSingleNode("/joblist/job/sequence/command/exec"));
assertNull(document.selectSingleNode("/joblist/job/sequence/command/script"));
assertNotNull(document.selectSingleNode("/joblist/job/sequence/command/scriptfile"));
assertEquals("/usr/local/scripts/test1.sh", document.selectSingleNode("/joblist/job/sequence/command/scriptfile").getText());
assertNull(document.selectSingleNode("/joblist/job/sequence/command/scriptargs"));
}
{
IDispatchedScript script = new testScript() {
public String getFrameworkProject() {
return TEST_PROJECT;
}