svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.impl / src / test / java / org / gvsig / expresionevaluator / impl / TestScript1.java @ 44389
History | View | Annotate | Download (3.42 KB)
1 |
package org.gvsig.expresionevaluator.impl; |
---|---|
2 |
|
3 |
import java.io.InputStream; |
4 |
import junit.framework.TestCase; |
5 |
import org.apache.commons.io.IOUtils; |
6 |
import org.apache.commons.lang3.StringUtils; |
7 |
import org.gvsig.expressionevaluator.Expression; |
8 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
9 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
10 |
import org.gvsig.expressionevaluator.impl.javascripting.CosaScriptEngineFactory; |
11 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
12 |
import org.gvsig.tools.script.Script; |
13 |
|
14 |
public class TestScript1 extends TestCase { |
15 |
|
16 |
public TestScript1(String testName) { |
17 |
super(testName);
|
18 |
} |
19 |
|
20 |
@Override
|
21 |
protected void setUp() throws Exception { |
22 |
super.setUp();
|
23 |
new DefaultLibrariesInitializer().fullInitialize();
|
24 |
} |
25 |
|
26 |
@Override
|
27 |
protected void tearDown() throws Exception { |
28 |
super.tearDown();
|
29 |
} |
30 |
|
31 |
// TODO add test methods here. The name must begin with 'test'. For example:
|
32 |
// public void testHello() {}
|
33 |
public void testScript1() throws Exception { |
34 |
InputStream is = this.getClass().getResource("/org/gvsig/expressionevaluator/impl/TestScript1_1.txt").openStream(); |
35 |
String source = StringUtils.join(IOUtils.readLines(is), "\n"); |
36 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
37 |
|
38 |
Object r;
|
39 |
Script sc; |
40 |
try {
|
41 |
sc = manager.createScript("test1", source, CosaScriptEngineFactory.LANGUAGE_NAME);
|
42 |
} catch (Exception ex) { |
43 |
System.err.println(ex.getMessage());
|
44 |
throw ex;
|
45 |
} |
46 |
r = sc.invokeFunction("form_validate", new Object[]{"form"}); |
47 |
assertEquals(true, r);
|
48 |
|
49 |
r = sc.invokeFunction("form_isReadOnly", new Object[]{"form"}); |
50 |
assertEquals(false, r);
|
51 |
} |
52 |
|
53 |
public void testScript2() throws Exception { |
54 |
InputStream is = this.getClass().getResource("/org/gvsig/expressionevaluator/impl/TestScript1_2.txt").openStream(); |
55 |
String source = StringUtils.join(IOUtils.readLines(is), "\n"); |
56 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
57 |
|
58 |
Object r;
|
59 |
Script sc; |
60 |
try {
|
61 |
sc = manager.createScript("test2", source, CosaScriptEngineFactory.LANGUAGE_NAME);
|
62 |
} catch (Exception ex) { |
63 |
System.err.println(ex.getMessage());
|
64 |
throw ex;
|
65 |
} |
66 |
r = sc.invokeFunction("test1", null); |
67 |
assertEquals(" hola adios fin", r);
|
68 |
|
69 |
r = sc.invokeFunction("test2", null); |
70 |
assertEquals(" hola adios fin", r);
|
71 |
|
72 |
} |
73 |
|
74 |
public void testScript3() throws Exception { |
75 |
InputStream is = this.getClass().getResource("/org/gvsig/expressionevaluator/impl/TestScript1_2.txt").openStream(); |
76 |
String source = StringUtils.join(IOUtils.readLines(is), "\n"); |
77 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
78 |
|
79 |
Object r;
|
80 |
Script sc; |
81 |
try {
|
82 |
sc = manager.createScript("test3", source, CosaScriptEngineFactory.LANGUAGE_NAME);
|
83 |
} catch (Exception ex) { |
84 |
System.err.println(ex.getMessage());
|
85 |
throw ex;
|
86 |
} |
87 |
r = sc.invokeFunction("test3", null); |
88 |
assertEquals("Hola amigos", r);
|
89 |
|
90 |
r = sc.invokeFunction("saluda", new Object[] { "pato" }); |
91 |
assertEquals("Hola pato", r);
|
92 |
|
93 |
} |
94 |
|
95 |
} |