Author: marrink
Date: Mon May 12 06:30:16 2008
New Revision: 655498
URL: http://svn.apache.org/viewvc?rev=655498&view=rev
Log:
RESOLVED - issue WICKET-1292: WicketTester continueToOriginalDestination() uses
application home page instead of original redictor
https://issues.apache.org/jira/browse/WICKET-1292
Fixed scenario where original destination is the homepage of the application
Added:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.html
(with props)
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.java
(with props)
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.html
(with props)
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.java
(with props)
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptTest.java
(with props)
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.html
(with props)
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.java
(with props)
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.html
(with props)
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.java
(with props)
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.html
(with props)
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.java
(with props)
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptTest.java
(with props)
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.html
(with props)
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.java
(with props)
Modified:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java
Modified:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java?rev=655498&r1=655497&r2=655498&view=diff
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java
(original)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java
Mon May 12 06:30:16 2008
@@ -19,7 +19,9 @@
import java.io.File;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
+import java.util.TreeSet;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
@@ -28,17 +30,21 @@
import org.apache.wicket.Application;
import org.apache.wicket.Component;
+import org.apache.wicket.IPageMap;
import org.apache.wicket.IRequestTarget;
import org.apache.wicket.Page;
import org.apache.wicket.PageParameters;
import org.apache.wicket.Session;
import org.apache.wicket.markup.html.pages.ExceptionErrorPage;
import org.apache.wicket.protocol.http.request.WebErrorCodeResponseTarget;
+import org.apache.wicket.protocol.http.request.WebRequestCodingStrategy;
+import org.apache.wicket.request.target.coding.WebRequestEncoder;
import
org.apache.wicket.request.target.component.BookmarkablePageRequestTarget;
import
org.apache.wicket.request.target.component.IBookmarkablePageRequestTarget;
import org.apache.wicket.request.target.component.IPageRequestTarget;
import org.apache.wicket.settings.IRequestCycleSettings;
import org.apache.wicket.util.file.WebApplicationPath;
+import org.apache.wicket.util.string.AppendingStringBuffer;
import org.apache.wicket.util.tester.BaseWicketTester;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -374,7 +380,70 @@
BaseWicketTester.callOnBeginRequest(cycle);
BookmarkablePageRequestTarget requestTarget = new
BookmarkablePageRequestTarget(
pageClass, params);
- if (application.getHomePage() != null)
+ if (pageClass == application.getHomePage())
+ {
+ // special handling
+
+ // code is copy pasted from
+ //
org.apache.wicket.protocol.http.request.WebRequestCodingStrategy.encode(RequestCycle
+ // , IBookmarkablePageRequestTarget)
+ // since only the test is suffering from this
problem
+
+ // this is a bit ugly and i am open to
suggestions on how to fix this better. MM
+ String pageMapName;
+ IRequestTarget currentTarget =
cycle.getRequestTarget();
+ if (currentTarget instanceof IPageRequestTarget)
+ {
+ Page currentPage =
((IPageRequestTarget)currentTarget).getPage();
+ final IPageMap pageMap =
currentPage.getPageMap();
+ if (pageMap.isDefault())
+ {
+ pageMapName = "";
+ }
+ else
+ {
+ pageMapName = pageMap.getName();
+ }
+ }
+ else
+ {
+ pageMapName = "";
+ }
+ AppendingStringBuffer buffer = new
AppendingStringBuffer(64);
+ WebRequestEncoder encoder = new
WebRequestEncoder(buffer);
+
encoder.addValue(WebRequestCodingStrategy.BOOKMARKABLE_PAGE_PARAMETER_NAME,
+ pageMapName + Component.PATH_SEPARATOR
+ pageClass.getName());
+ if (params != null)
+ {
+ final Iterator iterator;
+ if
(UnitTestSettings.getSortUrlParameters())
+ {
+ iterator = new
TreeSet(params.keySet()).iterator();
+ }
+ else
+ {
+ iterator =
params.keySet().iterator();
+ }
+ while (iterator.hasNext())
+ {
+ final String key =
(String)iterator.next();
+ final String values[] =
params.getStringArray(key);
+ if (values != null)
+ {
+ for (int i = 0; i <
values.length; i++)
+ {
+
encoder.addValue(key, values[i]);
+ }
+ }
+ }
+ }
+ String url = buffer.toString();
+ String path = application.getClass().getName();
+ path = path.substring(path.lastIndexOf('.') +
1);
+ path = "/" + path + "/" + path + "/";
+ getServletRequest().setURL(path + url);
+ }
+ else if (application.getHomePage() != null)
{
String url =
cycle.urlFor(requestTarget).toString();
String path = application.getClass().getName();
Added:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.html
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.html?rev=655498&view=auto
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.html
(added)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.html
Mon May 12 06:30:16 2008
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
+ <title>Page</title>
+</head>
+<body>
+
+ <span wicket:id="label">test</span>
+
+</body>
+</html>
\ No newline at end of file
Propchange:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.html
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.java?rev=655498&view=auto
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.java
(added)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.java
Mon May 12 06:30:16 2008
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.redirect.intercept;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+
+/**
+ * HomePage.
+ *
+ * @author marrink
+ */
+public class HomePage extends WebPage
+{
+
+ /**
+ * Construct.
+ */
+ public HomePage()
+ {
+ add(new Label("label", "Home"));
+ }
+
+}
Propchange:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.html
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.html?rev=655498&view=auto
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.html
(added)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.html
Mon May 12 06:30:16 2008
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
+ <title>Page</title>
+</head>
+<body>
+
+ <a href="#" wicket:id="link">link</a>
+
+</body>
+</html>
Propchange:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.html
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.java?rev=655498&view=auto
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.java
(added)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.java
Mon May 12 06:30:16 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.redirect.intercept;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.RestartResponseAtInterceptPageException;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.link.Link;
+
+/**
+ * Page handling the [EMAIL PROTECTED]
RestartResponseAtInterceptPageException}.
+ *
+ * @author marrink
+ */
+public class InterceptPage extends WebPage
+{
+
+ /**
+ * Construct.
+ */
+ public InterceptPage()
+ {
+ add(new Link("link")
+ {
+
+ private static final long serialVersionUID = 1L;
+
+ public void onClick()
+ {
+ if (!continueToOriginalDestination())
+
setResponsePage(Application.get().getHomePage());
+ }
+ });
+ }
+
+}
Propchange:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptTest.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptTest.java?rev=655498&view=auto
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptTest.java
(added)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptTest.java
Mon May 12 06:30:16 2008
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.redirect.intercept;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.RestartResponseAtInterceptPageException;
+import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.authorization.Action;
+import org.apache.wicket.authorization.IAuthorizationStrategy;
+import org.apache.wicket.resource.DummyApplication;
+import org.apache.wicket.util.tester.WicketTester;
+
+/**
+ * Testcase for bug WICKET-1292.
+ *
+ * @see <a
href="https://issues.apache.org/jira/browse/WICKET-1292">WICKET-1292</a>
+ * @author marrink
+ */
+public class InterceptTest extends WicketTestCase
+{
+
+ /**
+ * @see org.apache.wicket.WicketTestCase#setUp()
+ */
+ protected void setUp() throws Exception
+ {
+ tester = new WicketTester(new DummyApplication()
+ {
+ protected void init()
+ {
+
getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy()
+ {
+
+ private boolean block = true;
+
+ public boolean
isActionAuthorized(Component component, Action action)
+ {
+ return true;
+ }
+
+ public boolean
isInstantiationAuthorized(Class componentClass)
+ {
+ if (block &&
+ (componentClass ==
TargetPage.class || componentClass == HomePage.class))
+ {
+ block = false;
+ throw new
RestartResponseAtInterceptPageException(InterceptPage.class);
+ }
+ return true;
+ }
+ });
+ super.init();
+ }
+
+ public Class getHomePage()
+ {
+ return HomePage.class;
+ }
+ });
+ }
+
+ /**
+ * Testcase for the behavior of WicketTester with respect to
continueToOrginialDestination.
+ * Tests a non homepage class.
+ */
+ public void
testRestartResponseAtInterceptPageAndContinueTorOriginalDestination()
+ {
+ tester.startPage(TargetPage.class);
+ tester.assertRenderedPage(InterceptPage.class);
+ tester.clickLink("link");
+ tester.assertRenderedPage(TargetPage.class);
+ }
+
+ /**
+ * Testcase for the behavior of WicketTester with respect to
continueToOrginialDestination.
+ * Tests homepage class.
+ */
+ public void
testRestartResponseAtInterceptPageAndContinueTorOriginalDestination2()
+ {
+ tester.startPage(HomePage.class);
+ tester.assertRenderedPage(InterceptPage.class);
+ tester.clickLink("link");
+ tester.assertRenderedPage(HomePage.class);
+ }
+
+}
Propchange:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.html
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.html?rev=655498&view=auto
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.html
(added)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.html
Mon May 12 06:30:16 2008
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
+ <title>Page</title>
+</head>
+<body>
+
+ <span wicket:id="label">test</span>
+
+</body>
+</html>
\ No newline at end of file
Propchange:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.html
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.java?rev=655498&view=auto
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.java
(added)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.java
Mon May 12 06:30:16 2008
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.redirect.intercept;
+
+import org.apache.wicket.RestartResponseAtInterceptPageException;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+
+/**
+ * Original target page before [EMAIL PROTECTED]
RestartResponseAtInterceptPageException}.
+ *
+ * @author marrink
+ */
+public class TargetPage extends WebPage
+{
+
+ /**
+ * Construct.
+ */
+ public TargetPage()
+ {
+ add(new Label("label", "Target"));
+ }
+
+}
Propchange:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java?rev=655498&r1=655497&r2=655498&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java
Mon May 12 06:30:16 2008
@@ -19,7 +19,9 @@
import java.io.File;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
+import java.util.TreeSet;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
@@ -28,17 +30,21 @@
import org.apache.wicket.Application;
import org.apache.wicket.Component;
+import org.apache.wicket.IPageMap;
import org.apache.wicket.IRequestTarget;
import org.apache.wicket.Page;
import org.apache.wicket.PageParameters;
import org.apache.wicket.Session;
import org.apache.wicket.markup.html.pages.ExceptionErrorPage;
import org.apache.wicket.protocol.http.request.WebErrorCodeResponseTarget;
+import org.apache.wicket.protocol.http.request.WebRequestCodingStrategy;
+import org.apache.wicket.request.target.coding.WebRequestEncoder;
import
org.apache.wicket.request.target.component.BookmarkablePageRequestTarget;
import
org.apache.wicket.request.target.component.IBookmarkablePageRequestTarget;
import org.apache.wicket.request.target.component.IPageRequestTarget;
import org.apache.wicket.settings.IRequestCycleSettings;
import org.apache.wicket.util.file.WebApplicationPath;
+import org.apache.wicket.util.string.AppendingStringBuffer;
import org.apache.wicket.util.tester.BaseWicketTester;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -375,7 +381,70 @@
BaseWicketTester.callOnBeginRequest(cycle);
BookmarkablePageRequestTarget requestTarget = new
BookmarkablePageRequestTarget(
pageClass, params);
- if (application.getHomePage() != null)
+ if (pageClass == application.getHomePage())
+ {
+ // special handling
+
+ // code is copy pasted from
+ //
org.apache.wicket.protocol.http.request.WebRequestCodingStrategy.encode(RequestCycle
+ // , IBookmarkablePageRequestTarget)
+ // since only the test is suffering from this
problem
+
+ // this is a bit ugly and i am open to
suggestions on how to fix this better. MM
+ String pageMapName;
+ IRequestTarget currentTarget =
cycle.getRequestTarget();
+ if (currentTarget instanceof IPageRequestTarget)
+ {
+ Page currentPage =
((IPageRequestTarget)currentTarget).getPage();
+ final IPageMap pageMap =
currentPage.getPageMap();
+ if (pageMap.isDefault())
+ {
+ pageMapName = "";
+ }
+ else
+ {
+ pageMapName = pageMap.getName();
+ }
+ }
+ else
+ {
+ pageMapName = "";
+ }
+ AppendingStringBuffer buffer = new
AppendingStringBuffer(64);
+ WebRequestEncoder encoder = new
WebRequestEncoder(buffer);
+
encoder.addValue(WebRequestCodingStrategy.BOOKMARKABLE_PAGE_PARAMETER_NAME,
+ pageMapName + Component.PATH_SEPARATOR
+ pageClass.getName());
+ if (params != null)
+ {
+ final Iterator iterator;
+ if
(UnitTestSettings.getSortUrlParameters())
+ {
+ iterator = new
TreeSet(params.keySet()).iterator();
+ }
+ else
+ {
+ iterator =
params.keySet().iterator();
+ }
+ while (iterator.hasNext())
+ {
+ final String key =
(String)iterator.next();
+ final String values[] =
params.getStringArray(key);
+ if (values != null)
+ {
+ for (int i = 0; i <
values.length; i++)
+ {
+
encoder.addValue(key, values[i]);
+ }
+ }
+ }
+ }
+ String url = buffer.toString();
+ String path = application.getClass().getName();
+ path = path.substring(path.lastIndexOf('.') +
1);
+ path = "/" + path + "/" + path + "/";
+ getServletRequest().setURL(path + url);
+ }
+ else if (application.getHomePage() != null)
{
String url =
cycle.urlFor(requestTarget).toString();
String path = application.getClass().getName();
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.html
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.html?rev=655498&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.html
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.html
Mon May 12 06:30:16 2008
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
+ <title>Page</title>
+</head>
+<body>
+
+ <span wicket:id="label">test</span>
+
+</body>
+</html>
\ No newline at end of file
Propchange:
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.html
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.java?rev=655498&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.java
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.java
Mon May 12 06:30:16 2008
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.redirect.intercept;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+
+/**
+ * HomePage.
+ *
+ * @author marrink
+ */
+public class HomePage extends WebPage<Void>
+{
+
+ /**
+ * Construct.
+ */
+ public HomePage()
+ {
+ add(new Label<String>("label", "Home"));
+ }
+
+}
Propchange:
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/HomePage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.html
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.html?rev=655498&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.html
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.html
Mon May 12 06:30:16 2008
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
+ <title>Page</title>
+</head>
+<body>
+
+ <a href="#" wicket:id="link">link</a>
+
+</body>
+</html>
Propchange:
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.html
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.java?rev=655498&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.java
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.java
Mon May 12 06:30:16 2008
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.redirect.intercept;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.RestartResponseAtInterceptPageException;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.link.Link;
+
+/**
+ * Page handling the [EMAIL PROTECTED]
RestartResponseAtInterceptPageException}.
+ *
+ * @author marrink
+ */
+public class InterceptPage extends WebPage<Void>
+{
+
+ /**
+ * Construct.
+ */
+ public InterceptPage()
+ {
+ add(new Link<Void>("link")
+ {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void onClick()
+ {
+ if (!continueToOriginalDestination())
+
setResponsePage(Application.get().getHomePage());
+ }
+ });
+ }
+
+}
Propchange:
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptPage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptTest.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptTest.java?rev=655498&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptTest.java
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptTest.java
Mon May 12 06:30:16 2008
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.redirect.intercept;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.Page;
+import org.apache.wicket.RestartResponseAtInterceptPageException;
+import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.authorization.Action;
+import org.apache.wicket.authorization.IAuthorizationStrategy;
+import org.apache.wicket.resource.DummyApplication;
+import org.apache.wicket.util.tester.WicketTester;
+
+/**
+ * Testcase for bug WICKET-1292.
+ *
+ * @see <a
href="https://issues.apache.org/jira/browse/WICKET-1292">WICKET-1292</a>
+ * @author marrink
+ */
+public class InterceptTest extends WicketTestCase
+{
+
+ /**
+ * @see org.apache.wicket.WicketTestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception
+ {
+ tester = new WicketTester(new DummyApplication()
+ {
+ @Override
+ protected void init()
+ {
+
getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy()
+ {
+
+ private boolean block = true;
+
+ public boolean
isActionAuthorized(Component< ? > component, Action action)
+ {
+ return true;
+ }
+
+ public boolean
isInstantiationAuthorized(
+ Class< ? extends Component>
componentClass)
+ {
+ if (block &&
+ (componentClass ==
TargetPage.class || componentClass == HomePage.class))
+ {
+ block = false;
+ throw new
RestartResponseAtInterceptPageException(InterceptPage.class);
+ }
+ return true;
+ }
+ });
+ super.init();
+ }
+
+ @Override
+ public Class< ? extends Page< ? >> getHomePage()
+ {
+ return HomePage.class;
+ }
+ });
+ }
+
+ /**
+ * Testcase for the behavior of WicketTester with respect to
continueToOrginialDestination.
+ * Tests a non homepage class.
+ */
+ public void
testRestartResponseAtInterceptPageAndContinueTorOriginalDestination()
+ {
+ tester.startPage(TargetPage.class);
+ tester.assertRenderedPage(InterceptPage.class);
+ tester.clickLink("link");
+ tester.assertRenderedPage(TargetPage.class);
+ }
+
+ /**
+ * Testcase for the behavior of WicketTester with respect to
continueToOrginialDestination.
+ * Tests homepage class.
+ */
+ public void
testRestartResponseAtInterceptPageAndContinueTorOriginalDestination2()
+ {
+ tester.startPage(HomePage.class);
+ tester.assertRenderedPage(InterceptPage.class);
+ tester.clickLink("link");
+ tester.assertRenderedPage(HomePage.class);
+ }
+
+}
Propchange:
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/InterceptTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.html
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.html?rev=655498&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.html
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.html
Mon May 12 06:30:16 2008
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
+ <title>Page</title>
+</head>
+<body>
+
+ <span wicket:id="label">test</span>
+
+</body>
+</html>
\ No newline at end of file
Propchange:
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.html
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.java?rev=655498&view=auto
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.java
(added)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.java
Mon May 12 06:30:16 2008
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.redirect.intercept;
+
+import org.apache.wicket.RestartResponseAtInterceptPageException;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+
+/**
+ * Original target page before [EMAIL PROTECTED]
RestartResponseAtInterceptPageException}.
+ *
+ * @author marrink
+ */
+public class TargetPage extends WebPage<Void>
+{
+
+ /**
+ * Construct.
+ */
+ public TargetPage()
+ {
+ add(new Label<String>("label", "Target"));
+ }
+
+}
Propchange:
wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/intercept/TargetPage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain