Lines 64-71
Link Here
|
64 |
|
64 |
|
65 |
bean = new Bean(); |
65 |
bean = new Bean(); |
66 |
|
66 |
|
67 |
tag = new SetSupport(); |
|
|
68 |
tag.setPageContext(pageContext); |
69 |
|
67 |
|
70 |
ExpressionFactory expressionFactory = createMock(ExpressionFactory.class); |
68 |
ExpressionFactory expressionFactory = createMock(ExpressionFactory.class); |
71 |
JspApplicationContext applicationContext = createMock(JspApplicationContext.class); |
69 |
JspApplicationContext applicationContext = createMock(JspApplicationContext.class); |
Lines 85-93
Link Here
|
85 |
|
83 |
|
86 |
@Test |
84 |
@Test |
87 |
public void testSyntax1WithNoScope() throws JspException { |
85 |
public void testSyntax1WithNoScope() throws JspException { |
|
|
86 |
tag = new MockSetSupport(VALUE); |
87 |
tag.setPageContext(pageContext); |
88 |
tag.setVar(VAR); |
88 |
tag.setVar(VAR); |
89 |
tag.valueSpecified = true; |
|
|
90 |
tag.value = VALUE; |
91 |
|
89 |
|
92 |
// verify mapper is checked but that no action is taken |
90 |
// verify mapper is checked but that no action is taken |
93 |
expect(vm.resolveVariable(VAR)).andReturn(null); |
91 |
expect(vm.resolveVariable(VAR)).andReturn(null); |
Lines 99-108
Link Here
|
99 |
|
97 |
|
100 |
@Test |
98 |
@Test |
101 |
public void testSyntax1WithNullScope() throws JspException { |
99 |
public void testSyntax1WithNullScope() throws JspException { |
|
|
100 |
tag = new MockSetSupport(VALUE); |
101 |
tag.setPageContext(pageContext); |
102 |
tag.setVar(VAR); |
102 |
tag.setVar(VAR); |
103 |
tag.setScope(null); |
103 |
tag.setScope(null); |
104 |
tag.valueSpecified = true; |
|
|
105 |
tag.value = VALUE; |
106 |
|
104 |
|
107 |
// verify mapper is checked but that no action is taken |
105 |
// verify mapper is checked but that no action is taken |
108 |
expect(vm.resolveVariable(VAR)).andReturn(null); |
106 |
expect(vm.resolveVariable(VAR)).andReturn(null); |
Lines 114-123
Link Here
|
114 |
|
112 |
|
115 |
@Test |
113 |
@Test |
116 |
public void testSyntax1WithPageScope() throws JspException { |
114 |
public void testSyntax1WithPageScope() throws JspException { |
|
|
115 |
tag = new MockSetSupport(VALUE); |
116 |
tag.setPageContext(pageContext); |
117 |
tag.setVar(VAR); |
117 |
tag.setVar(VAR); |
118 |
tag.setScope("page"); |
118 |
tag.setScope("page"); |
119 |
tag.valueSpecified = true; |
|
|
120 |
tag.value = VALUE; |
121 |
|
119 |
|
122 |
// verify mapper is checked but that no action is taken |
120 |
// verify mapper is checked but that no action is taken |
123 |
expect(vm.resolveVariable(VAR)).andReturn(null); |
121 |
expect(vm.resolveVariable(VAR)).andReturn(null); |
Lines 129-138
Link Here
|
129 |
|
127 |
|
130 |
@Test |
128 |
@Test |
131 |
public void testSyntax1WithNonPageScope() throws JspException { |
129 |
public void testSyntax1WithNonPageScope() throws JspException { |
|
|
130 |
tag = new MockSetSupport(VALUE); |
131 |
tag.setPageContext(pageContext); |
132 |
tag.setVar(VAR); |
132 |
tag.setVar(VAR); |
133 |
tag.setScope("request"); |
133 |
tag.setScope("request"); |
134 |
tag.valueSpecified = true; |
|
|
135 |
tag.value = VALUE; |
136 |
|
134 |
|
137 |
// verify mapper is not checked |
135 |
// verify mapper is not checked |
138 |
pageContext.setAttribute(VAR, VALUE, PageContext.REQUEST_SCOPE); |
136 |
pageContext.setAttribute(VAR, VALUE, PageContext.REQUEST_SCOPE); |
Lines 143-151
Link Here
|
143 |
|
141 |
|
144 |
@Test |
142 |
@Test |
145 |
public void testSyntax1WithNullValueAndNoScope() throws JspException { |
143 |
public void testSyntax1WithNullValueAndNoScope() throws JspException { |
|
|
144 |
tag = new MockSetSupport(null); |
145 |
tag.setPageContext(pageContext); |
146 |
tag.setVar(VAR); |
146 |
tag.setVar(VAR); |
147 |
tag.valueSpecified = true; |
|
|
148 |
tag.value = null; |
149 |
|
147 |
|
150 |
// verify mapper is checked but that no action is taken |
148 |
// verify mapper is checked but that no action is taken |
151 |
expect(vm.resolveVariable(VAR)).andReturn(null); |
149 |
expect(vm.resolveVariable(VAR)).andReturn(null); |
Lines 157-166
Link Here
|
157 |
|
155 |
|
158 |
@Test |
156 |
@Test |
159 |
public void testSyntax1WithNullValueAndNonPageScope() throws JspException { |
157 |
public void testSyntax1WithNullValueAndNonPageScope() throws JspException { |
|
|
158 |
tag = new MockSetSupport(null); |
159 |
tag.setPageContext(pageContext); |
160 |
tag.setVar(VAR); |
160 |
tag.setVar(VAR); |
161 |
tag.setScope("request"); |
161 |
tag.setScope("request"); |
162 |
tag.valueSpecified = true; |
|
|
163 |
tag.value = null; |
164 |
|
162 |
|
165 |
// verify mapper is checked but that no action is taken |
163 |
// verify mapper is checked but that no action is taken |
166 |
expect(vm.resolveVariable(VAR)).andReturn(null); |
164 |
expect(vm.resolveVariable(VAR)).andReturn(null); |
Lines 174-184
Link Here
|
174 |
public void testSyntax3WithMap() throws JspException { |
172 |
public void testSyntax3WithMap() throws JspException { |
175 |
@SuppressWarnings("unchecked") |
173 |
@SuppressWarnings("unchecked") |
176 |
Map<String, Object> target = createMock(Map.class); |
174 |
Map<String, Object> target = createMock(Map.class); |
177 |
tag.target = target; |
175 |
tag = new MockSetSupport(VALUE, target, PROPERTY); |
178 |
tag.property = PROPERTY; |
176 |
tag.setPageContext(pageContext); |
179 |
tag.valueSpecified = true; |
177 |
|
180 |
tag.value = VALUE; |
|
|
181 |
|
182 |
expect(target.put(PROPERTY, VALUE)).andStubReturn(null); |
178 |
expect(target.put(PROPERTY, VALUE)).andStubReturn(null); |
183 |
replay(target); |
179 |
replay(target); |
184 |
tag.doEndTag(); |
180 |
tag.doEndTag(); |
Lines 189-198
Link Here
|
189 |
public void testSyntax3WithMapWhenPropertyIsNull() throws JspException { |
185 |
public void testSyntax3WithMapWhenPropertyIsNull() throws JspException { |
190 |
@SuppressWarnings("unchecked") |
186 |
@SuppressWarnings("unchecked") |
191 |
Map<String, Object> target = createMock(Map.class); |
187 |
Map<String, Object> target = createMock(Map.class); |
192 |
tag.target = target; |
188 |
tag = new MockSetSupport(VALUE, target, null); |
193 |
tag.property = null; |
189 |
tag.setPageContext(pageContext); |
194 |
tag.valueSpecified = true; |
|
|
195 |
tag.value = VALUE; |
196 |
|
190 |
|
197 |
expect(target.put(null, VALUE)).andStubReturn(null); |
191 |
expect(target.put(null, VALUE)).andStubReturn(null); |
198 |
replay(target); |
192 |
replay(target); |
Lines 204-213
Link Here
|
204 |
public void testSyntax3WithMapWhenValueIsNull() throws JspException { |
198 |
public void testSyntax3WithMapWhenValueIsNull() throws JspException { |
205 |
@SuppressWarnings("unchecked") |
199 |
@SuppressWarnings("unchecked") |
206 |
Map<String, Object> target = createMock(Map.class); |
200 |
Map<String, Object> target = createMock(Map.class); |
207 |
tag.target = target; |
201 |
tag = new MockSetSupport(null, target, PROPERTY); |
208 |
tag.property = PROPERTY; |
202 |
tag.setPageContext(pageContext); |
209 |
tag.valueSpecified = true; |
|
|
210 |
tag.value = null; |
211 |
|
203 |
|
212 |
expect(target.remove(PROPERTY)).andStubReturn(null); |
204 |
expect(target.remove(PROPERTY)).andStubReturn(null); |
213 |
replay(target); |
205 |
replay(target); |
Lines 217-226
Link Here
|
217 |
|
209 |
|
218 |
@Test |
210 |
@Test |
219 |
public void testSyntax3WithBean() throws JspException { |
211 |
public void testSyntax3WithBean() throws JspException { |
220 |
tag.target = bean; |
212 |
tag = new MockSetSupport(VALUE, bean, PROPERTY); |
221 |
tag.property = PROPERTY; |
213 |
tag.setPageContext(pageContext); |
222 |
tag.valueSpecified = true; |
|
|
223 |
tag.value = VALUE; |
224 |
|
214 |
|
225 |
tag.doEndTag(); |
215 |
tag.doEndTag(); |
226 |
Assert.assertEquals(VALUE, bean.getProperty()); |
216 |
Assert.assertEquals(VALUE, bean.getProperty()); |
Lines 228-237
Link Here
|
228 |
|
218 |
|
229 |
@Test |
219 |
@Test |
230 |
public void testSyntax3WithBeanAndNullValue() throws JspException { |
220 |
public void testSyntax3WithBeanAndNullValue() throws JspException { |
231 |
tag.target = bean; |
221 |
tag = new MockSetSupport(null, bean, PROPERTY); |
232 |
tag.property = PROPERTY; |
222 |
tag.setPageContext(pageContext); |
233 |
tag.valueSpecified = true; |
|
|
234 |
tag.value = null; |
235 |
|
223 |
|
236 |
tag.doEndTag(); |
224 |
tag.doEndTag(); |
237 |
Assert.assertNull(bean.getProperty()); |
225 |
Assert.assertNull(bean.getProperty()); |
Lines 239-248
Link Here
|
239 |
|
227 |
|
240 |
@Test |
228 |
@Test |
241 |
public void testSyntax3WithBeanAndUndefinedProperty() throws JspException { |
229 |
public void testSyntax3WithBeanAndUndefinedProperty() throws JspException { |
242 |
tag.target = bean; |
230 |
tag = new MockSetSupport(VALUE, bean, "undefined"); |
243 |
tag.property = "undefined"; |
231 |
tag.setPageContext(pageContext); |
244 |
tag.valueSpecified = true; |
|
|
245 |
tag.value = VALUE; |
246 |
|
232 |
|
247 |
try { |
233 |
try { |
248 |
tag.doEndTag(); |
234 |
tag.doEndTag(); |
Lines 253-262
Link Here
|
253 |
|
239 |
|
254 |
@Test |
240 |
@Test |
255 |
public void testSyntax3WithBeanAndReadOnlyProperty() throws JspException { |
241 |
public void testSyntax3WithBeanAndReadOnlyProperty() throws JspException { |
256 |
tag.target = bean; |
242 |
tag = new MockSetSupport(VALUE, bean, "readOnly"); |
257 |
tag.property = "readOnly"; |
243 |
tag.setPageContext(pageContext); |
258 |
tag.valueSpecified = true; |
|
|
259 |
tag.value = VALUE; |
260 |
|
244 |
|
261 |
try { |
245 |
try { |
262 |
tag.doEndTag(); |
246 |
tag.doEndTag(); |
Lines 267-276
Link Here
|
267 |
|
251 |
|
268 |
@Test |
252 |
@Test |
269 |
public void testSyntax3WhenTargetIsNull() throws JspException { |
253 |
public void testSyntax3WhenTargetIsNull() throws JspException { |
270 |
tag.target = null; |
254 |
tag = new MockSetSupport(VALUE, null, PROPERTY); |
271 |
tag.property = PROPERTY; |
255 |
tag.setPageContext(pageContext); |
272 |
tag.valueSpecified = true; |
|
|
273 |
tag.value = VALUE; |
274 |
|
256 |
|
275 |
try { |
257 |
try { |
276 |
tag.doEndTag(); |
258 |
tag.doEndTag(); |
Lines 287-295
Link Here
|
287 |
*/ |
269 |
*/ |
288 |
@Test |
270 |
@Test |
289 |
public void test49526WhenNotMapped() throws JspException { |
271 |
public void test49526WhenNotMapped() throws JspException { |
|
|
272 |
tag = new MockSetSupport(VALUE); |
273 |
tag.setPageContext(pageContext); |
290 |
tag.setVar(VAR); |
274 |
tag.setVar(VAR); |
291 |
tag.valueSpecified = true; |
|
|
292 |
tag.value = VALUE; |
293 |
|
275 |
|
294 |
// verify mapper is checked but that no action is taken |
276 |
// verify mapper is checked but that no action is taken |
295 |
expect(vm.resolveVariable(VAR)).andReturn(null); |
277 |
expect(vm.resolveVariable(VAR)).andReturn(null); |
Lines 306-314
Link Here
|
306 |
*/ |
288 |
*/ |
307 |
@Test |
289 |
@Test |
308 |
public void test49526WhenAlreadyMapped() throws JspException { |
290 |
public void test49526WhenAlreadyMapped() throws JspException { |
|
|
291 |
tag = new MockSetSupport(VALUE); |
292 |
tag.setPageContext(pageContext); |
309 |
tag.setVar(VAR); |
293 |
tag.setVar(VAR); |
310 |
tag.valueSpecified = true; |
|
|
311 |
tag.value = VALUE; |
312 |
|
294 |
|
313 |
// verify mapper is checked and the mapped variable removed |
295 |
// verify mapper is checked and the mapped variable removed |
314 |
ValueExpression ve = createMock(ValueExpression.class); |
296 |
ValueExpression ve = createMock(ValueExpression.class); |
Lines 327-335
Link Here
|
327 |
*/ |
309 |
*/ |
328 |
@Test |
310 |
@Test |
329 |
public void test49526WhenNotUsingPageContext() throws JspException { |
311 |
public void test49526WhenNotUsingPageContext() throws JspException { |
|
|
312 |
tag = new MockSetSupport(VALUE); |
313 |
tag.setPageContext(pageContext); |
330 |
tag.setVar(VAR); |
314 |
tag.setVar(VAR); |
331 |
tag.valueSpecified = true; |
|
|
332 |
tag.value = VALUE; |
333 |
tag.setScope("request"); |
315 |
tag.setScope("request"); |
334 |
|
316 |
|
335 |
// verify mapper is not checked |
317 |
// verify mapper is not checked |
Lines 341-361
Link Here
|
341 |
|
323 |
|
342 |
@Test |
324 |
@Test |
343 |
public void testResultFromValueAttribute() { |
325 |
public void testResultFromValueAttribute() { |
344 |
tag.valueSpecified = true; |
326 |
tag = new MockSetSupport(VALUE); |
345 |
tag.value = VALUE; |
|
|
346 |
Assert.assertSame(VALUE, tag.getResult()); |
327 |
Assert.assertSame(VALUE, tag.getResult()); |
347 |
} |
328 |
} |
348 |
|
329 |
|
349 |
@Test |
330 |
@Test |
350 |
public void testResultFromNullValueAttribute() { |
331 |
public void testResultFromNullValueAttribute() { |
351 |
tag.valueSpecified = true; |
332 |
tag = new MockSetSupport(null); |
352 |
tag.value = null; |
|
|
353 |
Assert.assertNull(tag.getResult()); |
333 |
Assert.assertNull(tag.getResult()); |
354 |
} |
334 |
} |
355 |
|
335 |
|
356 |
@Test |
336 |
@Test |
357 |
public void testResultFromBodyContent() { |
337 |
public void testResultFromBodyContent() { |
358 |
tag.valueSpecified = false; |
338 |
tag = new MockSetSupport(); |
359 |
BodyContent bodyContent = createMock(BodyContent.class); |
339 |
BodyContent bodyContent = createMock(BodyContent.class); |
360 |
expect(bodyContent.getString()).andStubReturn(" Hello "); |
340 |
expect(bodyContent.getString()).andStubReturn(" Hello "); |
361 |
replay(bodyContent); |
341 |
replay(bodyContent); |
Lines 365-383
Link Here
|
365 |
|
345 |
|
366 |
@Test |
346 |
@Test |
367 |
public void testResultFromNullBodyContent() { |
347 |
public void testResultFromNullBodyContent() { |
368 |
tag.valueSpecified = false; |
348 |
tag = new MockSetSupport(); |
369 |
tag.setBodyContent(null); |
349 |
tag.setBodyContent(null); |
370 |
Assert.assertEquals("", tag.getResult()); |
350 |
Assert.assertEquals("", tag.getResult()); |
371 |
} |
351 |
} |
372 |
|
352 |
|
373 |
@Test |
353 |
@Test |
374 |
public void testResultFromEmptyBodyContent() { |
354 |
public void testResultFromEmptyBodyContent() { |
375 |
tag.valueSpecified = false; |
355 |
tag = new MockSetSupport(); |
376 |
BodyContent bodyContent = createMock(BodyContent.class); |
356 |
BodyContent bodyContent = createMock(BodyContent.class); |
377 |
expect(bodyContent.getString()).andStubReturn(null); |
357 |
expect(bodyContent.getString()).andStubReturn(null); |
378 |
Assert.assertEquals("", tag.getResult()); |
358 |
Assert.assertEquals("", tag.getResult()); |
379 |
} |
359 |
} |
380 |
|
360 |
|
|
|
361 |
public static class MockSetSupport extends SetSupport { |
362 |
private final boolean valueSpecified; |
363 |
private final Object value; |
364 |
private final Object target; |
365 |
private final String property; |
366 |
|
367 |
public MockSetSupport() { |
368 |
this.value = null; |
369 |
this.valueSpecified = false; |
370 |
this.target = null; |
371 |
this.property = null; |
372 |
} |
373 |
|
374 |
public MockSetSupport(Object value, Object target, String property) { |
375 |
this.value = value; |
376 |
this.valueSpecified = true; |
377 |
this.target = target; |
378 |
this.property = property; |
379 |
} |
380 |
|
381 |
public MockSetSupport(Object value) { |
382 |
this.value = value; |
383 |
this.valueSpecified = true; |
384 |
this.target = null; |
385 |
this.property = null; |
386 |
} |
387 |
|
388 |
@Override |
389 |
protected boolean isValueSpecified() { |
390 |
return valueSpecified; |
391 |
} |
392 |
|
393 |
@Override |
394 |
protected Object evalValue() { |
395 |
return value; |
396 |
} |
397 |
|
398 |
@Override |
399 |
protected Object evalTarget() { |
400 |
return target; |
401 |
} |
402 |
|
403 |
@Override |
404 |
protected String evalProperty() { |
405 |
return property; |
406 |
} |
407 |
} |
408 |
|
381 |
public static class Bean { |
409 |
public static class Bean { |
382 |
private String property; |
410 |
private String property; |
383 |
|
411 |
|