You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tiles.apache.org by ap...@apache.org on 2009/07/17 16:28:22 UTC

svn commit: r795099 - in /tiles/framework/branches/TILES_2_1_X/tiles-jsp/src: main/java/org/apache/tiles/jsp/taglib/ test/java/org/apache/tiles/jsp/taglib/

Author: apetrelli
Date: Fri Jul 17 14:28:22 2009
New Revision: 795099

URL: http://svn.apache.org/viewvc?rev=795099&view=rev
Log:
TILES-441
Applied patch by Roshni Basu, along with other checks.
Added test case.

Added:
    tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/test/java/org/apache/tiles/jsp/taglib/
    tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/test/java/org/apache/tiles/jsp/taglib/ImportAttributeTagTest.java   (with props)
Modified:
    tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AttributeTagSupport.java
    tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/ImportAttributeTag.java

Modified: tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AttributeTagSupport.java
URL: http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AttributeTagSupport.java?rev=795099&r1=795098&r2=795099&view=diff
==============================================================================
--- tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AttributeTagSupport.java (original)
+++ tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AttributeTagSupport.java Fri Jul 17 14:28:22 2009
@@ -163,6 +163,9 @@
             }
 
             if (attributeValue == null) {
+                if (ignore) {
+                    return SKIP_BODY;
+                }
                 throw new TilesJspException("Attribute with name '" + name
                         + "' has a null value.");
             }

Modified: tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/ImportAttributeTag.java
URL: http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/ImportAttributeTag.java?rev=795099&r1=795098&r2=795099&view=diff
==============================================================================
--- tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/ImportAttributeTag.java (original)
+++ tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/ImportAttributeTag.java Fri Jul 17 14:28:22 2009
@@ -120,11 +120,14 @@
                 try {
                     Object attributeValue = container.evaluate(attr, pageContext);
                     if (attributeValue == null) {
-                        throw new TilesJspException(
-                                "Error importing attributes. " + "Attribute '"
-                                        + name + "' has a null value ");
+                        if (!ignore) {
+                            throw new TilesJspException(
+                                    "Error importing attributes. " + "Attribute '"
+                                            + name + "' has a null value ");
+                        }
+                    } else {
+                        pageContext.setAttribute(name, attributeValue, scope);
                     }
-                    pageContext.setAttribute(name, attributeValue, scope);
                 } catch (TilesException e) {
                     if (!ignore) {
                         throw e;

Added: tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/test/java/org/apache/tiles/jsp/taglib/ImportAttributeTagTest.java
URL: http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/test/java/org/apache/tiles/jsp/taglib/ImportAttributeTagTest.java?rev=795099&view=auto
==============================================================================
--- tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/test/java/org/apache/tiles/jsp/taglib/ImportAttributeTagTest.java (added)
+++ tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/test/java/org/apache/tiles/jsp/taglib/ImportAttributeTagTest.java Fri Jul 17 14:28:22 2009
@@ -0,0 +1,156 @@
+/*
+ * $Id$
+ *
+ * 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.tiles.jsp.taglib;
+
+import static org.easymock.classextension.EasyMock.*;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.servlet.jsp.PageContext;
+
+import org.apache.tiles.Attribute;
+import org.apache.tiles.AttributeContext;
+import org.apache.tiles.TilesContainer;
+import org.apache.tiles.servlet.context.ServletUtil;
+import org.junit.Test;
+
+/**
+ * Tests {@link ImportAttributeTag}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ImportAttributeTagTest {
+
+    /**
+     * Tests {@link ImportAttributeTag} with name specified and ignore false.
+     *
+     * @throws TilesJspException If something goes wrong.
+     */
+    @Test(expected = TilesJspException.class)
+    public void testTagNullEvaluateException() throws TilesJspException {
+        PageContext pageContext = createMock(PageContext.class);
+        TilesContainer container = createMock(TilesContainer.class);
+        AttributeContext attributeContext = createMock(AttributeContext.class);
+        Attribute attribute = new Attribute("myValue");
+        expect(pageContext.getAttribute(
+                ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME,
+                PageContext.REQUEST_SCOPE)).andReturn(container);
+        expect(container.getAttributeContext(pageContext)).andReturn(attributeContext);
+        expect(attributeContext.getAttribute("attributeName")).andReturn(attribute);
+        expect(container.evaluate(attribute, pageContext)).andReturn(null);
+
+        replay(pageContext, container, attributeContext);
+        ImportAttributeTag tag = new ImportAttributeTag();
+        tag.setPageContext(pageContext);
+        tag.setName("attributeName");
+        tag.doStartTag();
+        verify(pageContext, container, attributeContext);
+    }
+
+    /**
+     * Tests {@link ImportAttributeTag} with name specified and ignore true.
+     *
+     * @throws TilesJspException If something goes wrong.
+     */
+    @Test
+    public void testTagNullEvaluateIgnoreException() throws TilesJspException {
+        PageContext pageContext = createMock(PageContext.class);
+        TilesContainer container = createMock(TilesContainer.class);
+        AttributeContext attributeContext = createMock(AttributeContext.class);
+        Attribute attribute = new Attribute("myValue");
+        expect(pageContext.getAttribute(
+                ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME,
+                PageContext.REQUEST_SCOPE)).andReturn(container);
+        expect(container.getAttributeContext(pageContext)).andReturn(attributeContext);
+        expect(attributeContext.getAttribute("attributeName")).andReturn(attribute);
+        expect(container.evaluate(attribute, pageContext)).andReturn(null);
+
+        replay(pageContext, container, attributeContext);
+        ImportAttributeTag tag = new ImportAttributeTag();
+        tag.setPageContext(pageContext);
+        tag.setName("attributeName");
+        tag.setIgnore(true);
+        tag.doStartTag();
+        verify(pageContext, container, attributeContext);
+    }
+
+
+    /**
+     * Tests {@link ImportAttributeTag} with name not specified and ignore false.
+     *
+     * @throws TilesJspException If something goes wrong.
+     */
+    @Test(expected = TilesJspException.class)
+    public void testTagNullEvaluateAllException() throws TilesJspException {
+        PageContext pageContext = createMock(PageContext.class);
+        TilesContainer container = createMock(TilesContainer.class);
+        AttributeContext attributeContext = createMock(AttributeContext.class);
+        Attribute attribute = new Attribute("myValue");
+        expect(pageContext.getAttribute(
+                ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME,
+                PageContext.REQUEST_SCOPE)).andReturn(container);
+        expect(container.getAttributeContext(pageContext)).andReturn(attributeContext);
+        expect(attributeContext.getAttribute("attributeName")).andReturn(attribute);
+        expect(container.evaluate(attribute, pageContext)).andReturn(null);
+        expect(attributeContext.getCascadedAttributeNames()).andReturn(null);
+        Set<String> names = new HashSet<String>();
+        names.add("attributeName");
+        expect(attributeContext.getLocalAttributeNames()).andReturn(names);
+
+        replay(pageContext, container, attributeContext);
+        ImportAttributeTag tag = new ImportAttributeTag();
+        tag.setPageContext(pageContext);
+        tag.doStartTag();
+        verify(pageContext, container, attributeContext);
+    }
+
+    /**
+     * Tests {@link ImportAttributeTag} with name not specified and ignore true.
+     *
+     * @throws TilesJspException If something goes wrong.
+     */
+    @Test
+    public void testTagNullEvaluateAllIgnoreException() throws TilesJspException {
+        PageContext pageContext = createMock(PageContext.class);
+        TilesContainer container = createMock(TilesContainer.class);
+        AttributeContext attributeContext = createMock(AttributeContext.class);
+        Attribute attribute = new Attribute("myValue");
+        expect(pageContext.getAttribute(
+                ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME,
+                PageContext.REQUEST_SCOPE)).andReturn(container);
+        expect(container.getAttributeContext(pageContext)).andReturn(attributeContext);
+        expect(attributeContext.getAttribute("attributeName")).andReturn(attribute);
+        expect(container.evaluate(attribute, pageContext)).andReturn(null);
+        expect(attributeContext.getCascadedAttributeNames()).andReturn(null);
+        Set<String> names = new HashSet<String>();
+        names.add("attributeName");
+        expect(attributeContext.getLocalAttributeNames()).andReturn(names);
+
+        replay(pageContext, container, attributeContext);
+        ImportAttributeTag tag = new ImportAttributeTag();
+        tag.setPageContext(pageContext);
+        tag.setIgnore(true);
+        tag.doStartTag();
+        verify(pageContext, container, attributeContext);
+    }
+}

Propchange: tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/test/java/org/apache/tiles/jsp/taglib/ImportAttributeTagTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/test/java/org/apache/tiles/jsp/taglib/ImportAttributeTagTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL