File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\test\src\test\java\hudson\tasks\ShellTest.java.html

1 package hudson.tasks;
2
3 import hudson.Functions;
4 import hudson.Launcher.ProcStarter;
5 import hudson.Proc;
6 import hudson.model.FreeStyleBuild;
7 import hudson.model.FreeStyleProject;
8 import org.apache.commons.io.FileUtils;
9 import org.jvnet.hudson.test.FakeLauncher;
10 import org.jvnet.hudson.test.HudsonTestCase;
11 import org.jvnet.hudson.test.PretendSlave;
12
13 import java.io.File;
14 import java.io.IOException;
15 import java.io.PrintStream;
16 import java.util.List;
17
18 /**
19 * @author Kohsuke Kawaguchi
20 */
21 public class ShellTest extends HudsonTestCase {
22 public void testBasic() throws Exception {
23 // If we're on Windows, don't bother doing this.
24 if (Functions.isWindows())
25 return;
26
27 // TODO: define a FakeLauncher implementation with easymock so that this kind of assertions can be simplified.
28 PretendSlave s = createPretendSlave(new FakeLauncher() {
29 public Proc onLaunch(ProcStarter p) throws IOException {
30 // test the command line argument.
31 List<String> cmds = p.cmds();
32 assertEquals("/bin/sh",cmds.get(0));
33 assertEquals("-xe",cmds.get(1));
34 assertTrue(new File(cmds.get(2)).exists());
35
36 // fake the execution
37 PrintStream ps = new PrintStream(p.stdout());
38 ps.println("Hudson was here");
39 ps.close();
40
41 return new FinishedProc(0);
42 }
43 });
44 FreeStyleProject p = createFreeStyleProject();
45 p.getBuildersList().add(new Shell("echo abc"));
46 p.setAssignedNode(s);
47
48 FreeStyleBuild b = assertBuildStatusSuccess(p.scheduleBuild2(0).get());
49
50 assertEquals(1,s.numLaunch);
51 assertTrue(FileUtils.readFileToString(b.getLogFile()).contains("Hudson was here"));
52 }
53 }
54