1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.exec;
19
20 import static org.junit.jupiter.api.Assertions.assertTrue;
21
22 import java.io.File;
23 import java.nio.file.Path;
24 import java.nio.file.Paths;
25 import java.util.concurrent.Executors;
26
27 import org.junit.jupiter.api.Test;
28 import org.junit.jupiter.api.condition.DisabledOnOs;
29 import org.junitpioneer.jupiter.SetSystemProperty;
30
31
32
33
34 @SetSystemProperty(key = "org.apache.commons.exec.lenient", value = "false")
35 @SetSystemProperty(key = "org.apache.commons.exec.debug", value = "true")
36 public class StandAloneTest {
37
38 @Test
39 @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS)
40 public void testDefaultExecutorBuilderFromFile() throws Exception {
41 final Path testScript = TestUtil.resolveScriptPathForOS("./src/test/scripts/standalone");
42
43 final Executor exec = DefaultExecutor.builder()
44 .setThreadFactory(Executors.defaultThreadFactory())
45 .setExecuteStreamHandler(new PumpStreamHandler())
46 .setWorkingDirectory(new File("."))
47 .get();
48
49 exec.setStreamHandler(new PumpStreamHandler());
50 final CommandLine cl = new CommandLine(testScript);
51 exec.execute(cl);
52 assertTrue(new File("./target/mybackup.gz").exists());
53 }
54
55 @Test
56 @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS)
57 public void testDefaultExecutorBuilderFromPath() throws Exception {
58 final Path testScript = TestUtil.resolveScriptPathForOS("./src/test/scripts/standalone");
59
60 final Executor exec = DefaultExecutor.builder()
61 .setThreadFactory(Executors.defaultThreadFactory())
62 .setExecuteStreamHandler(new PumpStreamHandler())
63 .setWorkingDirectory(Paths.get("."))
64 .get();
65
66 exec.setStreamHandler(new PumpStreamHandler());
67 final CommandLine cl = new CommandLine(testScript);
68 exec.execute(cl);
69 assertTrue(new File("./target/mybackup.gz").exists());
70 }
71
72 @Test
73 @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS)
74 public void testDefaultExecutorDefaultBuilder() throws Exception {
75 final Path testScript = TestUtil.resolveScriptPathForOS("./src/test/scripts/standalone");
76 final Executor exec = DefaultExecutor.builder().get();
77 exec.setStreamHandler(new PumpStreamHandler());
78 final CommandLine cl = new CommandLine(testScript);
79 exec.execute(cl);
80 assertTrue(new File("./target/mybackup.gz").exists());
81 }
82
83 @Test
84 @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS)
85 public void testDefaultExecutorFromFile() throws Exception {
86 final Path testScript = TestUtil.resolveScriptPathForOS("./src/test/scripts/standalone");
87 final Executor exec = new DefaultExecutor();
88 exec.setStreamHandler(new PumpStreamHandler());
89 final CommandLine cl = new CommandLine(testScript);
90 exec.execute(cl);
91 assertTrue(new File("./target/mybackup.gz").exists());
92 }
93
94 @Test
95 @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS)
96 public void testDefaultExecutorFromPath() throws Exception {
97 final Path testScript = TestUtil.resolveScriptPathForOS("./src/test/scripts/standalone");
98 final Executor exec = new DefaultExecutor();
99 exec.setStreamHandler(new PumpStreamHandler());
100 final CommandLine cl = new CommandLine(testScript);
101 exec.execute(cl);
102 assertTrue(new File("./target/mybackup.gz").exists());
103 }
104 }