View | Details | Raw Unified | Return to bug 49526
Collapse All | Expand All

(-)pom.xml (-2 / +14 lines)
Lines 68-74 Link Here
68
  </contributors>
68
  </contributors>
69
69
70
  <dependencies>
70
  <dependencies>
71
    <dependency>
71
      <dependency>
72
          <groupId>junit</groupId>
73
          <artifactId>junit</artifactId>
74
          <version>4.8.1</version>
75
      </dependency>
76
      <dependency>
72
      <groupId>org.apache.taglibs</groupId>
77
      <groupId>org.apache.taglibs</groupId>
73
      <artifactId>taglibs-standard-spec</artifactId>
78
      <artifactId>taglibs-standard-spec</artifactId>
74
      <version>1.2-SNAPSHOT</version>
79
      <version>1.2-SNAPSHOT</version>
Lines 103-111 Link Here
103
    <dependency>
108
    <dependency>
104
      <groupId>junit</groupId>
109
      <groupId>junit</groupId>
105
      <artifactId>junit</artifactId>
110
      <artifactId>junit</artifactId>
106
      <version>3.8.2</version>
111
      <version>4.8.1</version>
107
      <scope>test</scope>
112
      <scope>test</scope>
108
    </dependency>
113
    </dependency>
114
      <dependency>
115
          <groupId>org.easymock</groupId>
116
          <artifactId>easymock</artifactId>
117
          <version>3.0</version>
118
          <scope>test</scope>
119
      </dependency>
109
  </dependencies> 
120
  </dependencies> 
110
121
111
  <build>
122
  <build>
Lines 126-131 Link Here
126
          <includes>
137
          <includes>
127
            <include>org/apache/taglibs/standard/lang/jstl/test/StaticFunctionTests.java</include>
138
            <include>org/apache/taglibs/standard/lang/jstl/test/StaticFunctionTests.java</include>
128
            <include>org/apache/taglibs/standard/TestVersion.java</include>
139
            <include>org/apache/taglibs/standard/TestVersion.java</include>
140
            <include>org/apache/taglibs/standard/tag/**/Test*.java</include>
129
          </includes>
141
          </includes>
130
          <excludes>
142
          <excludes>
131
            <!-- Old tests -->
143
            <!-- Old tests -->
(-)src/test/java/org/apache/taglibs/standard/tag/common/core/TestSetSupport.java (+109 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
package org.apache.taglibs.standard.tag.common.core;
18
19
import org.junit.Before;
20
import org.junit.Test;
21
22
import javax.el.ELContext;
23
import javax.el.ValueExpression;
24
import javax.el.VariableMapper;
25
import javax.servlet.jsp.JspException;
26
import javax.servlet.jsp.PageContext;
27
28
import static org.easymock.EasyMock.createMock;
29
import static org.easymock.EasyMock.expect;
30
import static org.easymock.EasyMock.replay;
31
import static org.easymock.EasyMock.verify;
32
33
public class TestSetSupport {
34
35
    private PageContext pageContext;
36
    private ELContext elContext;
37
    private VariableMapper vm;
38
    private SetSupport tag;
39
40
    @Before
41
    public void setup() {
42
        tag = new SetSupport();
43
        pageContext = createMock(PageContext.class);
44
        elContext = createMock(ELContext.class);
45
        vm = createMock(VariableMapper.class);
46
47
        expect(pageContext.getELContext()).andStubReturn(elContext);
48
        expect(elContext.getVariableMapper()).andStubReturn(vm);
49
    }
50
51
    /**
52
     * Verify Bug 49526 when there is no existing variable mapping.
53
     *
54
     * @throws JspException if there's an error
55
     */
56
    @Test
57
    public void test49526WhenNotMapped() throws JspException {
58
        tag.setPageContext(pageContext);
59
        tag.setVar("x");
60
        tag.value = "Hello";
61
62
        // verify mapper is checked but that no action is taken
63
        expect(vm.resolveVariable("x")).andReturn(null);
64
        pageContext.setAttribute("x", "Hello", PageContext.PAGE_SCOPE);
65
        replay(pageContext, elContext, vm);
66
        tag.doEndTag();
67
        verify(pageContext, elContext, vm);
68
    }
69
70
    /**
71
     * Verify Bug 49526 when there is an existing variable mapping.
72
     *
73
     * @throws JspException if there's an error
74
     */
75
    @Test
76
    public void test49526WhenAlreadyMapped() throws JspException {
77
        tag.setPageContext(pageContext);
78
        tag.setVar("x");
79
        tag.value = "Hello";
80
81
        // verify mapper is checked and the mapped variable removed
82
        ValueExpression ve = createMock(ValueExpression.class);
83
        expect(vm.resolveVariable("x")).andReturn(ve);
84
        expect(vm.setVariable("x", null)).andReturn(ve);
85
        pageContext.setAttribute("x", "Hello", PageContext.PAGE_SCOPE);
86
        replay(pageContext, elContext, vm, ve);
87
        tag.doEndTag();
88
        verify(pageContext, elContext, vm, ve);
89
    }
90
91
    /**
92
     * Verify Bug 49526 when we are not setting into the page context.
93
     *
94
     * @throws JspException if there's an error
95
     */
96
    @Test
97
    public void test49526WhenNotUsingPageContext() throws JspException {
98
        tag.setPageContext(pageContext);
99
        tag.setVar("x");
100
        tag.value = "Hello";
101
        tag.setScope("request");
102
103
        // verify mapper is not checked
104
        pageContext.setAttribute("x", "Hello", PageContext.REQUEST_SCOPE);
105
        replay(pageContext, elContext, vm);
106
        tag.doEndTag();
107
        verify(pageContext, elContext, vm);
108
    }
109
}

Return to bug 49526