/*
 * 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.markup.html.link;

import org.apache.wicket.WicketTestCase;
import org.apache.wicket.request.mapper.parameter.PageParameters;

/**
 * @author jcompagner
 */
public class BookmarkablePageLinkTest extends WicketTestCase
{

	/**
	 * Construct.
	 * 
	 * @param name
	 */
	public BookmarkablePageLinkTest(String name)
	{
		super(name);
	}

	/**
	 * @throws Exception
	 */
	public void testBookmarkableRequest() throws Exception
	{
		tester.startPage(BookmarkableHomePageLinksPage.class);
		assertEquals(tester.getLastRenderedPage().getClass(), BookmarkableHomePageLinksPage.class);

	}

	/**
	 * @throws Exception
	 */
	public void testBookmarkableRequestWithIntercept() throws Exception
	{
		tester.startPage(BookmarkableThrowsInterceptPage.class);

		assertEquals(tester.getLastRenderedPage().getClass(), BookmarkableSetSecurityPage.class);

		tester.startPage(BookmarkableContinueToPage.class);
		assertEquals(tester.getLastRenderedPage().getClass(), BookmarkableThrowsInterceptPage.class);

	}

	/**
	 * @throws Exception
	 */
	public void testBookmarkableRequestWithInterceptWithParams() throws Exception
	{
		PageParameters pp = new PageParameters();
		pp.set("test", "test");

		tester.startPage(BookmarkableThrowsInterceptPage.class, pp);

		assertEquals(tester.getLastRenderedPage().getClass(), BookmarkableSetSecurityPage.class);

		tester.startPage(BookmarkableContinueToPage.class);
		assertEquals(tester.getLastRenderedPage().getClass(), BookmarkableThrowsInterceptPage.class);
	}
}

@@ -841,16 +841,59 @@
 .link;%0A%0A
+import org.apache.wicket.MockPageWithLink;%0A
 import o
@@ -990,16 +990,41 @@
 ameters;
+%0Aimport org.junit.Assert;
 %0A%0A/**%0A *
@@ -2378,11 +2378,854 @@
 ass);%0A%09%7D
+%0A%0A%09/**%0A%09 * @see %3Ca href=%22https://issues.apache.org/jira/browse/WICKET-3721%22%3EWICKET-3721%3C/a%3E%0A%09 */%0A%09public void bug_testCustomParametersWithSpecialCharacters()%0A%09%7B%0A%09%09BookmarkablePageLink%3CMockPageWithLink%3E link = new BookmarkablePageLink%3CMockPageWithLink%3E(%0A%09%09%09%22link%22, MockPageWithLink.class);%0A%09%09link.getPageParameters().set(%22urlEscapeNeeded%22, %22someone's %5Eb%25a&d pa%5C%22rameter%22);%0A%0A%09%09tester.startComponentInPage(link, null);%0A%09%09String response = tester.getLastResponse().getDocument();%0A%09%09Assert.assertEquals(%0A%09%09%09%22%3Chtml%3E%3Cbody%3E%3Cspan wicket:id=%5C%22link%5C%22 onclick=%5C%22var win = this.ownerDocument.defaultView %7C%7C this.ownerDocument.parentWindow; if (win == window) %7B window.location.href=&#039;bookmarkable/org.apache.wicket.MockPageWithLink?urlEscapeNeeded=someone%2527s+%255Eb%2525a%2526d+pa%2522rameter&#039;; %7D ;return false%5C%22%3E%3C/span%3E%3C/body%3E%3C/html%3E%22,%0A%09%09%09response);%0A%0A%09%7D
 %0A%7D%0A

WICKET-3721 The Url's query parameters are not properly URL encoded