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