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 / TestEvaluateDynamicText.java @ 46010
History | View | Annotate | Download (3.67 KB)
1 |
package org.gvsig.expresionevaluator.impl; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.net.MalformedURLException; |
5 |
import java.net.URL; |
6 |
import junit.framework.TestCase; |
7 |
import org.gvsig.expressionevaluator.SymbolTable; |
8 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
9 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
10 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
11 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
12 |
import org.gvsig.tools.ToolsLocator; |
13 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
14 |
|
15 |
public class TestEvaluateDynamicText extends TestCase { |
16 |
|
17 |
public TestEvaluateDynamicText(String testName) { |
18 |
super(testName);
|
19 |
} |
20 |
|
21 |
@Override
|
22 |
protected void setUp() throws Exception { |
23 |
super.setUp();
|
24 |
new DefaultLibrariesInitializer().fullInitialize();
|
25 |
} |
26 |
|
27 |
@Override
|
28 |
protected void tearDown() throws Exception { |
29 |
super.tearDown();
|
30 |
} |
31 |
|
32 |
// TODO add test methods here. The name must begin with 'test'. For example:
|
33 |
// public void testHello() {}
|
34 |
|
35 |
protected SymbolTable createSymbolTable() {
|
36 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
37 |
MutableSymbolTable symbolTable = manager.createSymbolTable(); |
38 |
symbolTable.setVar("precio", 200); |
39 |
symbolTable.setVar("PI", Math.PI); |
40 |
return symbolTable;
|
41 |
} |
42 |
|
43 |
public void testSimple1() { |
44 |
|
45 |
SymbolTable symbolTable = createSymbolTable(); |
46 |
String s = ExpressionUtils.evaluateDynamicText(symbolTable, "el precion es <%=precio%>"); |
47 |
|
48 |
assertEquals("el precion es 200", s);
|
49 |
} |
50 |
|
51 |
public void testSimple2() { |
52 |
String s = ExpressionUtils.evaluateDynamicText("el home es <%=HOME()%>"); |
53 |
|
54 |
assertEquals("el home es "+ToolsLocator.getFoldersManager().getHome().toString(), s);
|
55 |
} |
56 |
|
57 |
public void testSimple3() { |
58 |
String s = ExpressionUtils.evaluateDynamicText("un fichero temporal <%=UNIQUETEMPORARYFILE('nombre.txt')%>"); |
59 |
|
60 |
// El resultado viene a ser algo como:
|
61 |
// "un fichero temporal /tmp/tmp-gvsig/nombre-1-16d2f3e4f44.txt"
|
62 |
if( !s.startsWith("un fichero temporal ") || !s.contains("nombre-") || !s.endsWith(".txt") ) { |
63 |
assertTrue("Expected 'un fichero temporal *nombre-*.txt' and found '"+s+"'", false); |
64 |
} |
65 |
} |
66 |
|
67 |
public void test1() { |
68 |
|
69 |
SymbolTable symbolTable = createSymbolTable(); |
70 |
String s = ExpressionUtils.evaluateDynamicText(symbolTable, "el precion es <%=precio%> y PI*100 es <%=TOINTEGER(PI*100)%>"); |
71 |
|
72 |
assertEquals("el precion es 200 y PI*100 es 314", s);
|
73 |
} |
74 |
|
75 |
public void testFilename1() { |
76 |
File source = new File("<%=UNIQUETEMPORARYFILE('nombre.txt')%>"); |
77 |
File target = ExpressionUtils.evaluateFilename(source);
|
78 |
|
79 |
// El resultado viene a ser algo como:
|
80 |
// /tmp/tmp-gvsig/nombre-1-16d2f3e4f44.txt
|
81 |
String s = target.getAbsolutePath();
|
82 |
if( !s.contains("nombre-") || !s.endsWith(".txt") ) { |
83 |
assertTrue("Expected '*nombre-*.txt' and found '"+s+"'", false); |
84 |
} |
85 |
} |
86 |
|
87 |
public void testFilename2() { |
88 |
File source = new File("/tmp/prueba.txt"); |
89 |
File target = ExpressionUtils.evaluateFilename(source);
|
90 |
|
91 |
String s = target.getAbsolutePath();
|
92 |
assertEquals(source.getAbsolutePath(), s); |
93 |
} |
94 |
|
95 |
public void testURL() throws Exception { |
96 |
SymbolTable symbolTable = createSymbolTable(); |
97 |
|
98 |
URL source = new URL("file://tmp/gvsig/<%='nombre-'||precio||'.txt'%>"); |
99 |
URL target = ExpressionUtils.evaluateURL(symbolTable,source);
|
100 |
|
101 |
assertEquals("file://tmp/gvsig/nombre-200.txt", target.toString());
|
102 |
} |
103 |
|
104 |
} |