1
1
/*
2
- * Copyright 2002-2011 the original author or authors.
2
+ * Copyright 2002-2012 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .web .util ;
18
18
19
+ import javax .servlet .ServletContext ;
19
20
import javax .servlet .jsp .JspException ;
20
21
import javax .servlet .jsp .PageContext ;
21
22
import javax .servlet .jsp .el .ELException ;
33
34
import static org .junit .Assert .*;
34
35
35
36
/**
36
- * @author Aled Arendsen
37
+ * @author Alef Arendsen
37
38
* @author Juergen Hoeller
38
39
* @since 16.09.2003
39
40
*/
@@ -43,9 +44,9 @@ public class ExpressionEvaluationUtilsTests {
43
44
public void testIsSpringJspExpressionSupportActive () {
44
45
MockServletContext sc = new MockServletContext ();
45
46
PageContext pc = new MockPageContext (sc );
46
- assertTrue (ExpressionEvaluationUtils .isSpringJspExpressionSupportActive (pc ));
47
- sc .addInitParameter ("springJspExpressionSupport" , "false" );
48
47
assertFalse (ExpressionEvaluationUtils .isSpringJspExpressionSupportActive (pc ));
48
+ sc .addInitParameter ("springJspExpressionSupport" , "true" );
49
+ assertTrue (ExpressionEvaluationUtils .isSpringJspExpressionSupportActive (pc ));
49
50
}
50
51
51
52
@ Test
@@ -82,7 +83,9 @@ public void testIsExpressionLanguage() {
82
83
83
84
@ Test
84
85
public void testEvaluate () throws Exception {
85
- PageContext ctx = new MockPageContext ();
86
+ MockServletContext sc = new MockServletContext ();
87
+ sc .addInitParameter ("springJspExpressionSupport" , "true" );
88
+ MockPageContext ctx = new MockPageContext (sc );
86
89
ctx .setAttribute ("bla" , "blie" );
87
90
88
91
assertEquals ("blie" , ExpressionEvaluationUtils .evaluate ("test" , "${bla}" , String .class , ctx ));
@@ -99,7 +102,9 @@ public void testEvaluate() throws Exception {
99
102
100
103
@ Test
101
104
public void testEvaluateWithConcatenation () throws Exception {
102
- PageContext ctx = new MockPageContext ();
105
+ MockServletContext sc = new MockServletContext ();
106
+ sc .addInitParameter ("springJspExpressionSupport" , "true" );
107
+ MockPageContext ctx = new MockPageContext (sc );
103
108
ctx .setAttribute ("bla" , "blie" );
104
109
105
110
String expr = "text${bla}text${bla}text" ;
@@ -139,7 +144,9 @@ public void testEvaluateWithConcatenation() throws Exception {
139
144
140
145
@ Test
141
146
public void testEvaluateString () throws Exception {
142
- PageContext ctx = new MockPageContext ();
147
+ MockServletContext sc = new MockServletContext ();
148
+ sc .addInitParameter ("springJspExpressionSupport" , "true" );
149
+ MockPageContext ctx = new MockPageContext (sc );
143
150
ctx .setAttribute ("bla" , "blie" );
144
151
145
152
assertEquals ("blie" , ExpressionEvaluationUtils .evaluateString ("test" , "${bla}" , ctx ));
@@ -148,7 +155,9 @@ public void testEvaluateString() throws Exception {
148
155
149
156
@ Test
150
157
public void testEvaluateStringWithConcatenation () throws Exception {
151
- PageContext ctx = new MockPageContext ();
158
+ MockServletContext sc = new MockServletContext ();
159
+ sc .addInitParameter ("springJspExpressionSupport" , "true" );
160
+ MockPageContext ctx = new MockPageContext (sc );
152
161
ctx .setAttribute ("bla" , "blie" );
153
162
154
163
String expr = "text${bla}text${bla}text" ;
@@ -180,7 +189,9 @@ public void testEvaluateStringWithConcatenation() throws Exception {
180
189
181
190
@ Test
182
191
public void testEvaluateInteger () throws Exception {
183
- PageContext ctx = new MockPageContext ();
192
+ MockServletContext sc = new MockServletContext ();
193
+ sc .addInitParameter ("springJspExpressionSupport" , "true" );
194
+ MockPageContext ctx = new MockPageContext (sc );
184
195
ctx .setAttribute ("bla" , new Integer (1 ));
185
196
186
197
assertEquals (1 , ExpressionEvaluationUtils .evaluateInteger ("test" , "${bla}" , ctx ));
@@ -189,7 +200,9 @@ public void testEvaluateInteger() throws Exception {
189
200
190
201
@ Test
191
202
public void testEvaluateBoolean () throws Exception {
192
- PageContext ctx = new MockPageContext ();
203
+ MockServletContext sc = new MockServletContext ();
204
+ sc .addInitParameter ("springJspExpressionSupport" , "true" );
205
+ MockPageContext ctx = new MockPageContext (sc );
193
206
ctx .setAttribute ("bla" , new Boolean (true ));
194
207
195
208
assertTrue (ExpressionEvaluationUtils .evaluateBoolean ("test" , "${bla}" , ctx ));
@@ -198,7 +211,9 @@ public void testEvaluateBoolean() throws Exception {
198
211
199
212
@ Test
200
213
public void testRepeatedEvaluate () throws Exception {
201
- PageContext ctx = new CountingMockPageContext ();
214
+ MockServletContext sc = new MockServletContext ();
215
+ sc .addInitParameter ("springJspExpressionSupport" , "true" );
216
+ PageContext ctx = new CountingMockPageContext (sc );
202
217
CountingMockExpressionEvaluator eval = (CountingMockExpressionEvaluator ) ctx .getExpressionEvaluator ();
203
218
ctx .setAttribute ("bla" , "blie" );
204
219
ctx .setAttribute ("blo" , "blue" );
@@ -218,7 +233,9 @@ public void testRepeatedEvaluate() throws Exception {
218
233
219
234
@ Test
220
235
public void testEvaluateWithComplexConcatenation () throws Exception {
221
- PageContext ctx = new CountingMockPageContext ();
236
+ MockServletContext sc = new MockServletContext ();
237
+ sc .addInitParameter ("springJspExpressionSupport" , "true" );
238
+ PageContext ctx = new CountingMockPageContext (sc );
222
239
CountingMockExpressionEvaluator eval = (CountingMockExpressionEvaluator ) ctx .getExpressionEvaluator ();
223
240
ctx .setAttribute ("bla" , "blie" );
224
241
ctx .setAttribute ("blo" , "blue" );
@@ -247,6 +264,10 @@ public void testEvaluateWithComplexConcatenation() throws Exception {
247
264
248
265
private static class CountingMockPageContext extends MockPageContext {
249
266
267
+ public CountingMockPageContext (ServletContext servletContext ) {
268
+ super (servletContext );
269
+ }
270
+
250
271
private ExpressionEvaluator eval = new CountingMockExpressionEvaluator (this );
251
272
252
273
public ExpressionEvaluator getExpressionEvaluator () {
0 commit comments