|
| 1 | +/* |
| 2 | + * Copyright 2011 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a> |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.ocpsoft.rewrite.faces.navigate; |
| 17 | + |
| 18 | +import static org.hamcrest.Matchers.containsString; |
| 19 | +import static org.hamcrest.Matchers.endsWith; |
| 20 | +import static org.hamcrest.Matchers.is; |
| 21 | +import static org.junit.Assert.assertThat; |
| 22 | + |
| 23 | +import org.jboss.arquillian.container.test.api.Deployment; |
| 24 | +import org.jboss.arquillian.junit.Arquillian; |
| 25 | +import org.jboss.shrinkwrap.api.spec.WebArchive; |
| 26 | +import org.junit.Test; |
| 27 | +import org.junit.runner.RunWith; |
| 28 | +import org.ocpsoft.rewrite.config.ConfigurationProvider; |
| 29 | +import org.ocpsoft.rewrite.faces.test.FacesBase; |
| 30 | +import org.ocpsoft.rewrite.test.RewriteTestBase; |
| 31 | + |
| 32 | +import com.gargoylesoftware.htmlunit.HttpMethod; |
| 33 | +import com.gargoylesoftware.htmlunit.html.HtmlPage; |
| 34 | + |
| 35 | +@RunWith(Arquillian.class) |
| 36 | +public class NavigateOutcomeTest extends RewriteTestBase |
| 37 | +{ |
| 38 | + |
| 39 | + @Deployment(testable = false) |
| 40 | + public static WebArchive getDeployment() |
| 41 | + { |
| 42 | + return FacesBase.getDeployment() |
| 43 | + .addClass(NavigateOutcomeBean.class) |
| 44 | + .addAsServiceProviderAndClasses(ConfigurationProvider.class, NavigateOutcomeConfig.class) |
| 45 | + .addAsWebResource("navigate-outcome.xhtml", "navigate.xhtml"); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void testRedirectSimpleString() throws Exception |
| 50 | + { |
| 51 | + |
| 52 | + HtmlPage firstPage = getWebClient("/navigate").getPage(); |
| 53 | + HtmlPage secondPage = firstPage.getElementById("form:redirectSimpleString").click(); |
| 54 | + |
| 55 | + assertThat(secondPage.getWebResponse().getWebRequest().getHttpMethod(), is(HttpMethod.GET)); |
| 56 | + assertThat(secondPage.getUrl().toString(), endsWith("/navigate?q=foo")); |
| 57 | + |
| 58 | + String secondPageContent = secondPage.getWebResponse().getContentAsString(); |
| 59 | + assertThat(secondPageContent, containsString("Value = [foo]")); |
| 60 | + |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void testRedirectWithSpace() throws Exception |
| 65 | + { |
| 66 | + |
| 67 | + HtmlPage firstPage = getWebClient("/navigate").getPage(); |
| 68 | + HtmlPage secondPage = firstPage.getElementById("form:redirectWithSpace").click(); |
| 69 | + |
| 70 | + assertThat(secondPage.getWebResponse().getWebRequest().getHttpMethod(), is(HttpMethod.GET)); |
| 71 | + assertThat(secondPage.getUrl().toString(), endsWith("/navigate?q=foo+bar")); |
| 72 | + |
| 73 | + String secondPageContent = secondPage.getWebResponse().getContentAsString(); |
| 74 | + assertThat(secondPageContent, containsString("Value = [foo bar]")); |
| 75 | + |
| 76 | + } |
| 77 | + |
| 78 | + @Test |
| 79 | + public void testRedirectWithAmpersand() throws Exception |
| 80 | + { |
| 81 | + |
| 82 | + HtmlPage firstPage = getWebClient("/navigate").getPage(); |
| 83 | + HtmlPage secondPage = firstPage.getElementById("form:redirectWithAmpersand").click(); |
| 84 | + |
| 85 | + assertThat(secondPage.getWebResponse().getWebRequest().getHttpMethod(), is(HttpMethod.GET)); |
| 86 | + assertThat(secondPage.getUrl().toString(), endsWith("/navigate?q=foo%26bar")); |
| 87 | + |
| 88 | + String secondPageContent = secondPage.getWebResponse().getContentAsString(); |
| 89 | + assertThat(secondPageContent, containsString("Value = [foo&bar]")); |
| 90 | + |
| 91 | + } |
| 92 | + |
| 93 | + @Test |
| 94 | + public void testRedirectWithEquals() throws Exception |
| 95 | + { |
| 96 | + |
| 97 | + HtmlPage firstPage = getWebClient("/navigate").getPage(); |
| 98 | + HtmlPage secondPage = firstPage.getElementById("form:redirectWithEquals").click(); |
| 99 | + |
| 100 | + assertThat(secondPage.getWebResponse().getWebRequest().getHttpMethod(), is(HttpMethod.GET)); |
| 101 | + assertThat(secondPage.getUrl().toString(), endsWith("/navigate?q=foo%3Dbar")); |
| 102 | + |
| 103 | + String secondPageContent = secondPage.getWebResponse().getContentAsString(); |
| 104 | + assertThat(secondPageContent, containsString("Value = [foo=bar]")); |
| 105 | + |
| 106 | + } |
| 107 | + |
| 108 | + @Test |
| 109 | + public void testRedirectWithChinese() throws Exception |
| 110 | + { |
| 111 | + |
| 112 | + HtmlPage firstPage = getWebClient("/navigate").getPage(); |
| 113 | + HtmlPage secondPage = firstPage.getElementById("form:redirectWithChinese").click(); |
| 114 | + |
| 115 | + assertThat(secondPage.getWebResponse().getWebRequest().getHttpMethod(), is(HttpMethod.GET)); |
| 116 | + assertThat(secondPage.getUrl().toString(), endsWith("/navigate?q=%E6%BC%A2%E5%AD%97")); |
| 117 | + |
| 118 | + } |
| 119 | + |
| 120 | + @Test |
| 121 | + public void testNavigateNoParams() throws Exception |
| 122 | + { |
| 123 | + |
| 124 | + HtmlPage firstPage = getWebClient("/navigate").getPage(); |
| 125 | + HtmlPage secondPage = firstPage.getElementById("form:navigateNoParams").click(); |
| 126 | + |
| 127 | + assertThat(secondPage.getWebResponse().getWebRequest().getHttpMethod(), is(HttpMethod.POST)); |
| 128 | + assertThat(secondPage.getUrl().toString(), endsWith("/navigate")); |
| 129 | + |
| 130 | + } |
| 131 | + |
| 132 | +} |
0 commit comments