1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package org.objectledge.external;
30
31 import java.io.IOException;
32
33 import org.objectledge.utils.LedgeTestCase;
34
35 /***
36 * Test for the ProcessExecutor class.
37 *
38 * @author <a href="rafal@caltha.pl">RafaĆ Krzewski</a>
39 * @version $Id: ProcessExecutorTest.java,v 1.2 2006/11/06 16:51:12 zwierzem Exp $
40 */
41 public class ProcessExecutorTest
42 extends LedgeTestCase
43 {
44 private ScriptDirectory scriptDir;
45
46 private ProcessExecutor executor;
47
48 public void setUp()
49 {
50 boolean unix = false;
51 String osName = System.getProperty("os.name");
52 if(osName.equals("Linux") || osName.equals("Mac OS X"))
53 {
54 unix = true;
55 }
56
57 scriptDir = new ScriptDirectory(getFileSystem(),
58 ScriptDirectory.DEFAULT_PROVIDER,
59 unix ? "external" : null,
60 ScriptDirectory.DEFAULT_PATH_PATTERN,
61 ScriptDirectory.DEFAULT_COMMAND);
62
63 executor = new ProcessExecutor(getLogger(), ProcessExecutor.DEFAULT_SHELL);
64
65 initLog4J("ERROR");
66 }
67
68 public void testPlainExec() throws IOException
69 {
70 ExecutionResult res = executor.exec(scriptDir.getPath("test.sh"));
71 assertEquals(0, res.getExitValue());
72 }
73
74 public void testExitValue() throws IOException
75 {
76 ExecutionResult res = executor.exec(scriptDir.getPath("exitValue.sh"));
77 assertEquals(4, res.getExitValue());
78 }
79
80 public void testInput() throws IOException
81 {
82 ExecutionResult res;
83 res = executor.exec("bad input", false, false, scriptDir.getPath("input.sh"));
84 assertEquals(1, res.getExitValue());
85 res = executor.exec("good input", false, false, scriptDir.getPath("input.sh"));
86 assertEquals(0, res.getExitValue());
87 }
88
89 public void testOuptut() throws IOException
90 {
91 ExecutionResult res;
92 res = executor.exec(true, false, scriptDir.getPath("test.sh"));
93 assertEquals("test.sh\n", res.getOutput());
94 }
95
96 public void testError() throws IOException
97 {
98 ExecutionResult res;
99 res = executor.exec(false, true, scriptDir.getPath("error.sh"));
100 assertEquals(0, res.getExitValue());
101 assertEquals("error.sh\n", res.getError());
102 }
103
104 public void testConifg()
105 throws Exception
106 {
107 checkSchema("config/org.objectledge.external.ProcessExecutor.xml",
108 "org/objectledge/external/ProcessExecutor.rng");
109 executor = new ProcessExecutor(getLogger(), getConfig(getFileSystem(),
110 "config/org.objectledge.external.ProcessExecutor.xml"));
111 }
112 }