tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkuhn...@apache.org
Subject svn commit: r485258 - in /tapestry/tapestry4/trunk: ./ tapestry-framework/src/java/org/apache/tapestry/ tapestry-framework/src/java/org/apache/tapestry/components/ tapestry-framework/src/java/org/apache/tapestry/services/impl/ tapestry-framework/src/ja...
Date Sun, 10 Dec 2006 21:07:12 GMT
Author: jkuhnert
Date: Sun Dec 10 13:07:10 2006
New Revision: 485258

URL: http://svn.apache.org/viewvc?view=rev&rev=485258
Log:
Fixes for TAPESTRY-736.

Added new ForBean test to cover very basic scenarios.

Added:
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/components/TestForBean.java
Modified:
    tapestry/tapestry4/trunk/.checkstyle
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/PageRenderSupport.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/ForBean.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/DefaultResponseBuilder.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/DojoAjaxResponseBuilder.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/JSONResponseBuilder.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/util/PageRenderSupportImpl.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/components/TestIfElse.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/dojo/AjaxShellDelegateTest.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/TestPageRenderSupport.java

Modified: tapestry/tapestry4/trunk/.checkstyle
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/.checkstyle?view=diff&rev=485258&r1=485257&r2=485258
==============================================================================
--- tapestry/tapestry4/trunk/.checkstyle (original)
+++ tapestry/tapestry4/trunk/.checkstyle Sun Dec 10 13:07:10 2006
@@ -8,16 +8,15 @@
     </fileset>
     <filter name="FilesFromPackage" enabled="true">
         <filter-data value="tapestry-framework/src/test"/>
-        <filter-data value="tapestry-examples/VlibBeans/src/test"/>
-        <filter-data value="tapestry-examples/Vlib/src/test"/>
-        <filter-data value="tapestry-framework/src/descriptor"/>
-        <filter-data value="tapestry-contrib/src/descriptor"/>
         <filter-data value="tapestry-portlet/src/test"/>
-        <filter-data value="tapestry-annotations/src/descriptor"/>
-        <filter-data value="tapestry-portlet/src/descriptor"/>
         <filter-data value="tapestry-examples/Workbench/src/test"/>
+        <filter-data value="tapestry-framework/src/js"/>
         <filter-data value="tapestry-contrib/src/test"/>
         <filter-data value="tapestry-annotations/src/test"/>
+        <filter-data value="tapestry-annotations/src/descriptor"/>
+        <filter-data value="tapestry-contrib/src/descriptor"/>
+        <filter-data value="tapestry-framework/src/descriptor"/>
+        <filter-data value="tapestry-portlet/src/descriptor"/>
     </filter>
     <filter name="NonSrcDirs" enabled="true"/>
 </fileset-config>

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/PageRenderSupport.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/PageRenderSupport.java?view=diff&rev=485258&r1=485257&r2=485258
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/PageRenderSupport.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/PageRenderSupport.java
Sun Dec 10 13:07:10 2006
@@ -31,10 +31,23 @@
      * as a function parameter, or as a property assignment. A typical return value might
be
      * <code>tapestry_preload[7].src</code>.
      * 
-     * @deprecated To be removed in 4.2, use {@link #getPreloadedImageReference(IComponent,
String)} instead.
+     * @deprecated To be removed in 4.2, use {@link #getPreloadedImageReference(IComponent,
String)} 
+     *              or {@link #getPreloadedImageReference(IComponent, IAsset)} instead.
      */
 
     String getPreloadedImageReference(String url);
+    
+    /**
+     * Operates in the same way that {@link #getPreloadedImageReference(IComponent, String)}
does, except 
+     * the source is the actual {@link IAsset} of an image to preload. 
+     * 
+     * @param target
+     *          The component the asset is being loaded for.
+     * @param source
+     *          The asset image to preload.
+     * @return The url representing the image that can be safely retrieved by the browser
to see it.
+     */
+    String getPreloadedImageReference(IComponent target, IAsset source);
     
     /**
      * Sets up the given URL to preload, and returns a reference to the loaded image, in
the form of

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/ForBean.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/ForBean.java?view=diff&rev=485258&r1=485257&r2=485258
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/ForBean.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/components/ForBean.java
Sun Dec 10 13:07:10 2006
@@ -79,7 +79,7 @@
     public abstract boolean getRenderTag();
     
     public abstract String getElement();
-
+    
     public abstract String getKeyExpression();
 
     public abstract IPrimaryKeyConverter getConverter();
@@ -556,7 +556,7 @@
         // Check if the string rep is empty. If so, just return the default value.
         if (rep == null || rep.length() == 0)
             return getDefaultValue();
-
+        
         // If required, find a value with an equivalent string representation and return
it
         boolean match = getMatch();
         if (match)
@@ -583,7 +583,7 @@
                 // If the string rep is just the value itself, unsqueeze it
                 value = squeezer.unsqueeze(squeezed);
                 break;
-
+                
             case DESC_PRIMARY_KEY:
                 // Perform keyExpression match if not already attempted
                 if (!match && getKeyExpression() != null)
@@ -635,7 +635,7 @@
         value = findValueWithStringRepInIterator(sourceIterator, repToValueMap, rep, repSource);
         if (value != null)
             return value;
-
+        
         value = findValueWithStringRepInIterator(fullSourceIterator, repToValueMap, rep,
repSource);
         return value;
     }
@@ -662,10 +662,10 @@
             Object sourceValue = it.next();
             if (sourceValue == null)
                 continue;
-
+            
             String sourceRep = repSource.getStringRep(sourceValue);
             repToValueMap.put(sourceRep, sourceValue);
-
+            
             if (rep.equals(sourceRep))
                 return sourceValue;
         }
@@ -686,10 +686,10 @@
         IBinding sourceBinding = getBinding("source");
         if (sourceBinding != null)
             source = sourceBinding.getObject();
-
+        
         if (source != null)
             it = (Iterator) getValueConverter().coerceValue(source, Iterator.class);
-
+        
         if (it == null)
             it = Collections.EMPTY_LIST.iterator();
 

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/DefaultResponseBuilder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/DefaultResponseBuilder.java?view=diff&rev=485258&r1=485257&r2=485258
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/DefaultResponseBuilder.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/DefaultResponseBuilder.java
Sun Dec 10 13:07:10 2006
@@ -18,6 +18,7 @@
 
 import org.apache.hivemind.Resource;
 import org.apache.hivemind.util.Defense;
+import org.apache.tapestry.IAsset;
 import org.apache.tapestry.IComponent;
 import org.apache.tapestry.IMarkupWriter;
 import org.apache.tapestry.IPage;
@@ -248,6 +249,14 @@
     public boolean isImageInitializationAllowed(IComponent target)
     {
         return true;
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public String getPreloadedImageReference(IComponent target, IAsset source)
+    {
+        return _prs.getPreloadedImageReference(target, source);
     }
     
     /**

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/DojoAjaxResponseBuilder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/DojoAjaxResponseBuilder.java?view=diff&rev=485258&r1=485257&r2=485258
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/DojoAjaxResponseBuilder.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/DojoAjaxResponseBuilder.java
Sun Dec 10 13:07:10 2006
@@ -26,6 +26,7 @@
 
 import org.apache.hivemind.Resource;
 import org.apache.hivemind.util.Defense;
+import org.apache.tapestry.IAsset;
 import org.apache.tapestry.IComponent;
 import org.apache.tapestry.IForm;
 import org.apache.tapestry.IMarkupWriter;
@@ -329,6 +330,14 @@
             return true;
         
         return contains(target);
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public String getPreloadedImageReference(IComponent target, IAsset source)
+    {
+        return _prs.getPreloadedImageReference(target, source);
     }
     
     /**

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/JSONResponseBuilder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/JSONResponseBuilder.java?view=diff&rev=485258&r1=485257&r2=485258
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/JSONResponseBuilder.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/JSONResponseBuilder.java
Sun Dec 10 13:07:10 2006
@@ -24,6 +24,7 @@
 
 import org.apache.hivemind.Resource;
 import org.apache.hivemind.util.Defense;
+import org.apache.tapestry.IAsset;
 import org.apache.tapestry.IComponent;
 import org.apache.tapestry.IJSONRender;
 import org.apache.tapestry.IMarkupWriter;
@@ -333,6 +334,14 @@
     public boolean isImageInitializationAllowed(IComponent target)
     {
         return false;
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public String getPreloadedImageReference(IComponent target, IAsset source)
+    {
+        return _prs.getPreloadedImageReference(target, source);
     }
     
     /**

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/util/PageRenderSupportImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/util/PageRenderSupportImpl.java?view=diff&rev=485258&r1=485257&r2=485258
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/util/PageRenderSupportImpl.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/util/PageRenderSupportImpl.java
Sun Dec 10 13:07:10 2006
@@ -107,9 +107,15 @@
         return getPreloadedImageReference(null, URL);
     }
     
+    public String getPreloadedImageReference(IComponent target, IAsset source)
+    {
+        return getPreloadedImageReference(target, source.buildURL());
+    }
+    
     public String getPreloadedImageReference(IComponent target, String URL)
     {
-        if (target != null && !_builder.isImageInitializationAllowed(target))
+        if (target != null 
+                && !_builder.isImageInitializationAllowed(target))
             return URL;
         
         if (_imageMap == null)

Added: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/components/TestForBean.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/components/TestForBean.java?view=auto&rev=485258
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/components/TestForBean.java
(added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/components/TestForBean.java
Sun Dec 10 13:07:10 2006
@@ -0,0 +1,153 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed 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.tapestry.components;
+
+import static org.easymock.EasyMock.*;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.tapestry.BaseComponentTestCase;
+import org.apache.tapestry.IBinding;
+import org.apache.tapestry.IForm;
+import org.apache.tapestry.IMarkupWriter;
+import org.apache.tapestry.IRender;
+import org.apache.tapestry.IRequestCycle;
+import org.apache.tapestry.TapestryUtils;
+import org.apache.tapestry.coerce.ValueConverter;
+import org.apache.tapestry.services.ResponseBuilder;
+import org.apache.tapestry.spec.IComponentSpecification;
+import org.apache.tapestry.spec.IParameterSpecification;
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests functionality of {@link ForBean} .
+ *
+ * @author jkuhnert
+ */
+@Test
+public class TestForBean extends BaseComponentTestCase
+{   
+    public void test_Render()
+    {
+        IRequestCycle cycle = newMock(IRequestCycle.class);
+        IMarkupWriter writer = newBufferWriter();
+        ValueConverter conv = newMock(ValueConverter.class);
+        ResponseBuilder resp = newMock(ResponseBuilder.class);
+        IComponentSpecification spec = newSpec();
+        IParameterSpecification pspec = newMock(IParameterSpecification.class);
+        
+        List src = new ArrayList();
+        src.add("Test1");
+        src.add("Test2");
+        
+        IBinding source = newBinding(src);
+        
+        ForBean bean = newInstance(ForBean.class, new Object[] {
+            "valueConverter", conv,
+            "responseBuilder", resp,
+            "templateTagName", "div",
+            "renderTag", true,
+            "specification", spec
+            });
+        
+        expect(cycle.renderStackPush(bean)).andReturn(bean);
+        
+        expect(cycle.isRewinding()).andReturn(false);
+        
+        expect(cycle.getAttribute(TapestryUtils.FORM_ATTRIBUTE)).andReturn(null);
+        
+        expect(spec.getParameter("source")).andReturn(pspec).anyTimes();
+        
+        expect(conv.coerceValue(src, Iterator.class)).andReturn(src.iterator());
+        
+        expect(resp.isDynamic()).andReturn(false).anyTimes();
+        
+        expect(cycle.getResponseBuilder()).andReturn(resp).anyTimes();
+        
+        IRender body = newMock(IRender.class);
+        
+        resp.render(writer, body, cycle);
+        expectLastCall().anyTimes();
+        
+        expect(cycle.renderStackPop()).andReturn(bean);
+        
+        replay();
+        
+        bean.addBody(body);
+        bean.setBinding("source", source);
+        
+        bean.render(writer, cycle);
+        
+        verify();
+        
+        assertBuffer("<div></div><div></div>");
+    }
+    
+    public void test_Rewind_Missing_Converter()
+    {
+        IRequestCycle cycle = newMock(IRequestCycle.class);
+        IMarkupWriter writer = newWriter();
+        ValueConverter conv = newMock(ValueConverter.class);
+        ResponseBuilder resp = newMock(ResponseBuilder.class);
+        IForm form = newMock(IForm.class);
+        IComponentSpecification spec = newSpec();
+       // IParameterSpecification pspec = newMock(IParameterSpecification.class);
+        
+        List src = new ArrayList();
+        src.add("Test1");
+        src.add("Test2");
+        
+        IBinding source = newBinding(src);
+        
+        ForBean bean = newInstance(ForBean.class, new Object[] {
+            "valueConverter", conv,
+            "responseBuilder", resp,
+            "templateTagName", "div",
+            "renderTag", true,
+            "specification", spec
+            });
+        
+        expect(cycle.renderStackPush(bean)).andReturn(bean);
+        
+        expect(cycle.isRewinding()).andReturn(true).anyTimes();
+        
+        expect(cycle.getAttribute(TapestryUtils.FORM_ATTRIBUTE)).andReturn(form);
+        
+        expect(form.isRewinding()).andReturn(true);
+        
+        expect(form.getElementId(bean)).andReturn("foo");
+        
+        String[] parms = (String[])src.toArray((new String[src.size()]));
+        
+        expect(cycle.getParameters("foo")).andReturn(parms);
+        
+        expect(conv.coerceValue(src, Iterator.class)).andReturn(src.iterator());
+        
+        expect(resp.isDynamic()).andReturn(false).anyTimes();
+        
+        expect(cycle.renderStackPop()).andReturn(bean);
+        
+        replay();
+        
+        // bean.addBody(body);
+        bean.setBinding("source", source);
+        
+        bean.render(writer, cycle);
+        
+        verify();
+    }
+}

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/components/TestIfElse.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/components/TestIfElse.java?view=diff&rev=485258&r1=485257&r2=485258
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/components/TestIfElse.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/components/TestIfElse.java
Sun Dec 10 13:07:10 2006
@@ -44,7 +44,7 @@
         IRender render = newMock(IRender.class);
         
         render.render(writer, cycle);
-
+        
         return render;
     }
 

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/dojo/AjaxShellDelegateTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/dojo/AjaxShellDelegateTest.java?view=diff&rev=485258&r1=485257&r2=485258
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/dojo/AjaxShellDelegateTest.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/dojo/AjaxShellDelegateTest.java
Sun Dec 10 13:07:10 2006
@@ -34,6 +34,7 @@
  * @author jkuhnert
  */
 @Test(sequential=true)
+@SuppressWarnings("all")
 public class AjaxShellDelegateTest extends BaseComponentTestCase
 {
     private static final String SYSTEM_NEWLINE= (String)java.security.AccessController.doPrivileged(

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/TestPageRenderSupport.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/TestPageRenderSupport.java?view=diff&rev=485258&r1=485257&r2=485258
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/TestPageRenderSupport.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/util/TestPageRenderSupport.java
Sun Dec 10 13:07:10 2006
@@ -24,6 +24,7 @@
 import org.apache.hivemind.Resource;
 import org.apache.tapestry.BaseComponentTestCase;
 import org.apache.tapestry.IAsset;
+import org.apache.tapestry.IComponent;
 import org.apache.tapestry.IMarkupWriter;
 import org.apache.tapestry.IRequestCycle;
 import org.apache.tapestry.asset.AssetFactory;
@@ -40,19 +41,20 @@
  * @since 4.0
  */
 @Test(sequential=true)
+@SuppressWarnings("all")
 public class TestPageRenderSupport extends BaseComponentTestCase
 {
     private static final String SYSTEM_NEWLINE= (String)java.security.AccessController.doPrivileged(
             new sun.security.action.GetPropertyAction("line.separator"));
     
     private static final String TEST_NEWLINE= "\n";
-
+    
     private AssetFactory newAssetFactory()
     {
         return newMock(AssetFactory.class);
     }
 
-    private IAsset newAsset(IRequestCycle cycle, String url)
+    private IAsset newAsset(String url)
     {
         IAsset asset = newMock(IAsset.class);
         checkOrder(asset, false);
@@ -126,15 +128,18 @@
         Location l = newLocation();
         IRequestCycle cycle = newCycle();
         IMarkupWriter writer = createWriter();
-
+        
+        IComponent comp = newMock(IComponent.class);
+        IAsset img = newAsset("/zip/zap.png");
+        
         replay();
-
+        
         PageRenderSupportImpl prs = new PageRenderSupportImpl(factory, "", l, newBuilder(writer));
-
+        
         assertEquals(prs.getPreloadedImageReference("/foo/bar.gif"), "tapestry.preload[0].src");
-        assertEquals(prs.getPreloadedImageReference("/zip/zap.png"), "tapestry.preload[1].src");
+        assertEquals(prs.getPreloadedImageReference(comp, img), "tapestry.preload[1].src");
         assertEquals(prs.getPreloadedImageReference("/foo/bar.gif"), "tapestry.preload[0].src");
-
+        
         prs.addBodyScript("myBodyScript();");
 
         prs.writeBodyScript(writer, cycle);
@@ -282,11 +287,11 @@
         AssetFactory assetFactory = newMock(AssetFactory.class);
         
         Resource script1 = newResource();
-        IAsset asset1 = newAsset(cycle, "/script1.js");
+        IAsset asset1 = newAsset("/script1.js");
         
         Resource script2 = newResource();
-        IAsset asset2 = newAsset(cycle, "/script2.js");
-
+        IAsset asset2 = newAsset("/script2.js");
+        
         expect(assetFactory.createAsset(script1, null)).andReturn(asset1);
 
         expect(assetFactory.createAsset(script2, null)).andReturn(asset2);



Mime
View raw message