}
public void testExecute() throws Exception {
Project project = new Project();
ProcessTester server = new ProcessTester();
XhJavaBgTask task = new XhJavaBgTask();
task.setProject(project);
task.setClassname(ProcessTester.class.getName());
task.setClasspath(new Path(project, getClassPath()));
task.createArg().setLine("-p " + server.getPort());
task.createArg().setLine("-s user.dir");
task.createArg().setLine("-t 60");
task.setProcessName(PROC_NAME);
try {
ProcessRegistry.getProcess(PROC_NAME);
fail("Expected BuildException");
} catch (BuildException be) {
assertEquals("Wrong message",
"Process " + PROC_NAME + " not registered.",
be.getMessage());
}
task.execute();
assertEquals("Process not registered", task, ProcessRegistry.getProcess(PROC_NAME));
assertTrue("Process is not running", task.isRunning());
assertTrue("Process is not running", server.passed());
assertEqualsIgnoreCase("Wrong user dir",
System.getProperty("user.dir"),
server.getReceivedData());
server.getSocket().close();
// wait 500ms for process to terminate
Thread.sleep(500);
assertTrue("Process is still running", !task.isRunning());
try {
ProcessRegistry.getProcess(PROC_NAME);