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 / TestExpression.java @ 44614
History | View | Annotate | Download (2.2 KB)
1 | 43983 | jjdelcerro | package org.gvsig.expresionevaluator.impl; |
---|---|---|---|
2 | |||
3 | import junit.framework.TestCase; |
||
4 | import org.gvsig.expressionevaluator.Expression; |
||
5 | 44614 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
6 | import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
||
7 | import org.gvsig.expressionevaluator.MutableSymbolTable; |
||
8 | 43983 | jjdelcerro | import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
9 | |||
10 | |||
11 | 44614 | jjdelcerro | public class TestExpression extends TestCase { |
12 | 43983 | jjdelcerro | |
13 | 44614 | jjdelcerro | public TestExpression(String testName) { |
14 | 43983 | jjdelcerro | super(testName);
|
15 | } |
||
16 | |||
17 | @Override
|
||
18 | protected void setUp() throws Exception { |
||
19 | super.setUp();
|
||
20 | new DefaultLibrariesInitializer().fullInitialize();
|
||
21 | } |
||
22 | |||
23 | @Override
|
||
24 | protected void tearDown() throws Exception { |
||
25 | super.tearDown();
|
||
26 | } |
||
27 | |||
28 | 44614 | jjdelcerro | private MutableSymbolTable createMutableSymbolTable() {
|
29 | ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
||
30 | MutableSymbolTable t = manager.createSymbolTable(); |
||
31 | return t;
|
||
32 | } |
||
33 | |||
34 | private Expression createExpression() { |
||
35 | ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
||
36 | Expression e = manager.createExpression();
|
||
37 | return e;
|
||
38 | } |
||
39 | |||
40 | |||
41 | 43983 | jjdelcerro | // TODO add test methods here. The name must begin with 'test'. For example:
|
42 | // public void testHello() {}
|
||
43 | |||
44 | |||
45 | 44614 | jjdelcerro | public void testToJSON1() { |
46 | 43983 | jjdelcerro | String source = "precio + 10"; |
47 | |||
48 | 44614 | jjdelcerro | Expression expression = createExpression();
|
49 | 43983 | jjdelcerro | expression.setPhrase(source); |
50 | |||
51 | assertEquals( |
||
52 | 43984 | jjdelcerro | "{\"phrase\":\"precio + 10\"}",
|
53 | expression.toJSON() |
||
54 | 43983 | jjdelcerro | ); |
55 | } |
||
56 | 44614 | jjdelcerro | |
57 | public void testA() { |
||
58 | |||
59 | Expression expression = createExpression();
|
||
60 | expression.setPhrase("precio * 10");
|
||
61 | |||
62 | MutableSymbolTable t1 = createMutableSymbolTable(); |
||
63 | t1.setVar("precio", 2); |
||
64 | Object v1 = expression.execute(t1);
|
||
65 | assertEquals(20, (int)v1); |
||
66 | |||
67 | t1.setVar("precio", 3); |
||
68 | v1 = expression.execute(t1); |
||
69 | assertEquals(30, (int)v1); |
||
70 | |||
71 | MutableSymbolTable t2 = createMutableSymbolTable(); |
||
72 | t2.setVar("precio", 4); |
||
73 | v1 = expression.execute(t2); |
||
74 | assertEquals(40, (int)v1); |
||
75 | |||
76 | } |
||
77 | |||
78 | 43983 | jjdelcerro | } |