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 name.angoca.zemucan.executer.impl;
30
31 import name.angoca.zemucan.ParameterNullException;
32 import name.angoca.zemucan.tools.Constants;
33 import name.angoca.zemucan.tools.configurator.Configurator;
34 import name.angoca.zemucan.tools.test.RandomTestRunner;
35
36 import org.junit.After;
37 import org.junit.Assert;
38 import org.junit.Test;
39 import org.junit.runner.RunWith;
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 @RunWith(RandomTestRunner.class)
64 public final class ImplementationExecuterTest {
65
66
67
68
69 public ImplementationExecuterTest() {
70
71 }
72
73
74
75
76 @After
77 public void tearDown() {
78
79 Configurator.destroyInstance();
80
81
82 ImplementationExecuter.destroyInstance();
83 }
84
85
86
87
88
89 @Test
90 public void testDB2Native() {
91
92 System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
93 "sa_conf-test-DB2Native.xml");
94
95 final String actualString = Configurator.getInstance().getProperty(
96 ImplementationExecuter.DB2_NATIVE_PROPERTY);
97 final boolean condition = Boolean.parseBoolean(actualString);
98
99 Assert.assertTrue("Yes DB2 native", condition);
100 }
101
102
103
104
105
106
107
108 @Test
109 public void testExecutionInLinuxDB2WithoutParams()
110 throws ParameterNullException {
111
112 System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
113 "sa_conf-test-NoDB2Native.xml");
114
115
116 System.clearProperty(ImplementationExecuter.DB2_PARAMS);
117 System.setProperty("os.name", "Linux Virtual");
118
119 final String command = "db2 !ls";
120 final String[] actuals = ImplementationExecuter.getInstance()
121 .getCommandsToExecute(command);
122
123 final String[] expecteds = new String[] { "db2", "!ls" };
124
125 Assert.assertArrayEquals("DB2 commands in Linux without parameters",
126 expecteds, actuals);
127 }
128
129
130
131
132
133
134
135 @Test
136 public void testExecutionInLinuxDB2WithtParams()
137 throws ParameterNullException {
138
139 System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
140 "sa_conf-test-NoDB2Native.xml");
141
142
143 System.setProperty(ImplementationExecuter.DB2_PARAMS, "-v");
144 System.setProperty("os.name", "Linux Virtual");
145
146 final String command = "db2 !ls";
147 final String[] actuals = ImplementationExecuter.getInstance()
148 .getCommandsToExecute(command);
149
150 final String[] expecteds = new String[] { "db2", "-v", "!ls" };
151
152 Assert.assertArrayEquals("DB2 commands in Linux with parameters",
153 expecteds, actuals);
154 }
155
156
157
158
159
160
161
162 @Test
163 public void testExecutionInLinuxNoDB2() throws ParameterNullException {
164
165 System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
166 "sa_conf-test-NoDB2Native.xml");
167
168
169 System.clearProperty(ImplementationExecuter.DB2_PARAMS);
170 System.setProperty("os.name", "Linux Virtual");
171
172 final String command = "ls";
173 final String[] actuals = ImplementationExecuter.getInstance()
174 .getCommandsToExecute(command);
175
176 final String[] expecteds = new String[] { "ls" };
177
178 Assert.assertArrayEquals("No DB2 commands in Linux", expecteds,
179 actuals);
180 }
181
182
183
184
185
186
187
188 @Test
189 public void testExecutionInUnknownOS() throws ParameterNullException {
190
191 System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
192 "sa_conf-test-NoDB2Native.xml");
193
194
195 System.setProperty(ImplementationExecuter.DB2_PARAMS, "-v");
196 System.setProperty("os.name", "Unknown OS");
197
198 final String command = "db2 !dir";
199 final String[] actuals = ImplementationExecuter.getInstance()
200 .getCommandsToExecute(command);
201
202 final String[] expecteds = new String[] { "!dir" };
203
204 Assert.assertArrayEquals("DB2 commands in an unknown OS", expecteds,
205 actuals);
206 }
207
208
209
210
211
212
213
214 @Test
215 public void testExecutionInWindowsDB2WithoutParams()
216 throws ParameterNullException {
217
218 System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
219 "sa_conf-test-NoDB2Native.xml");
220
221
222 System.clearProperty(ImplementationExecuter.DB2_PARAMS);
223 final String command = "db2 !dir";
224 final String os = System.getProperty("os.name");
225
226 System.setProperty("os.name", "Windows 7");
227 final String[] actuals = ImplementationExecuter.getInstance()
228 .getCommandsToExecute(command);
229 System.setProperty("os.name", os);
230
231 final String[] expecteds = new String[] {
232 "cmd.exe", "/c", "db2", "!dir" };
233
234 Assert.assertArrayEquals("DB2 commands in Windows without parameters",
235 expecteds, actuals);
236 }
237
238
239
240
241
242
243
244 @Test
245 public void testExecutionInWindowsDB2WithParams()
246 throws ParameterNullException {
247
248 System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
249 "sa_conf-test-NoDB2Native.xml");
250
251
252 System.setProperty(ImplementationExecuter.DB2_PARAMS, "-v");
253 final String command = "db2 !dir";
254 final String os = System.getProperty("os.name");
255
256 System.setProperty("os.name", "Windows 7");
257 final String[] actuals = ImplementationExecuter.getInstance()
258 .getCommandsToExecute(command);
259 System.setProperty("os.name", os);
260
261 final String[] expecteds = new String[] { "cmd.exe", "/c", "db2", "-v",
262 "!dir" };
263
264 Assert.assertArrayEquals("DB2 commands in Windows with parameters",
265 expecteds, actuals);
266 }
267
268
269
270
271
272
273
274 @Test
275 public void testExecutionInWindowsNoDB2() throws ParameterNullException {
276
277 System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
278 "sa_conf-test-NoDB2Native.xml");
279
280
281 System.clearProperty(ImplementationExecuter.DB2_PARAMS);
282 final String command = "dir";
283 final String os = System.getProperty("os.name");
284
285 System.setProperty("os.name", "Windows 7");
286 final String[] actuals = ImplementationExecuter.getInstance()
287 .getCommandsToExecute(command);
288 System.setProperty("os.name", os);
289
290 final String[] expecteds = new String[] { "cmd.exe", "/c", "dir" };
291
292 Assert.assertArrayEquals("No DB2 commands in Windows", expecteds,
293 actuals);
294 }
295
296
297
298
299
300
301
302 @Test
303 public void testExecutionWithDB2Params() throws ParameterNullException {
304
305 System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
306 "sa_conf-test-DB2Native.xml");
307
308
309 System.setProperty(ImplementationExecuter.DB2_PARAMS, "-v");
310
311 final String command = "db2 !dir";
312 final String[] actuals = ImplementationExecuter.getInstance()
313 .getCommandsToExecute(command);
314
315 final String[] expecteds = new String[] { "db2", "-v", "!dir" };
316
317 Assert.assertArrayEquals("DB2 commands with parameters", expecteds,
318 actuals);
319 }
320
321
322
323
324
325
326
327 @Test
328 public void testExecutionWithNoDB2Params() throws ParameterNullException {
329
330 System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
331 "sa_conf-test-DB2Native.xml");
332
333
334 System.clearProperty(ImplementationExecuter.DB2_PARAMS);
335
336 final String command = "db2 !dir";
337 final String[] actuals = ImplementationExecuter.getInstance()
338 .getCommandsToExecute(command);
339
340 final String[] expecteds = new String[] { "db2", "!dir" };
341
342 Assert.assertArrayEquals("DB2 commands without parameters", expecteds,
343 actuals);
344 }
345
346
347
348
349
350
351
352 @Test
353 public void testExecutionWithNullParam() throws ParameterNullException {
354 final String command = null;
355
356 try {
357 ImplementationExecuter.getInstance().getCommandsToExecute(command);
358 } catch (final Exception exception) {
359 Assert.assertTrue("ParameterNullException",
360 exception instanceof ParameterNullException);
361 }
362 }
363
364
365
366
367 @Test
368 public void testExitEmpty() {
369
370 System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
371 "sa_conf-test-exitEmpty.xml");
372
373 final String actual = ImplementationExecuter.getInstance().getTokens();
374
375 final String expected = ImplementationExecuter.EXIT_VALUE;
376
377 Assert.assertEquals("Tokens to finish the application", expected,
378 actual);
379 }
380
381
382
383
384
385 @Test
386 public void testNoDB2Native() {
387
388 System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
389 "sa_conf-test-NoDB2Native.xml");
390
391 final String actualString = Configurator.getInstance().getProperty(
392 ImplementationExecuter.DB2_NATIVE_PROPERTY);
393 final boolean condition = Boolean.parseBoolean(actualString);
394
395 Assert.assertFalse("No DB2 native", condition);
396 }
397 }