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