Kent,

Really would have liked to see some kind of discussion about the PageTester
before it went fully into the code base since it seems a bit intrusive.

I'm finding the changes to Element to be a little strange.  setSrcObject() /
getSrc() ... is it intentional that the names are different?  Why "src" ...
that's not mneumonic or descriptive.  Is this even necessary ... it seems
like you could maintain a Map inside the page tester from element to Object
and not clutter the Element API with this.

On the whole, these look like useful changes, I'm anxious to see how the
page tester works out.

On 12/18/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

Author: freemant
Date: Mon Dec 18 07:08:35 2006
New Revision: 488300

URL: http://svn.apache.org/viewvc?view=rev&rev=488300
Log:
1) Changed PageTester to use a StrategyRegistry.
2) Changed to use an Object[] instead of List<?> to store a context.
3) Fixed a typo in the component event doc page.

Added:

    
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/ActionLinkClicker.java

    
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/LinkClicker.java

    
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageLinkClicker.java
Modified:

    
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandler.java

    
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandlerImpl.java

    
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkPathSource.java

    
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentEventDispatcher.java

    
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LinkFactoryImpl.java

    
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLinkHandler.java

    
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLinkHandlerImpl.java

    
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLinkPathSource.java

    
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageRenderDispatcher.java

    
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/FooContextPathSource.java

    
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/NoOpURLEncoder.java

    
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageTester.java
    tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/event.apt

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandler.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandler.java?view=diff&rev=488300&r1=488299&r2=488300

==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandler.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandler.java
Mon Dec 18 07:08:35 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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.internal.services;

import org.apache.tapestry.Link;

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandlerImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandlerImpl.java?view=diff&rev=488300&r1=488299&r2=488300

==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandlerImpl.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandlerImpl.java
Mon Dec 18 07:08:35 2006
@@ -34,7 +34,7 @@

         element.triggerEvent(
                 pathSource.getAction(),
-                pathSource.getContext().toArray(),
+                pathSource.getContext(),
                 _componentEventHandler);

         // It's possible that the component event will have changed the
active page.

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkPathSource.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkPathSource.java?view=diff&rev=488300&r1=488299&r2=488300

==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkPathSource.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkPathSource.java
Mon Dec 18 07:08:35 2006
@@ -14,7 +14,6 @@

package org.apache.tapestry.internal.services;

-import java.util.List;

public class ActionLinkPathSource implements PathSource
{
@@ -27,10 +26,10 @@

     private final String _componentNestedId;

-    private final List<?> _context;
+    private final Object[] _context;

     public ActionLinkPathSource(String contextPath, String action, String
pageName, String componentNestedId,
-            List<?> context)
+            Object[] context)
     {
         _contextPath = contextPath;
         _action = action;
@@ -73,7 +72,7 @@
         return _componentNestedId;
     }

-    public List<?> getContext()
+    public Object[] getContext()
     {
         return _context;
     }

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentEventDispatcher.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentEventDispatcher.java?view=diff&rev=488300&r1=488299&r2=488300

==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentEventDispatcher.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentEventDispatcher.java
Mon Dec 18 07:08:35 2006
@@ -15,7 +15,6 @@
package org.apache.tapestry.internal.services;

import java.io.IOException;
-import java.util.Arrays;

import org.apache.tapestry.Link;
import org.apache.tapestry.services.Dispatcher;
@@ -63,7 +62,7 @@
             context[i - 1] = chunks[i];

         Link link = _actionLinkHandler.handle(new
ActionLinkPathSource(null, eventType,
-                logicalPageName, nestedComponentId, Arrays.asList
(context)));
+                logicalPageName, nestedComponentId, context));

         String URL = link.toRedirectURI();


Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LinkFactoryImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LinkFactoryImpl.java?view=diff&rev=488300&r1=488299&r2=488300

==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LinkFactoryImpl.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LinkFactoryImpl.java
Mon Dec 18 07:08:35 2006
@@ -18,7 +18,6 @@
import static
org.apache.tapestry.ioc.internal.util.CollectionFactory.newMap;
import static
org.apache.tapestry.ioc.internal.util.CollectionFactory.newThreadSafeList;

-import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -106,8 +105,7 @@
         String logicalPageName =
_componentClassResolver.resolvePageClassNameToPageName(pageName);

         ActionLinkPathSource pathSource = new
ActionLinkPathSource(_contextPathSource
-                .getContextPath(), action, logicalPageName,
component.getNestedId(), Arrays
-                .asList(context));
+                .getContextPath(), action, logicalPageName,
component.getNestedId(), context);

         Link link = new LinkImpl(_encoder, pathSource);

@@ -144,7 +142,8 @@

         rootElement.triggerEvent(TapestryConstants.PASSIVATE_EVENT, null,
handler);

-        PageLinkPathSource pathSource = new
PageLinkPathSource(_contextPathSource.getContextPath(), logicalPageName,
context);
+        PageLinkPathSource pathSource = new
PageLinkPathSource(_contextPathSource.getContextPath(),
+                logicalPageName, context.toArray());

         Link link = new LinkImpl(_encoder, pathSource);


Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLinkHandler.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLinkHandler.java?view=diff&rev=488300&r1=488299&r2=488300

==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLinkHandler.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLinkHandler.java
Mon Dec 18 07:08:35 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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.internal.services;

public interface PageLinkHandler

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLinkHandlerImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLinkHandlerImpl.java?view=diff&rev=488300&r1=488299&r2=488300

==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLinkHandlerImpl.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLinkHandlerImpl.java
Mon Dec 18 07:08:35 2006
@@ -37,7 +37,7 @@

         page.getRootElement().triggerEvent(
                 TapestryConstants.ACTIVATE_EVENT,
-                pathSource.getContext().toArray(),
+                pathSource.getContext(),
                 null);

         renderer.renderPage(page);

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLinkPathSource.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLinkPathSource.java?view=diff&rev=488300&r1=488299&r2=488300

==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLinkPathSource.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLinkPathSource.java
Mon Dec 18 07:08:35 2006
@@ -14,7 +14,6 @@

package org.apache.tapestry.internal.services;

-import java.util.List;

public class PageLinkPathSource implements PathSource
{
@@ -23,9 +22,9 @@

     private final String _pageName;

-    private final List<?> _context;
+    private final Object[] _context;

-    public PageLinkPathSource(String contextPath, String pageName,
List<?> context)
+    public PageLinkPathSource(String contextPath, String pageName,
Object[] context)
     {
         _contextPath = contextPath;
         _pageName = pageName;
@@ -53,7 +52,7 @@
         return builder.toString();
     }

-    public List<?> getContext()
+    public Object[] getContext()
     {
         return _context;
     }

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageRenderDispatcher.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageRenderDispatcher.java?view=diff&rev=488300&r1=488299&r2=488300

==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageRenderDispatcher.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageRenderDispatcher.java
Mon Dec 18 07:08:35 2006
@@ -15,7 +15,6 @@
package org.apache.tapestry.internal.services;

import java.io.IOException;
-import java.util.Arrays;

import org.apache.tapestry.internal.structure.Page;
import org.apache.tapestry.services.Dispatcher;
@@ -65,24 +64,22 @@
             // TODO: Decode strings?
             context[i - 1] = terms[i];
         }
-        _handler.handle(
-                new PageLinkPathSource(null, logicalPageName,
Arrays.asList(context)),
-                new PageRenderer()
-                {
+        _handler.handle(new PageLinkPathSource(null, logicalPageName,
context), new PageRenderer()
+        {

-                    public void renderPage(Page page)
-                    {
-                        try
-                        {
-                            _renderer.renderPageResponse(page, response);
-                        }
-                        catch (IOException ex)
-                        {
-                            new RuntimeException(ex);
-                        }
+            public void renderPage(Page page)
+            {
+                try
+                {
+                    _renderer.renderPageResponse(page, response);
+                }
+                catch (IOException ex)
+                {
+                    new RuntimeException(ex);
+                }

-                    }
-                });
+            }
+        });

         return true;
     }

Added:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/ActionLinkClicker.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/ActionLinkClicker.java?view=auto&rev=488300

==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/ActionLinkClicker.java
(added)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/ActionLinkClicker.java
Mon Dec 18 07:08:35 2006
@@ -0,0 +1,68 @@
+// Copyright 2006 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.test.pagelevel;
+
+import org.apache.tapestry.Link;
+import org.apache.tapestry.dom.Document;
+import org.apache.tapestry.internal.services.ActionLinkHandler;
+import org.apache.tapestry.internal.services.ActionLinkPathSource;
+import org.apache.tapestry.internal.services.LinkImpl;
+import org.apache.tapestry.internal.services.PathSource;
+import org.apache.tapestry.ioc.Registry;
+
+/**
+ * Simulates a click on an action link.
+ */
+public class ActionLinkClicker implements LinkClicker
+{
+    private final Registry _registry;
+
+    private final PageLinkClicker _pageLinkClicker;
+
+    private final ActionLinkHandler _actionLinkHandler;
+
+    public ActionLinkClicker(Registry registry, PageLinkClicker
pageLinkClicker)
+    {
+        _registry = registry;
+        _pageLinkClicker = pageLinkClicker;
+        _actionLinkHandler = _registry.getService(ActionLinkHandler.class
);
+    }
+
+    /**
+     * Click on the action link and get a page link in return. Then use
the [EMAIL PROTECTED] PageLinkClicker}
+     * to click the page link.
+     *
+     * @param pageSource
+     *            The path source for the action link.
+     * @return The DOM created. Typically you will assert against it.
+     */
+    public Document click(PathSource pathSource)
+    {
+        Link pageLink = click((ActionLinkPathSource) pathSource);
+        return _pageLinkClicker.click(((LinkImpl)
pageLink).getPathSource());
+    }
+
+    private Link click(ActionLinkPathSource pathSource)
+    {
+        try
+        {
+            return _actionLinkHandler.handle(pathSource);
+        }
+        finally
+        {
+            _registry.cleanupThread();
+        }
+    }
+}

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/FooContextPathSource.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/FooContextPathSource.java?view=diff&rev=488300&r1=488299&r2=488300

==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/FooContextPathSource.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/FooContextPathSource.java
Mon Dec 18 07:08:35 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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.test.pagelevel;

import org.apache.tapestry.internal.services.ContextPathSource;

Added:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/LinkClicker.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/LinkClicker.java?view=auto&rev=488300

==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/LinkClicker.java
(added)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/LinkClicker.java
Mon Dec 18 07:08:35 2006
@@ -0,0 +1,32 @@
+// Copyright 2006 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.test.pagelevel;
+
+import org.apache.tapestry.dom.Document;
+import org.apache.tapestry.internal.services.PathSource;
+
+/**
+ * Simulates a click on a link.
+ */
+public interface LinkClicker
+{
+    /**
+     * @param pageSource
+     *            The path source for the link.
+     * @return The DOM created. Typically you will assert against it.
+     */
+    Document click(PathSource pathSource);
+
+}

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/NoOpURLEncoder.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/NoOpURLEncoder.java?view=diff&rev=488300&r1=488299&r2=488300

==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/NoOpURLEncoder.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/NoOpURLEncoder.java
Mon Dec 18 07:08:35 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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.test.pagelevel;

import org.apache.tapestry.internal.services.URLEncoder;

Added:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageLinkClicker.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageLinkClicker.java?view=auto&rev=488300

==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageLinkClicker.java
(added)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageLinkClicker.java
Mon Dec 18 07:08:35 2006
@@ -0,0 +1,74 @@
+// Copyright 2006 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.test.pagelevel;
+
+import org.apache.tapestry.dom.Document;
+import org.apache.tapestry.internal.services.MarkupWriterImpl;
+import org.apache.tapestry.internal.services.PageLinkHandler;
+import org.apache.tapestry.internal.services.PageLinkPathSource;
+import org.apache.tapestry.internal.services.PageMarkupRenderer;
+import org.apache.tapestry.internal.services.PageRenderer;
+import org.apache.tapestry.internal.services.PathSource;
+import org.apache.tapestry.internal.structure.Page;
+import org.apache.tapestry.ioc.Registry;
+
+/**
+ * Simulates a click on a page link.
+ */
+public class PageLinkClicker implements LinkClicker
+{
+    private final Registry _registry;
+
+    private final PageLinkHandler _pageLinkHandler;
+
+    private final PageMarkupRenderer _renderer;
+
+    public PageLinkClicker(Registry registry)
+    {
+        _registry = registry;
+        _pageLinkHandler = _registry.getService(PageLinkHandler.class);
+        _renderer = _registry.getService(PageMarkupRenderer.class);
+    }
+
+    /**
+     * Click on the page link.
+     *
+     * @param pageSource
+     *            The path source for the page link.
+     * @return The DOM created. Typically you will assert against it.
+     */
+    public Document click(PathSource pathSource)
+    {
+        try
+        {
+            final MarkupWriterImpl writer = new MarkupWriterImpl();
+            _pageLinkHandler.handle((PageLinkPathSource) pathSource, new
PageRenderer()
+            {
+
+                public void renderPage(Page page)
+                {
+                    _renderer.renderPageMarkup(page, writer);
+                }
+
+            });
+            return writer.getDocument();
+        }
+        finally
+        {
+            _registry.cleanupThread();
+        }
+    }
+
+}

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageTester.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageTester.java?view=diff&rev=488300&r1=488299&r2=488300

==============================================================================
---
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageTester.java
(original)
+++
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageTester.java
Mon Dec 18 07:08:35 2006
@@ -19,37 +19,28 @@
import java.util.Collections;
import java.util.Map;

-import org.apache.tapestry.Link;
import org.apache.tapestry.dom.Document;
import org.apache.tapestry.dom.Element;
import org.apache.tapestry.internal.TapestryAppInitializer;
-import org.apache.tapestry.internal.services.ActionLinkHandler;
import org.apache.tapestry.internal.services.ActionLinkPathSource;
import org.apache.tapestry.internal.services.LinkImpl;
-import org.apache.tapestry.internal.services.MarkupWriterImpl;
-import org.apache.tapestry.internal.services.PageLinkHandler;
import org.apache.tapestry.internal.services.PageLinkPathSource;
-import org.apache.tapestry.internal.services.PageMarkupRenderer;
-import org.apache.tapestry.internal.services.PageRenderer;
import org.apache.tapestry.internal.services.PathSource;
-import org.apache.tapestry.internal.structure.Page;
import org.apache.tapestry.ioc.Registry;
import org.apache.tapestry.ioc.internal.util.Defense;
+import org.apache.tapestry.ioc.util.StrategyRegistry;

/**
  * This class is used to run a Tapestry app in an in-process testing
environment. You can ask it to
- * render a certain page and check the DOM object created. Because no
servlet container is required,
- * it is very fast and you can directly debug into your code in your IDE.
+ * render a certain page and check the DOM object created. You can also
ask it to click on a link
+ * element in the DOM object to get the next page. Because no servlet
container is required, it is
+ * very fast and you can directly debug into your code in your IDE.
  */
public class PageTester
{
     private Registry _registry;

-    private PageMarkupRenderer _renderer;
-
-    private PageLinkHandler _pageLinkHandler;
-
-    private ActionLinkHandler _actionLinkHandler;
+    private StrategyRegistry<LinkClicker> _clickerRegistry;

     /**
      * Initializes a PageTester without overriding any services.
@@ -77,9 +68,16 @@
     {
         _registry = new TapestryAppInitializer(appPackage, appName,
"test",
                 addDefaultOverrides(serviceOverrides)).getRegistry();
-        _pageLinkHandler = _registry.getService(PageLinkHandler.class);
-        _actionLinkHandler = _registry.getService(ActionLinkHandler.class
);
-        _renderer = _registry.getService(PageMarkupRenderer.class);
+        buildLinkClickersRegistry();
+    }
+
+    private void buildLinkClickersRegistry()
+    {
+        PageLinkClicker pageLinkClicker = new PageLinkClicker(_registry);
+        Map<Class, LinkClicker> map = newMap();
+        map.put(PageLinkPathSource.class, pageLinkClicker);
+        map.put(ActionLinkPathSource.class, new
ActionLinkClicker(_registry, pageLinkClicker));
+        _clickerRegistry = new StrategyRegistry<LinkClicker>(
LinkClicker.class, map);
     }

     private Map<String, Object> addDefaultOverrides(Map<String, Object>
serviceOverrides)
@@ -116,12 +114,12 @@
      * Renders a page specified by its name.
      *
      * @param pageName
-     *            the name of the page to be rendered.
-     * @return the DOM created. Typically you will assert against it.
+     *            The name of the page to be rendered.
+     * @return The DOM created. Typically you will assert against it.
      */
     public Document renderPage(String pageName)
     {
-        return clickPageLink(new PageLinkPathSource(null, pageName,
Collections.EMPTY_LIST));
+        return clickLink(new PageLinkPathSource(null, pageName, new
Object[0]));
     }

     /**
@@ -138,70 +136,13 @@
         {
             throw new IllegalArgumentException("No source object is
associated with the Element");
         }
-        return clickLink((LinkImpl) link.getSrc());
-    }
-
-    private Document clickLink(Link link)
-    {
-        PathSource pathSource = ((LinkImpl) link).getPathSource();
-        if (pathSource instanceof ActionLinkPathSource)
-        {
-            return clickLink(clickActionLink((ActionLinkPathSource)
pathSource));
-        }
-        if (pathSource instanceof PageLinkPathSource)
-        {
-            return clickPageLink((PageLinkPathSource) pathSource);
-        }
-        throw new IllegalArgumentException("The type of the path source
is not supported: "
-                + pathSource.getClass().getName());
-    }
-
-    /**
-     * Simulates a click on an action link. No redirection is performed.
-     *
-     * @param pageSource
-     *            The path source for the action link.
-     * @return The page Link created.
-     */
-    private Link clickActionLink(ActionLinkPathSource pathSource)
-    {
-        try
-        {
-            return _actionLinkHandler.handle(pathSource);
-        }
-        finally
-        {
-            _registry.cleanupThread();
-        }
+        return clickLink(((LinkImpl) link.getSrc()).getPathSource());
     }

-    /**
-     * Simulates a click on a page link.
-     *
-     * @param pageSource
-     *            The path source for the page link.
-     * @return The DOM created. Typically you will assert against it.
-     */
-    private Document clickPageLink(PageLinkPathSource pathSource)
+    private Document clickLink(PathSource pathSource)
     {
-        try
-        {
-            final MarkupWriterImpl writer = new MarkupWriterImpl();
-            _pageLinkHandler.handle(pathSource, new PageRenderer()
-            {
-
-                public void renderPage(Page page)
-                {
-                    _renderer.renderPageMarkup(page, writer);
-                }
-
-            });
-            return writer.getDocument();
-        }
-        finally
-        {
-            _registry.cleanupThread();
-        }
+        LinkClicker clicker = _clickerRegistry.getByInstance(pathSource);
+        return clicker.click(pathSource);
     }

}

Modified:
tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/event.apt
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/event.apt?view=diff&rev=488300&r1=488299&r2=488300

==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/event.apt
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/event.apt
Mon Dec 18 07:08:35 2006
@@ -147,7 +147,7 @@
     @Inject
     private CustomerDAO _customerDAO;

-    @OnEvent("passivate')
+    @OnEvent("passivate")
     long passivate()
     {
       return _customer.getId();





--
Howard M. Lewis Ship
TWD Consulting, Inc.
Independent J2EE / Open-Source Java Consultant
Creator and PMC Chair, Apache Tapestry
Creator, Apache HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com

Reply via email to