Lines 16-21
Link Here
|
16 |
*/ |
16 |
*/ |
17 |
package org.apache.taglibs.standard.tag.common.core; |
17 |
package org.apache.taglibs.standard.tag.common.core; |
18 |
|
18 |
|
|
|
19 |
import org.junit.Assert; |
19 |
import org.junit.Before; |
20 |
import org.junit.Before; |
20 |
import org.junit.Test; |
21 |
import org.junit.Test; |
21 |
|
22 |
|
Lines 24-29
Link Here
|
24 |
import javax.el.VariableMapper; |
25 |
import javax.el.VariableMapper; |
25 |
import javax.servlet.jsp.JspException; |
26 |
import javax.servlet.jsp.JspException; |
26 |
import javax.servlet.jsp.PageContext; |
27 |
import javax.servlet.jsp.PageContext; |
|
|
28 |
import javax.servlet.jsp.tagext.BodyContent; |
27 |
|
29 |
|
28 |
import static org.easymock.EasyMock.createMock; |
30 |
import static org.easymock.EasyMock.createMock; |
29 |
import static org.easymock.EasyMock.expect; |
31 |
import static org.easymock.EasyMock.expect; |
Lines 31-36
Link Here
|
31 |
import static org.easymock.EasyMock.verify; |
33 |
import static org.easymock.EasyMock.verify; |
32 |
|
34 |
|
33 |
public class TestSetSupport { |
35 |
public class TestSetSupport { |
|
|
36 |
private static String VALUE = "Hello"; |
37 |
private static final String VAR = "x"; |
34 |
|
38 |
|
35 |
private PageContext pageContext; |
39 |
private PageContext pageContext; |
36 |
private ELContext elContext; |
40 |
private ELContext elContext; |
Lines 39-51
Link Here
|
39 |
|
43 |
|
40 |
@Before |
44 |
@Before |
41 |
public void setup() { |
45 |
public void setup() { |
42 |
tag = new SetSupport(); |
|
|
43 |
pageContext = createMock(PageContext.class); |
46 |
pageContext = createMock(PageContext.class); |
44 |
elContext = createMock(ELContext.class); |
47 |
elContext = createMock(ELContext.class); |
45 |
vm = createMock(VariableMapper.class); |
48 |
vm = createMock(VariableMapper.class); |
46 |
|
49 |
|
47 |
expect(pageContext.getELContext()).andStubReturn(elContext); |
50 |
expect(pageContext.getELContext()).andStubReturn(elContext); |
48 |
expect(elContext.getVariableMapper()).andStubReturn(vm); |
51 |
expect(elContext.getVariableMapper()).andStubReturn(vm); |
|
|
52 |
|
53 |
tag = new SetSupport(); |
54 |
tag.setPageContext(pageContext); |
49 |
} |
55 |
} |
50 |
|
56 |
|
51 |
/** |
57 |
/** |
Lines 55-67
Link Here
|
55 |
*/ |
61 |
*/ |
56 |
@Test |
62 |
@Test |
57 |
public void test49526WhenNotMapped() throws JspException { |
63 |
public void test49526WhenNotMapped() throws JspException { |
58 |
tag.setPageContext(pageContext); |
64 |
tag.setVar(VAR); |
59 |
tag.setVar("x"); |
65 |
tag.value = VALUE; |
60 |
tag.value = "Hello"; |
|
|
61 |
|
66 |
|
62 |
// verify mapper is checked but that no action is taken |
67 |
// verify mapper is checked but that no action is taken |
63 |
expect(vm.resolveVariable("x")).andReturn(null); |
68 |
expect(vm.resolveVariable(VAR)).andReturn(null); |
64 |
pageContext.setAttribute("x", "Hello", PageContext.PAGE_SCOPE); |
69 |
pageContext.setAttribute(VAR, VALUE, PageContext.PAGE_SCOPE); |
65 |
replay(pageContext, elContext, vm); |
70 |
replay(pageContext, elContext, vm); |
66 |
tag.doEndTag(); |
71 |
tag.doEndTag(); |
67 |
verify(pageContext, elContext, vm); |
72 |
verify(pageContext, elContext, vm); |
Lines 74-88
Link Here
|
74 |
*/ |
79 |
*/ |
75 |
@Test |
80 |
@Test |
76 |
public void test49526WhenAlreadyMapped() throws JspException { |
81 |
public void test49526WhenAlreadyMapped() throws JspException { |
77 |
tag.setPageContext(pageContext); |
82 |
tag.setVar(VAR); |
78 |
tag.setVar("x"); |
83 |
tag.value = VALUE; |
79 |
tag.value = "Hello"; |
|
|
80 |
|
84 |
|
81 |
// verify mapper is checked and the mapped variable removed |
85 |
// verify mapper is checked and the mapped variable removed |
82 |
ValueExpression ve = createMock(ValueExpression.class); |
86 |
ValueExpression ve = createMock(ValueExpression.class); |
83 |
expect(vm.resolveVariable("x")).andReturn(ve); |
87 |
expect(vm.resolveVariable(VAR)).andReturn(ve); |
84 |
expect(vm.setVariable("x", null)).andReturn(ve); |
88 |
expect(vm.setVariable(VAR, null)).andReturn(ve); |
85 |
pageContext.setAttribute("x", "Hello", PageContext.PAGE_SCOPE); |
89 |
pageContext.setAttribute(VAR, VALUE, PageContext.PAGE_SCOPE); |
86 |
replay(pageContext, elContext, vm, ve); |
90 |
replay(pageContext, elContext, vm, ve); |
87 |
tag.doEndTag(); |
91 |
tag.doEndTag(); |
88 |
verify(pageContext, elContext, vm, ve); |
92 |
verify(pageContext, elContext, vm, ve); |
Lines 95-109
Link Here
|
95 |
*/ |
99 |
*/ |
96 |
@Test |
100 |
@Test |
97 |
public void test49526WhenNotUsingPageContext() throws JspException { |
101 |
public void test49526WhenNotUsingPageContext() throws JspException { |
98 |
tag.setPageContext(pageContext); |
102 |
tag.setVar(VAR); |
99 |
tag.setVar("x"); |
103 |
tag.value = VALUE; |
100 |
tag.value = "Hello"; |
|
|
101 |
tag.setScope("request"); |
104 |
tag.setScope("request"); |
102 |
|
105 |
|
103 |
// verify mapper is not checked |
106 |
// verify mapper is not checked |
104 |
pageContext.setAttribute("x", "Hello", PageContext.REQUEST_SCOPE); |
107 |
pageContext.setAttribute(VAR, VALUE, PageContext.REQUEST_SCOPE); |
105 |
replay(pageContext, elContext, vm); |
108 |
replay(pageContext, elContext, vm); |
106 |
tag.doEndTag(); |
109 |
tag.doEndTag(); |
107 |
verify(pageContext, elContext, vm); |
110 |
verify(pageContext, elContext, vm); |
108 |
} |
111 |
} |
|
|
112 |
|
113 |
@Test |
114 |
public void testResultFromValueAttribute() { |
115 |
tag.valueSpecified = true; |
116 |
tag.value = VALUE; |
117 |
Assert.assertSame(VALUE, tag.getResult()); |
118 |
} |
119 |
|
120 |
@Test |
121 |
public void testResultFromNullValueAttribute() { |
122 |
tag.valueSpecified = true; |
123 |
tag.value = null; |
124 |
Assert.assertNull(tag.getResult()); |
125 |
} |
126 |
|
127 |
@Test |
128 |
public void testResultFromBodyContent() { |
129 |
tag.valueSpecified = false; |
130 |
BodyContent bodyContent = createMock(BodyContent.class); |
131 |
expect(bodyContent.getString()).andStubReturn(" Hello "); |
132 |
replay(bodyContent); |
133 |
tag.setBodyContent(bodyContent); |
134 |
Assert.assertEquals(VALUE, tag.getResult()); |
135 |
} |
136 |
|
137 |
@Test |
138 |
public void testResultFromNullBodyContent() { |
139 |
tag.valueSpecified = false; |
140 |
tag.setBodyContent(null); |
141 |
Assert.assertEquals("", tag.getResult()); |
142 |
} |
143 |
|
144 |
@Test |
145 |
public void testResultFromEmptyBodyContent() { |
146 |
tag.valueSpecified = false; |
147 |
BodyContent bodyContent = createMock(BodyContent.class); |
148 |
expect(bodyContent.getString()).andStubReturn(null); |
149 |
Assert.assertEquals("", tag.getResult()); |
150 |
} |
109 |
} |
151 |
} |