Author: hlship
Date: Fri Nov 7 11:50:04 2008
New Revision: 712240
URL: http://svn.apache.org/viewvc?rev=712240&view=rev
Log:
TAP5-10: An onActivate() event handler on a page can cause PageTester to fail
with a NullPointerException
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/app2/Final.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/app2/Launch.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/PageTesterTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/Final.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/Intermediate.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/Launch.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/PageRenderInvoker.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/PageTester.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/PageRenderInvoker.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/PageRenderInvoker.java?rev=712240&r1=712239&r2=712240&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/PageRenderInvoker.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/PageRenderInvoker.java
Fri Nov 7 11:50:04 2008
@@ -14,8 +14,10 @@
package org.apache.tapestry5.internal.test;
+import org.apache.tapestry5.Link;
import org.apache.tapestry5.dom.Document;
import org.apache.tapestry5.internal.services.ComponentInvocation;
+import org.apache.tapestry5.internal.services.ComponentInvocationMap;
import org.apache.tapestry5.internal.services.InvocationTarget;
import org.apache.tapestry5.internal.services.PageRenderTarget;
import org.apache.tapestry5.ioc.Registry;
@@ -37,9 +39,16 @@
private final TestableResponse response;
- public PageRenderInvoker(Registry registry)
+ private final ComponentInvoker followupInvoker;
+
+ private final ComponentInvocationMap componentInvocationMap;
+
+ public PageRenderInvoker(Registry registry, ComponentInvoker
followupInvoker,
+ ComponentInvocationMap componentInvocationMap)
{
this.registry = registry;
+ this.followupInvoker = followupInvoker;
+ this.componentInvocationMap = componentInvocationMap;
pageRenderRequestHandler =
this.registry.getService(PageRenderRequestHandler.class);
markupWriterFactory =
this.registry.getService(TestableMarkupWriterFactory.class);
@@ -65,6 +74,18 @@
pageRenderRequestHandler.handle(parameters);
+ Link redirect = response.getRedirectLink();
+
+ if (redirect != null)
+ {
+
+ ComponentInvocation followup =
componentInvocationMap.get(redirect);
+
+ response.clear();
+
+ return followupInvoker.invoke(followup);
+ }
+
return markupWriterFactory.getLatestMarkupWriter().getDocument();
}
catch (IOException ex)
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/PageTester.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/PageTester.java?rev=712240&r1=712239&r2=712240&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/PageTester.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/PageTester.java
Fri Nov 7 11:50:04 2008
@@ -107,7 +107,9 @@
globals.storeContext(new PageTesterContext(contextPath));
Map<Class, ComponentInvoker> map = newMap();
- map.put(PageRenderTarget.class, new PageRenderInvoker(registry));
+
+ map.put(PageRenderTarget.class, new PageRenderInvoker(registry, this,
invocationMap));
+
map.put(ComponentEventTarget.class, new
ComponentEventInvoker(registry, this, invocationMap));
invokerRegistry = StrategyRegistry.newInstance(ComponentInvoker.class,
map);
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app2/Final.tml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app2/Final.tml?rev=712240&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app2/Final.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app2/Final.tml Fri Nov 7
11:50:04 2008
@@ -0,0 +1,7 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+ <body>
+ <p>
+ Arrived on page<span
id="page-name">${componentResources.pageName}</span>.
+ </p>
+ </body>
+</html>
\ No newline at end of file
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app2/Launch.tml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app2/Launch.tml?rev=712240&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app2/Launch.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app2/Launch.tml Fri Nov 7
11:50:04 2008
@@ -0,0 +1,8 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+ <body>
+
+ <t:form t:id="form">
+ <input type="submit" value="Launch"/>
+ </t:form>
+ </body>
+</html>
\ No newline at end of file
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/PageTesterTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/PageTesterTest.java?rev=712240&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/PageTesterTest.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/PageTesterTest.java
Fri Nov 7 11:50:04 2008
@@ -0,0 +1,50 @@
+// Copyright 2008 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.tapestry5.integration;
+
+import org.apache.tapestry5.dom.Document;
+import org.apache.tapestry5.test.PageTester;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * Tests on PageTester itself.
+ */
+public class PageTesterTest extends Assert
+{
+ private static final String PACKAGE =
"org.apache.tapestry5.integration.app2";
+
+ @Test
+ public void on_activate_chain_is_followed()
+ {
+ PageTester tester = new PageTester(PACKAGE, "", "src/test/app2");
+
+ Document launchDoc = tester.renderPage("Launch");
+
+ Map<String, String> parameters = Collections.emptyMap();
+
+ // Submit the form, which will then skip through Intermediate and
+ // arrive at Final.
+
+ Document finalDoc =
tester.submitForm(launchDoc.getElementById("form"), parameters);
+
+ assertEquals(finalDoc.getElementById("page-name").getChildMarkup(),
"Final");
+
+ tester.shutdown();
+ }
+}
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/Final.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/Final.java?rev=712240&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/Final.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/Final.java
Fri Nov 7 11:50:04 2008
@@ -0,0 +1,19 @@
+// Copyright 2008 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.tapestry5.integration.app2.pages;
+
+public class Final
+{
+}
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/Intermediate.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/Intermediate.java?rev=712240&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/Intermediate.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/Intermediate.java
Fri Nov 7 11:50:04 2008
@@ -0,0 +1,23 @@
+// Copyright 2008 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.tapestry5.integration.app2.pages;
+
+public class Intermediate
+{
+ Object onActivate()
+ {
+ return Final.class;
+ }
+}
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/Launch.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/Launch.java?rev=712240&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/Launch.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/Launch.java
Fri Nov 7 11:50:04 2008
@@ -0,0 +1,23 @@
+// Copyright 2008 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.tapestry5.integration.app2.pages;
+
+public class Launch
+{
+ Object onSuccess()
+ {
+ return Intermediate.class;
+ }
+}