tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r960166 - in /tomcat/taglibs/standard/trunk/impl: ./ src/main/java/org/apache/taglibs/standard/tag/common/core/ src/test/java/org/apache/taglibs/standard/tag/common/ src/test/java/org/apache/taglibs/standard/tag/common/core/
Date Sat, 03 Jul 2010 07:36:34 GMT
Author: bayard
Date: Sat Jul  3 07:36:34 2010
New Revision: 960166

URL: http://svn.apache.org/viewvc?rev=960166&view=rev
Log:
Implementing commented out code - c:set now removes variables from ELContext VariableMapper.
Test and fix patches from Jeremy Boynes #49526

Added:
    tomcat/taglibs/standard/trunk/impl/src/test/java/org/apache/taglibs/standard/tag/common/
    tomcat/taglibs/standard/trunk/impl/src/test/java/org/apache/taglibs/standard/tag/common/core/
    tomcat/taglibs/standard/trunk/impl/src/test/java/org/apache/taglibs/standard/tag/common/core/TestSetSupport.java
  (with props)
Modified:
    tomcat/taglibs/standard/trunk/impl/pom.xml
    tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/core/SetSupport.java

Modified: tomcat/taglibs/standard/trunk/impl/pom.xml
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/pom.xml?rev=960166&r1=960165&r2=960166&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/impl/pom.xml (original)
+++ tomcat/taglibs/standard/trunk/impl/pom.xml Sat Jul  3 07:36:34 2010
@@ -68,7 +68,12 @@
   </contributors>
 
   <dependencies>
-    <dependency>
+      <dependency>
+          <groupId>junit</groupId>
+          <artifactId>junit</artifactId>
+          <version>4.8.1</version>
+      </dependency>
+      <dependency>
       <groupId>org.apache.taglibs</groupId>
       <artifactId>taglibs-standard-spec</artifactId>
       <version>1.2-SNAPSHOT</version>
@@ -103,9 +108,15 @@
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
-      <version>3.8.2</version>
+      <version>4.8.1</version>
       <scope>test</scope>
     </dependency>
+      <dependency>
+          <groupId>org.easymock</groupId>
+          <artifactId>easymock</artifactId>
+          <version>3.0</version>
+          <scope>test</scope>
+      </dependency>
   </dependencies> 
 
   <build>
@@ -126,6 +137,7 @@
           <includes>
             <include>org/apache/taglibs/standard/lang/jstl/test/StaticFunctionTests.java</include>
             <include>org/apache/taglibs/standard/TestVersion.java</include>
+            <include>org/apache/taglibs/standard/tag/**/Test*.java</include>
           </includes>
           <excludes>
             <!-- Old tests -->

Modified: tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/core/SetSupport.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/core/SetSupport.java?rev=960166&r1=960165&r2=960166&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/core/SetSupport.java
(original)
+++ tomcat/taglibs/standard/trunk/impl/src/main/java/org/apache/taglibs/standard/tag/common/core/SetSupport.java
Sat Jul  3 07:36:34 2010
@@ -128,12 +128,10 @@ public class SetSupport extends BodyTagS
                     //set variable in var Mapper
                     vm.setVariable(var, (ValueExpression)result);
                 } else {
-                    /*
-                    //else if not valueExpression - make sure to remove it from the Var mapper
-                    //if the scope is page, should I remove this?
-                    if (vm.resolveVariable(var)!=null) {
+                    // make sure to remove it from the VariableMapper if we will be setting
into page scope 
+                    if (scope == PageContext.PAGE_SCOPE && vm.resolveVariable(var)
!= null) {
                         vm.setVariable(var, null);
-                    }*/
+                    }
                     pageContext.setAttribute(var, result, scope);
                 }
             } else {

Added: tomcat/taglibs/standard/trunk/impl/src/test/java/org/apache/taglibs/standard/tag/common/core/TestSetSupport.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/impl/src/test/java/org/apache/taglibs/standard/tag/common/core/TestSetSupport.java?rev=960166&view=auto
==============================================================================
--- tomcat/taglibs/standard/trunk/impl/src/test/java/org/apache/taglibs/standard/tag/common/core/TestSetSupport.java
(added)
+++ tomcat/taglibs/standard/trunk/impl/src/test/java/org/apache/taglibs/standard/tag/common/core/TestSetSupport.java
Sat Jul  3 07:36:34 2010
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.taglibs.standard.tag.common.core;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.el.VariableMapper;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+public class TestSetSupport {
+
+    private PageContext pageContext;
+    private ELContext elContext;
+    private VariableMapper vm;
+    private SetSupport tag;
+
+    @Before
+    public void setup() {
+        tag = new SetSupport();
+        pageContext = createMock(PageContext.class);
+        elContext = createMock(ELContext.class);
+        vm = createMock(VariableMapper.class);
+
+        expect(pageContext.getELContext()).andStubReturn(elContext);
+        expect(elContext.getVariableMapper()).andStubReturn(vm);
+    }
+
+    /**
+     * Verify Bug 49526 when there is no existing variable mapping.
+     *
+     * @throws JspException if there's an error
+     */
+    @Test
+    public void test49526WhenNotMapped() throws JspException {
+        tag.setPageContext(pageContext);
+        tag.setVar("x");
+        tag.value = "Hello";
+
+        // verify mapper is checked but that no action is taken
+        expect(vm.resolveVariable("x")).andReturn(null);
+        pageContext.setAttribute("x", "Hello", PageContext.PAGE_SCOPE);
+        replay(pageContext, elContext, vm);
+        tag.doEndTag();
+        verify(pageContext, elContext, vm);
+    }
+
+    /**
+     * Verify Bug 49526 when there is an existing variable mapping.
+     *
+     * @throws JspException if there's an error
+     */
+    @Test
+    public void test49526WhenAlreadyMapped() throws JspException {
+        tag.setPageContext(pageContext);
+        tag.setVar("x");
+        tag.value = "Hello";
+
+        // verify mapper is checked and the mapped variable removed
+        ValueExpression ve = createMock(ValueExpression.class);
+        expect(vm.resolveVariable("x")).andReturn(ve);
+        expect(vm.setVariable("x", null)).andReturn(ve);
+        pageContext.setAttribute("x", "Hello", PageContext.PAGE_SCOPE);
+        replay(pageContext, elContext, vm, ve);
+        tag.doEndTag();
+        verify(pageContext, elContext, vm, ve);
+    }
+
+    /**
+     * Verify Bug 49526 when we are not setting into the page context.
+     *
+     * @throws JspException if there's an error
+     */
+    @Test
+    public void test49526WhenNotUsingPageContext() throws JspException {
+        tag.setPageContext(pageContext);
+        tag.setVar("x");
+        tag.value = "Hello";
+        tag.setScope("request");
+
+        // verify mapper is not checked
+        pageContext.setAttribute("x", "Hello", PageContext.REQUEST_SCOPE);
+        replay(pageContext, elContext, vm);
+        tag.doEndTag();
+        verify(pageContext, elContext, vm);
+    }
+}

Propchange: tomcat/taglibs/standard/trunk/impl/src/test/java/org/apache/taglibs/standard/tag/common/core/TestSetSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message