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