1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.common.util; |
17 |
|
|
18 |
|
import java.io.StringReader; |
19 |
|
import java.math.BigDecimal; |
20 |
|
import java.util.Arrays; |
21 |
|
import java.util.Calendar; |
22 |
|
import java.util.HashMap; |
23 |
|
import java.util.List; |
24 |
|
import java.util.Map; |
25 |
|
|
26 |
|
import org.apache.velocity.tools.generic.DateTool; |
27 |
|
import org.junit.Assert; |
28 |
|
import org.junit.Test; |
29 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (81) |
Complexity: 11 |
Complexity Density: 0.16 |
|
30 |
|
public class TestVelocityTemplateEngine { |
31 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
32 |
1
|
@Test... |
33 |
|
public void testEvaluateString_ContextMap() throws Exception { |
34 |
1
|
VelocityTemplateEngine templateEngine = new VelocityTemplateEngine(); |
35 |
1
|
Map<String, Object> map = new HashMap<String, Object>(); |
36 |
1
|
map.put("prop.1", "Kamal"); |
37 |
1
|
map.put("prop.2", "Larry"); |
38 |
|
|
39 |
1
|
String s = "List of Developers: $prop.1, $prop.2"; |
40 |
1
|
String eval = templateEngine.evaluate(map, s); |
41 |
|
|
42 |
1
|
Assert.assertEquals("List of Developers: $prop.1, $prop.2", eval); |
43 |
|
} |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1
PASS
|
|
45 |
1
|
@Test... |
46 |
|
public void testEvaluateString1() throws Exception { |
47 |
1
|
VelocityTemplateEngine templateEngine = new VelocityTemplateEngine(); |
48 |
1
|
Map<String, Object> map = new HashMap<String, Object>(); |
49 |
1
|
map.put("developers", "Kamal, Larry, Len, Sherman, Zdenek"); |
50 |
|
|
51 |
1
|
String s = "List of Developers: $developers"; |
52 |
1
|
String eval = templateEngine.evaluate(map, s); |
53 |
|
|
54 |
1
|
Assert.assertEquals("List of Developers: Kamal, Larry, Len, Sherman, Zdenek", eval); |
55 |
|
} |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
57 |
1
|
@Test... |
58 |
|
public void testEvaluateString2() throws Exception { |
59 |
1
|
VelocityTemplateEngine templateEngine = new VelocityTemplateEngine(); |
60 |
1
|
List<String> devList = Arrays.asList(new String[] {"Kamal", "Larry", "Len", "Sherman", "Zdenek"}); |
61 |
1
|
Map<String, Object> map = new HashMap<String, Object>(); |
62 |
1
|
map.put("developers", devList); |
63 |
|
|
64 |
1
|
String s = "List of Developers: $developers"; |
65 |
1
|
String eval = templateEngine.evaluate(map, s); |
66 |
|
|
67 |
1
|
Assert.assertEquals("List of Developers: [Kamal, Larry, Len, Sherman, Zdenek]", eval); |
68 |
|
} |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1
PASS
|
|
70 |
1
|
@Test... |
71 |
|
public void testEvaluateReader() throws Exception { |
72 |
1
|
VelocityTemplateEngine templateEngine = new VelocityTemplateEngine(); |
73 |
1
|
Map<String, Object> map = new HashMap<String, Object>(); |
74 |
1
|
map.put("developers", "Kamal, Larry, Len, Sherman, Zdenek"); |
75 |
|
|
76 |
1
|
StringReader sr = new StringReader("List of Developers: $developers"); |
77 |
1
|
String eval = templateEngine.evaluate(map, sr); |
78 |
|
|
79 |
1
|
Assert.assertEquals("List of Developers: Kamal, Larry, Len, Sherman, Zdenek", eval); |
80 |
|
} |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
82 |
1
|
@Test... |
83 |
|
public void testEvaluateNumber() throws Exception { |
84 |
1
|
VelocityTemplateEngine templateEngine = new VelocityTemplateEngine(); |
85 |
1
|
Map<String, Object> map = new HashMap<String, Object>(); |
86 |
1
|
map.put("expectedValue", new BigDecimal("100")); |
87 |
1
|
map.put("resultValue", new BigDecimal("60")); |
88 |
|
|
89 |
1
|
String s = "#set( $difference = ($expectedValue - $resultValue) )expectedValue=$expectedValue, resultValue=$resultValue, difference=$difference"; |
90 |
1
|
String eval = templateEngine.evaluate(map, s); |
91 |
|
|
92 |
1
|
Assert.assertEquals("expectedValue=100, resultValue=60, difference=40", eval); |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
95 |
1
|
@Test... |
96 |
|
public void testEvaluate_MathTool() throws Exception { |
97 |
1
|
VelocityTemplateEngine templateEngine = new VelocityTemplateEngine(); |
98 |
1
|
Map<String, Object> map = new HashMap<String, Object>(); |
99 |
1
|
map.put("expectedValue", "100"); |
100 |
1
|
map.put("resultValue", "60"); |
101 |
|
|
102 |
1
|
String s = "#set( $difference = ( $mathTool.toNumber($expectedValue) - $mathTool.toNumber($resultValue)) )expectedValue=$expectedValue, resultValue=$resultValue, difference=$difference"; |
103 |
1
|
String eval = templateEngine.evaluate(map, s); |
104 |
|
|
105 |
1
|
Assert.assertEquals("expectedValue=100, resultValue=60, difference=40", eval); |
106 |
|
} |
107 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
108 |
1
|
@Test... |
109 |
|
public void testEvaluate_DateTool() throws Exception { |
110 |
1
|
VelocityTemplateEngine templateEngine = new VelocityTemplateEngine(); |
111 |
1
|
Map<String, Object> map = new HashMap<String, Object>(); |
112 |
1
|
map.put("expectedValue", "100"); |
113 |
1
|
map.put("resultValue", "60"); |
114 |
|
|
115 |
1
|
String s = "Date created $dateTool.get('yyyy-MM-dd HH:mm z')"; |
116 |
1
|
String eval = templateEngine.evaluate(map, s); |
117 |
|
|
118 |
1
|
Assert.assertEquals("Date created " + new DateTool().get("yyyy-MM-dd HH:mm z"), eval); |
119 |
|
} |
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1
PASS
|
|
121 |
1
|
@Test... |
122 |
|
public void testEvaluate_DateComparisonTool() throws Exception { |
123 |
1
|
VelocityTemplateEngine templateEngine = new VelocityTemplateEngine(); |
124 |
1
|
Map<String, Object> map = new HashMap<String, Object>(); |
125 |
1
|
map.put("date1", Calendar.getInstance()); |
126 |
|
|
127 |
1
|
String s = "$dateComparisonTool.whenIs($date1, $date1)"; |
128 |
1
|
String eval = templateEngine.evaluate(map, s); |
129 |
|
|
130 |
1
|
Assert.assertEquals("same time", eval); |
131 |
|
} |
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1
PASS
|
|
133 |
1
|
@Test... |
134 |
|
public void testEvaluate_DateComparisonTool_NullContextMap() throws Exception { |
135 |
1
|
VelocityTemplateEngine templateEngine = new VelocityTemplateEngine(); |
136 |
|
|
137 |
1
|
String s = "$dateComparisonTool.difference($dateTool.calendar, $dateTool.calendar).hours"; |
138 |
1
|
String eval = templateEngine.evaluate(null, s); |
139 |
|
|
140 |
1
|
Assert.assertEquals("0", eval); |
141 |
|
} |
142 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1
PASS
|
|
143 |
1
|
@Test... |
144 |
|
public void testEvaluate_NumberTool() throws Exception { |
145 |
1
|
VelocityTemplateEngine templateEngine = new VelocityTemplateEngine(); |
146 |
1
|
Map<String, Object> map = new HashMap<String, Object>(); |
147 |
1
|
map.put("expectedValue", "100.12"); |
148 |
|
|
149 |
1
|
String s = "$numberTool.currency($expectedValue)"; |
150 |
1
|
String eval = templateEngine.evaluate(map, s); |
151 |
|
|
152 |
1
|
Assert.assertEquals("$100.12", eval); |
153 |
|
} |
154 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
155 |
1
|
@Test... |
156 |
|
public void testEvaluate_SortTool() throws Exception { |
157 |
1
|
VelocityTemplateEngine templateEngine = new VelocityTemplateEngine(); |
158 |
1
|
List<String> devList = Arrays.asList(new String[] {"Len", "Larry", "Kamal", "Zdenek", "Sherman"}); |
159 |
1
|
Map<String, Object> map = new HashMap<String, Object>(); |
160 |
1
|
map.put("developers", devList); |
161 |
|
|
162 |
1
|
String s = "$sortTool.sort($developers)"; |
163 |
1
|
String eval = templateEngine.evaluate(map, s); |
164 |
|
|
165 |
1
|
Assert.assertEquals("[Kamal, Larry, Len, Sherman, Zdenek]", eval); |
166 |
|
} |
167 |
|
} |