1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package ch.elca.el4j.tests.services.debug;
18
19 import static org.junit.Assert.assertEquals;
20
21 import java.util.Properties;
22
23 import org.junit.Test;
24 import org.springframework.context.ApplicationContext;
25 import org.springframework.context.support.FileSystemXmlApplicationContext;
26
27 import ch.elca.el4j.services.debug.BshCommandLineLauncher;
28 import ch.elca.el4j.services.debug.ResultHolder;
29 import ch.elca.el4j.services.debug.ShellExecutor;
30 import ch.elca.el4j.services.debug.ShellExecutorImpl;
31 import ch.elca.el4j.util.codingsupport.annotations.FindBugsSuppressWarnings;
32
33
34
35
36 public class ShellExecutorTest {
37
38 @Test
39 public void testSimpleEval () {
40 ShellExecutor se = new ShellExecutorImpl();
41
42 se.eval("bsh.show=true;");
43 Object result = se.eval("System.out.println(\"hello world\"); ii=10;");
44 System.out.println("result:"+result);
45 }
46
47 @Test
48 public void testBshCommandLauncher() {
49 Properties bkup = System.getProperties();
50
51 System.setProperty(BshCommandLineLauncher.BSH_LAUNCH_STRING, "uu=123;");
52 ApplicationContext ac = new FileSystemXmlApplicationContext("classpath*:mandatory/debugStartBshLauncher.xml");
53
54 BshCommandLineLauncher b = (BshCommandLineLauncher) ac.getBean("bshLauncher");
55 ResultHolder result = b.getShellExecutor().eval("i=uu;");
56 assertEquals(123, ((Number) result.getReturnValue()).longValue());
57
58 System.setProperties(bkup);
59 }
60
61 @Test
62 @FindBugsSuppressWarnings(value = "DLS_DEAD_LOCAL_STORE",
63 justification = "Test method doesn't care for values that are never read")
64 public void testBshCommandLauncher2() {
65 Properties bkup = System.getProperties();
66
67 System.setProperty(BshCommandLineLauncher.BSH_LAUNCH_STRING, "aa=2;");
68 ApplicationContext ac = new FileSystemXmlApplicationContext ("classpath*:mandatory/debugStartBshLauncher.xml");
69
70 BshCommandLineLauncher b = (BshCommandLineLauncher) ac.getBean("bshLauncher");
71 b.addScriptletClasspath("/test_scriptlets");
72 ResultHolder result = b.getShellExecutor().eval("debug(); el4j_test(); threadInfo();");
73 result = b.getShellExecutor().eval("i=aa;");
74 assertEquals(3, ((Number)result.getReturnValue()).longValue());
75
76 System.setProperties(bkup);
77 }
78
79 }