tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r292966 - in /jakarta/tapestry/trunk: ./ .settings/ framework/src/java/org/apache/tapestry/ framework/src/java/org/apache/tapestry/html/ framework/src/java/org/apache/tapestry/valid/ framework/src/test/org/apache/tapestry/ framework/src/tes...
Date Sat, 01 Oct 2005 12:14:17 GMT
Author: hlship
Date: Sat Oct  1 05:14:07 2005
New Revision: 292966

URL: http://svn.apache.org/viewcvs?rev=292966&view=rev
Log:
TAPESTRY-622: Add streamlined API for recording errors into a validation delegate
TAPESTRY-667: Methods marked deprecated in IComponent need to also be deprecated in AbstractComponent
to avoid compiler warnings (when subclassing)
Add test suites for Frame, Describe and Script components

Added:
    jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/html/DescribeTest.java
    jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/html/FrameTest.java
    jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/html/ScriptTest.java
    jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/valid/ValidationDelegateTest.java
      - copied, changed from r292042, jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/valid/TestValidationDelegate.java
Removed:
    jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/valid/TestValidationDelegate.java
Modified:
    jakarta/tapestry/trunk/.settings/org.eclipse.jdt.core.prefs
    jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/AbstractComponent.java
    jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Frame.java
    jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Frame.jwc
    jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Script.java
    jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Script.jwc
    jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/valid/IValidationDelegate.java
    jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/valid/ValidationDelegate.java
    jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/BaseComponentTestCase.java
    jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/form/MockDelegate.java
    jakarta/tapestry/trunk/status.xml

Modified: jakarta/tapestry/trunk/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/.settings/org.eclipse.jdt.core.prefs?rev=292966&r1=292965&r2=292966&view=diff
==============================================================================
--- jakarta/tapestry/trunk/.settings/org.eclipse.jdt.core.prefs (original)
+++ jakarta/tapestry/trunk/.settings/org.eclipse.jdt.core.prefs Sat Oct  1 05:14:07 2005
@@ -1,4 +1,4 @@
-#Thu Aug 25 21:35:11 PDT 2005
+#Fri Sep 30 15:48:02 EDT 2005
 eclipse.preferences.version=1
 org.eclipse.jdt.core.codeComplete.argumentPrefixes=
 org.eclipse.jdt.core.codeComplete.argumentSuffixes=
@@ -18,7 +18,7 @@
 org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
 org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
-org.eclipse.jdt.core.compiler.problem.deprecation=ignore
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
 org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
 org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
 org.eclipse.jdt.core.compiler.problem.discouragedReference=error

Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/AbstractComponent.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/AbstractComponent.java?rev=292966&r1=292965&r2=292966&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/AbstractComponent.java (original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/AbstractComponent.java Sat
Oct  1 05:14:07 2005
@@ -710,6 +710,7 @@
      * 
      * @see IComponent
      * @since 3.0
+     * @deprecated
      */
     public void setProperty(String propertyName, Object value)
     {
@@ -721,6 +722,7 @@
      * 
      * @see IComponent
      * @since 3.0
+     * @deprecated
      */
     public Object getProperty(String propertyName)
     {

Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Frame.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Frame.java?rev=292966&r1=292965&r2=292966&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Frame.java (original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Frame.java Sat Oct
 1 05:14:07 2005
@@ -15,10 +15,8 @@
 package org.apache.tapestry.html;
 
 import org.apache.tapestry.AbstractComponent;
-import org.apache.tapestry.IEngine;
 import org.apache.tapestry.IMarkupWriter;
 import org.apache.tapestry.IRequestCycle;
-import org.apache.tapestry.Tapestry;
 import org.apache.tapestry.engine.IEngineService;
 import org.apache.tapestry.engine.ILink;
 
@@ -31,13 +29,16 @@
 
 public abstract class Frame extends AbstractComponent
 {
+    /**
+     * Injected engine service.
+     * 
+     * @since 4.0
+     */
+    public abstract IEngineService getPageService();
+
     protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
     {
-        if (cycle.isRewinding())
-            return;
-
-        IEngine engine = cycle.getEngine();
-        IEngineService pageService = engine.getService(Tapestry.PAGE_SERVICE);
+        IEngineService pageService = getPageService();
         ILink link = pageService.getLink(cycle, false, getTargetPage());
 
         writer.beginEmpty("frame");

Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Frame.jwc
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Frame.jwc?rev=292966&r1=292965&r2=292966&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Frame.jwc (original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Frame.jwc Sat Oct 
1 05:14:07 2005
@@ -19,7 +19,7 @@
   "-//Apache Software Foundation//Tapestry Specification 4.0//EN" 
   "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
 	
-<component-specification class="org.apache.tapestry.html.Frame" 
+<component-specification class="org.apache.tapestry.html.Frame"
     allow-body="no"
     allow-informal-parameters="yes">
 
@@ -34,5 +34,7 @@
   </parameter>
   
   <reserved-parameter name="src"/>
+  
+  <inject property="pageService" object="engine-service:page"/>
   
 </component-specification>

Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Script.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Script.java?rev=292966&r1=292965&r2=292966&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Script.java (original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Script.java Sat Oct
 1 05:14:07 2005
@@ -42,6 +42,14 @@
 public abstract class Script extends AbstractComponent
 {
     /**
+     * Injected
+     * 
+     * @since 4.0
+     */
+
+    public abstract IScriptSource getScriptSource();
+
+    /**
      * A Map of input and output symbols visible to the body of the Script.
      * 
      * @since 2.2
@@ -93,15 +101,14 @@
      * Gets the {@link IScript}for the correct script.
      */
 
-    private IScript getParsedScript(IRequestCycle cycle)
+    private IScript getParsedScript()
     {
         String scriptPath = getScriptPath();
 
         if (scriptPath == null)
             throw Tapestry.createRequiredParameterException(this, "scriptPath");
 
-        IEngine engine = cycle.getEngine();
-        IScriptSource source = engine.getScriptSource();
+        IScriptSource source = getScriptSource();
 
         // If the script path is relative, it should be relative to the Script component's
         // container (i.e., relative to a page in the application).
@@ -115,7 +122,8 @@
         }
         catch (RuntimeException ex)
         {
-            throw new ApplicationRuntimeException(ex.getMessage(), this, null, ex);
+            throw new ApplicationRuntimeException(ex.getMessage(), this, getBinding("script")
+                    .getLocation(), ex);
         }
 
     }
@@ -128,7 +136,7 @@
 
             _symbols = getInputSymbols();
 
-            getParsedScript(cycle).execute(cycle, pageRenderSupport, _symbols);
+            getParsedScript().execute(cycle, pageRenderSupport, _symbols);
         }
 
         // Render the body of the Script;

Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Script.jwc
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Script.jwc?rev=292966&r1=292965&r2=292966&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Script.jwc (original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/Script.jwc Sat Oct
 1 05:14:07 2005
@@ -38,4 +38,6 @@
     </description>
   </parameter>
 
+  <inject property="scriptSource" object="infrastructure:scriptSource"/>
+  
 </component-specification>

Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/valid/IValidationDelegate.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/valid/IValidationDelegate.java?rev=292966&r1=292965&r2=292966&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/valid/IValidationDelegate.java
(original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/valid/IValidationDelegate.java
Sat Oct  1 05:14:07 2005
@@ -183,6 +183,19 @@
     public void record(String message, ValidationConstraint constraint);
 
     /**
+     * Convienience for recording a standard string messages against a field.
+     * 
+     * @param field
+     *            the field to record the error message against, or null to record an unassociated
+     *            error
+     * @param message
+     *            the error message to record
+     * @since 4.0
+     */
+
+    public void record(IFormComponent field, String message);
+
+    /**
      * Records an error in the current component, or an unassociated error. The maximum flexibility
      * recorder.
      * 

Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/valid/ValidationDelegate.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/valid/ValidationDelegate.java?rev=292966&r1=292965&r2=292966&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/valid/ValidationDelegate.java
(original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/valid/ValidationDelegate.java
Sat Oct  1 05:14:07 2005
@@ -223,6 +223,15 @@
         tracking.setConstraint(constraint);
     }
 
+    /** @since 4.0 */
+
+    public void record(IFormComponent field, String message)
+    {
+        setFormComponent(field);
+
+        record(message, null);
+    }
+
     public void recordFieldInputValue(String input)
     {
         FieldTracking tracking = findCurrentTracking();

Modified: jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/BaseComponentTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/BaseComponentTestCase.java?rev=292966&r1=292965&r2=292966&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/BaseComponentTestCase.java
(original)
+++ jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/BaseComponentTestCase.java
Sat Oct  1 05:14:07 2005
@@ -20,7 +20,10 @@
 import org.apache.hivemind.ClassResolver;
 import org.apache.hivemind.Locatable;
 import org.apache.hivemind.Location;
+import org.apache.hivemind.Resource;
 import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.tapestry.engine.IEngineService;
+import org.apache.tapestry.engine.ILink;
 import org.apache.tapestry.markup.AsciiMarkupFilter;
 import org.apache.tapestry.markup.MarkupWriterImpl;
 import org.apache.tapestry.spec.IComponentSpecification;
@@ -102,7 +105,7 @@
     protected void trainIsRewinding(IRequestCycle cycle, boolean rewinding)
     {
         cycle.isRewinding();
-        setReturnValue(cycle,rewinding);
+        setReturnValue(cycle, rewinding);
     }
 
     protected IRequestCycle newCycleGetPage(String pageName, IPage page)
@@ -279,14 +282,14 @@
     {
         page.getPageName();
 
-        setReturnValue(page,pageName);
+        setReturnValue(page, pageName);
     }
 
     protected void trainBuildURL(IAsset asset, IRequestCycle cycle, String URL)
     {
         asset.buildURL(cycle);
 
-        setReturnValue(asset,URL);
+        setReturnValue(asset, URL);
     }
 
     protected IAsset newAsset()
@@ -299,7 +302,7 @@
         IEngine engine = (IEngine) newMock(IEngine.class);
 
         engine.getClassResolver();
-        setReturnValue(engine,resolver);
+        setReturnValue(engine, resolver);
 
         return engine;
     }
@@ -308,7 +311,7 @@
     {
         page.getEngine();
 
-        setReturnValue(page,engine);
+        setReturnValue(page, engine);
     }
 
     protected IComponent newComponent()
@@ -319,19 +322,19 @@
     protected void trainGetPage(IComponent component, IPage page)
     {
         component.getPage();
-        setReturnValue(component,page);
+        setReturnValue(component, page);
     }
 
     protected void trainGetExtendedId(IComponent component, String extendedId)
     {
         component.getExtendedId();
-        setReturnValue(component,extendedId);
+        setReturnValue(component, extendedId);
     }
 
     protected void trainGetLocation(Locatable locatable, Location location)
     {
         locatable.getLocation();
-        setReturnValue(locatable,location);
+        setReturnValue(locatable, location);
     }
 
     protected IBinding newBinding()
@@ -342,6 +345,44 @@
     protected void trainGetComponent(IComponent container, String componentId, IComponent
containee)
     {
         container.getComponent(componentId);
-        setReturnValue(container,containee);
+        setReturnValue(container, containee);
+    }
+
+    protected IEngineService newEngineService()
+    {
+        return (IEngineService) newMock(IEngineService.class);
+    }
+
+    protected void trainGetLink(IEngineService service, IRequestCycle cycle, boolean post,
Object parameter, ILink link)
+    {
+        service.getLink(cycle, post, parameter);
+        setReturnValue(service, link);
+    }
+
+    protected void trainGetURL(ILink link, String URL)
+    {
+        link.getURL();
+        setReturnValue(link, URL);
+    }
+
+    protected ILink newLink()
+    {
+        ILink link = (ILink) newMock(ILink.class);
+        return link;
+    }
+
+    protected void trainGetPageRenderSupport(IRequestCycle cycle, PageRenderSupport support)
+    {
+        trainGetAttribute(cycle, TapestryUtils.PAGE_RENDER_SUPPORT_ATTRIBUTE, support);
+    }
+
+    protected IComponentSpecification newSpec()
+    {
+        return (IComponentSpecification) newMock(IComponentSpecification.class);
+    }
+
+    protected Resource newResource()
+    {
+        return (Resource) newMock(Resource.class);
     }
 }

Modified: jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/form/MockDelegate.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/form/MockDelegate.java?rev=292966&r1=292965&r2=292966&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/form/MockDelegate.java (original)
+++ jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/form/MockDelegate.java Sat
Oct  1 05:14:07 2005
@@ -157,4 +157,10 @@
     {
     }
 
+    public void record(IFormComponent field, String message)
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
 }

Added: jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/html/DescribeTest.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/html/DescribeTest.java?rev=292966&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/html/DescribeTest.java (added)
+++ jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/html/DescribeTest.java Sat
Oct  1 05:14:07 2005
@@ -0,0 +1,63 @@
+// Copyright 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.html;
+
+import org.apache.tapestry.BaseComponentTestCase;
+import org.apache.tapestry.IMarkupWriter;
+import org.apache.tapestry.IRequestCycle;
+import org.apache.tapestry.describe.HTMLDescriber;
+
+/**
+ * Tests for {@link org.apache.tapestry.html.Describe}.
+ * 
+ * @author Howard M. Lewis Ship
+ */
+public class DescribeTest extends BaseComponentTestCase
+{
+    public void testRewinding()
+    {
+        IMarkupWriter writer = newWriter();
+        IRequestCycle cycle = newCycle(true);
+
+        replayControls();
+
+        Describe component = (Describe) newInstance(Describe.class);
+
+        component.renderComponent(writer, cycle);
+
+        verifyControls();
+    }
+
+    public void testRender()
+    {
+        IMarkupWriter writer = newWriter();
+        IRequestCycle cycle = newCycle(false);
+
+        Object object = new Object();
+
+        HTMLDescriber describer = (HTMLDescriber) newMock(HTMLDescriber.class);
+
+        describer.describeObject(object, writer);
+
+        replayControls();
+
+        Describe component = (Describe) newInstance(Describe.class, new Object[]
+        { "object", object, "describer", describer });
+
+        component.renderComponent(writer, cycle);
+
+        verifyControls();
+    }
+}

Added: jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/html/FrameTest.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/html/FrameTest.java?rev=292966&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/html/FrameTest.java (added)
+++ jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/html/FrameTest.java Sat
Oct  1 05:14:07 2005
@@ -0,0 +1,89 @@
+// Copyright 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.html;
+
+import org.apache.tapestry.BaseComponentTestCase;
+import org.apache.tapestry.IBinding;
+import org.apache.tapestry.IMarkupWriter;
+import org.apache.tapestry.IRequestCycle;
+import org.apache.tapestry.engine.IEngineService;
+import org.apache.tapestry.engine.ILink;
+import org.apache.tapestry.spec.ComponentSpecification;
+
+/**
+ * Tests for the {@link org.apache.tapestry.html.Frame} component.
+ * 
+ * @author Howard M. Lewis Ship
+ * @since 4.0
+ */
+public class FrameTest extends BaseComponentTestCase
+{
+
+    public void testRender()
+    {
+        IEngineService pageService = newEngineService();
+        ILink link = newLink();
+
+        IMarkupWriter writer = newWriter();
+        IRequestCycle cycle = newCycle();
+
+        trainGetLink(pageService, cycle, false, "FramePage", link);
+        trainGetURL(link, "<LinkURL>");
+
+        writer.beginEmpty("frame");
+        writer.attribute("src", "<LinkURL>");
+
+        writer.closeTag();
+
+        replayControls();
+
+        Frame frame = (Frame) newInstance(Frame.class, new Object[]
+        { "pageService", pageService, "targetPage", "FramePage" });
+
+        frame.renderComponent(writer, cycle);
+
+        verifyControls();
+    }
+
+    public void testRenderWithInformal()
+    {
+        IBinding binding = newBinding("informal");
+        IEngineService pageService = newEngineService();
+        ILink link = newLink();
+
+        IMarkupWriter writer = newWriter();
+        IRequestCycle cycle = newCycle();
+
+        trainGetLink(pageService, cycle, false, "FramePage", link);
+        trainGetURL(link, "<LinkURL>");
+
+        writer.beginEmpty("frame");
+        writer.attribute("src", "<LinkURL>");
+        writer.attribute("class", "informal");
+
+        writer.closeTag();
+
+        replayControls();
+
+        Frame frame = (Frame) newInstance(Frame.class, new Object[]
+        { "pageService", pageService, "targetPage", "FramePage", "specification",
+                new ComponentSpecification() });
+        frame.setBinding("class", binding);
+
+        frame.renderComponent(writer, cycle);
+
+        verifyControls();
+    }
+}

Added: jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/html/ScriptTest.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/html/ScriptTest.java?rev=292966&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/html/ScriptTest.java (added)
+++ jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/html/ScriptTest.java Sat
Oct  1 05:14:07 2005
@@ -0,0 +1,242 @@
+// Copyright 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.html;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.hivemind.Resource;
+import org.apache.tapestry.BaseComponentTestCase;
+import org.apache.tapestry.IBinding;
+import org.apache.tapestry.IComponent;
+import org.apache.tapestry.IMarkupWriter;
+import org.apache.tapestry.IRender;
+import org.apache.tapestry.IRequestCycle;
+import org.apache.tapestry.IScript;
+import org.apache.tapestry.IScriptProcessor;
+import org.apache.tapestry.PageRenderSupport;
+import org.apache.tapestry.engine.IScriptSource;
+import org.apache.tapestry.spec.ComponentSpecification;
+import org.apache.tapestry.spec.IComponentSpecification;
+
+/**
+ * Tests for the {@link Script} component.
+ * 
+ * @author Howard M. Lewis Ship
+ * @since 4.0
+ */
+public class ScriptTest extends BaseComponentTestCase
+{
+    private static class MockScript implements IScript
+    {
+        Map _symbols;
+
+        public void execute(IRequestCycle cycle, IScriptProcessor processor, Map symbols)
+        {
+            _symbols = symbols;
+        }
+
+        public Resource getScriptResource()
+        {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+    }
+
+    /**
+     * No input symbols, no informal parameters.
+     */
+    public void testMinimalRender()
+    {
+        IScriptSource source = newScriptSource();
+        IScript script = newScript();
+
+        PageRenderSupport support = newPageRenderSupport();
+        IRequestCycle cycle = newCycle(false);
+        IMarkupWriter writer = newWriter();
+        Resource scriptLocation = newResource();
+        IRender body = newRender();
+
+        IComponent container = newComponent();
+
+        String scriptPath = "MyScript.script";
+
+        Script component = (Script) newInstance(Script.class, new Object[]
+        { "specification", new ComponentSpecification(), "container", container, "scriptSource",
+                source, "scriptPath", scriptPath });
+
+        trainGetPageRenderSupport(cycle, support);
+
+        trainGetScriptLocation(container, scriptPath, scriptLocation);
+
+        trainGetScript(source, scriptLocation, script);
+
+        script.execute(cycle, support, new HashMap());
+
+        body.render(writer, cycle);
+
+        replayControls();
+
+        component.addBody(body);
+
+        component.renderComponent(writer, cycle);
+
+        verifyControls();
+    }
+
+    public void testWithSymbolsMap()
+    {
+        IScriptSource source = newScriptSource();
+        MockScript script = new MockScript();
+
+        PageRenderSupport support = newPageRenderSupport();
+        IRequestCycle cycle = newCycle(false);
+        IMarkupWriter writer = newWriter();
+        Resource scriptLocation = newResource();
+        IRender body = newRender();
+
+        IComponent container = newComponent();
+
+        Map baseSymbols = new HashMap();
+        baseSymbols.put("fred", "barney");
+
+        String scriptPath = "MyScript.script";
+
+        Script component = (Script) newInstance(Script.class, new Object[]
+        { "specification", new ComponentSpecification(), "container", container, "scriptSource",
+                source, "scriptPath", scriptPath, "baseSymbols", baseSymbols });
+
+        trainGetPageRenderSupport(cycle, support);
+
+        trainGetScriptLocation(container, scriptPath, scriptLocation);
+
+        trainGetScript(source, scriptLocation, script);
+
+        body.render(writer, cycle);
+
+        replayControls();
+
+        component.addBody(body);
+
+        component.renderComponent(writer, cycle);
+
+        verifyControls();
+
+        assertEquals(baseSymbols, script._symbols);
+        assertSame(script._symbols, component.getSymbols());
+        assertNotSame(baseSymbols, script._symbols);
+    }
+
+    public void testWithSymbolsMapAndInformalParameters()
+    {
+        IScriptSource source = newScriptSource();
+        MockScript script = new MockScript();
+
+        PageRenderSupport support = newPageRenderSupport();
+        IRequestCycle cycle = newCycle(false);
+        IMarkupWriter writer = newWriter();
+        Resource scriptLocation = newResource();
+        IRender body = newRender();
+
+        IComponent container = newComponent();
+
+        Map baseSymbols = new HashMap();
+        baseSymbols.put("fred", "flintstone");
+        baseSymbols.put("flash", "gordon");
+
+        IBinding informal = newBinding("mercury");
+
+        String scriptPath = "MyScript.script";
+
+        Script component = (Script) newInstance(Script.class, new Object[]
+        { "specification", new ComponentSpecification(), "container", container, "scriptSource",
+                source, "scriptPath", scriptPath, "baseSymbols", baseSymbols });
+        component.setBinding("fred", informal);
+
+        trainGetPageRenderSupport(cycle, support);
+
+        trainGetScriptLocation(container, scriptPath, scriptLocation);
+
+        trainGetScript(source, scriptLocation, script);
+
+        body.render(writer, cycle);
+
+        replayControls();
+
+        component.addBody(body);
+
+        component.renderComponent(writer, cycle);
+
+        verifyControls();
+
+        Map expectedSymbols = new HashMap(baseSymbols);
+        expectedSymbols.put("fred", "mercury");
+
+        assertEquals(expectedSymbols, script._symbols);
+        assertSame(script._symbols, component.getSymbols());
+    }
+
+    public void testRewinding()
+    {
+        IMarkupWriter writer = newWriter();
+        IRequestCycle cycle = newCycle(true);
+        IRender body = newRender();
+
+        body.render(writer, cycle);
+
+        replayControls();
+
+        Script component = (Script) newInstance(Script.class);
+
+        component.addBody(body);
+
+        component.renderComponent(writer, cycle);
+
+        verifyControls();
+    }
+
+    protected IScript newScript()
+    {
+        return (IScript) newMock(IScript.class);
+    }
+
+    protected void trainGetScript(IScriptSource source, Resource scriptLocation, IScript
script)
+    {
+        source.getScript(scriptLocation);
+        setReturnValue(source, script);
+    }
+
+    protected IScriptSource newScriptSource()
+    {
+        return (IScriptSource) newMock(IScriptSource.class);
+    }
+
+    protected void trainGetScriptLocation(IComponent component, String scriptPath,
+            Resource scriptLocation)
+    {
+        IComponentSpecification spec = newSpec();
+        Resource resource = newResource();
+
+        component.getSpecification();
+        setReturnValue(component, spec);
+
+        spec.getSpecificationLocation();
+        setReturnValue(spec, resource);
+
+        resource.getRelativeResource(scriptPath);
+        setReturnValue(resource, scriptLocation);
+    }
+}

Copied: jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/valid/ValidationDelegateTest.java
(from r292042, jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/valid/TestValidationDelegate.java)
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/valid/ValidationDelegateTest.java?p2=jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/valid/ValidationDelegateTest.java&p1=jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/valid/TestValidationDelegate.java&r1=292042&r2=292966&rev=292966&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/valid/TestValidationDelegate.java
(original)
+++ jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/valid/ValidationDelegateTest.java
Sat Oct  1 05:14:07 2005
@@ -27,7 +27,7 @@
  * @since 1.0.8
  */
 
-public class TestValidationDelegate extends BaseValidatorTestCase
+public class ValidationDelegateTest extends BaseValidatorTestCase
 {
     protected IFormComponent newField(String name, int count)
     {
@@ -370,5 +370,62 @@
         control.setReturnValue(clientId);
 
         return field;
+    }
+
+    /**
+     * Test {@link ValidationDelegate#record(IFormComponent, String)}.
+     * 
+     * @since 4.0
+     */
+    public void testSimpleRecord()
+    {
+        IFormComponent field = newField();
+
+        trainGetName(field, "myField");
+        trainGetName(field, "myField");
+
+        replayControls();
+
+        ValidationDelegate delegate = new ValidationDelegate();
+
+        delegate.record(field, "My Error Message");
+
+        List list = delegate.getFieldTracking();
+
+        assertEquals(1, list.size());
+
+        IFieldTracking ft = (IFieldTracking) list.get(0);
+
+        assertEquals(true, ft.isInError());
+        assertSame(field, ft.getComponent());
+        assertNull(ft.getConstraint());
+        assertEquals("My Error Message", ft.getErrorRenderer().toString());
+
+        verifyControls();
+    }
+
+    public void testSimpleRecordUnassociated()
+    {
+        ValidationDelegate delegate = new ValidationDelegate();
+
+        delegate.record(null, "My Error Message");
+
+        List list = delegate.getUnassociatedTrackings();
+
+        assertEquals(1, list.size());
+
+        IFieldTracking ft = (IFieldTracking) list.get(0);
+
+        assertEquals(true, ft.isInError());
+        assertNull(ft.getComponent());
+        assertNull(ft.getConstraint());
+        assertEquals("My Error Message", ft.getErrorRenderer().toString());
+
+    }
+
+    protected void trainGetName(IFormComponent field, String name)
+    {
+        field.getName();
+        setReturnValue(field, name);
     }
 }

Modified: jakarta/tapestry/trunk/status.xml
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/status.xml?rev=292966&r1=292965&r2=292966&view=diff
==============================================================================
--- jakarta/tapestry/trunk/status.xml (original)
+++ jakarta/tapestry/trunk/status.xml Sat Oct  1 05:14:07 2005
@@ -59,6 +59,8 @@
       <action type="update" dev="HLS">Re-organize Tapestry project site navigation
to be more consistent</action>
       <action type="update" dev="HLS">Rework build to create an seperate Tapestry examples
distribution (which will be hosted from a non-ASF host)</action>
       <action type="fix" dev="DS" fixes-bug="TAPESTRY-492">Document MaskEdit component</action>
+      <action type="fix" dev="HLS" fixes-bug="TAPESTRY-622">Add streamlined API for
recording errors into a validation delegate</action>
+      <action type="fix" dev="HLS" fixes-bug="TAPESTRY-667">Methods marked deprecated
in IComponent need to also be deprecated in AbstractComponent to avoid compiler warnings (when
subclassing)</action>
     </release>
     <release version="4.0-beta-8" date="Sep 24 2005">
       <action type="fix" dev="DS" fixes-bug="TAPESTRY-465">Document Foreach component</action>



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


Mime
View raw message