Skip to content

Commit b41a389

Browse files
committed
Arquillian test for new rewrite-redirect: outcome
1 parent 998ac7a commit b41a389

4 files changed

Lines changed: 306 additions & 0 deletions

File tree

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
/*
17+
* Copyright 2011 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
18+
*
19+
* Licensed under the Apache License, Version 2.0 (the "License");
20+
* you may not use this file except in compliance with the License.
21+
* You may obtain a copy of the License at
22+
*
23+
* http://www.apache.org/licenses/LICENSE-2.0
24+
*
25+
* Unless required by applicable law or agreed to in writing, software
26+
* distributed under the License is distributed on an "AS IS" BASIS,
27+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28+
* See the License for the specific language governing permissions and
29+
* limitations under the License.
30+
*/
31+
package org.ocpsoft.rewrite.faces.navigate;
32+
33+
import javax.faces.bean.ManagedBean;
34+
import javax.faces.bean.RequestScoped;
35+
36+
@ManagedBean
37+
@RequestScoped
38+
public class NavigateOutcomeBean
39+
{
40+
41+
private String query;
42+
43+
public Navigate redirectSimpleString()
44+
{
45+
return Navigate.to("/navigate.xhtml")
46+
.with("q", "foo");
47+
}
48+
49+
public Navigate redirectWithSpace()
50+
{
51+
return Navigate.to("/navigate.xhtml")
52+
.with("q", "foo bar");
53+
}
54+
55+
public Navigate redirectWithAmpersand()
56+
{
57+
return Navigate.to("/navigate.xhtml")
58+
.with("q", "foo&bar");
59+
}
60+
61+
public Navigate redirectWithEquals()
62+
{
63+
return Navigate.to("/navigate.xhtml")
64+
.with("q", "foo=bar");
65+
}
66+
67+
public Navigate redirectWithChinese()
68+
{
69+
return Navigate.to("/navigate.xhtml")
70+
.with("q", "\u6f22\u5b57");
71+
}
72+
73+
public Navigate navigateNoParams()
74+
{
75+
return Navigate.to("/navigate.xhtml")
76+
.withoutRedirect();
77+
}
78+
79+
public String getQuery()
80+
{
81+
return query;
82+
}
83+
84+
public void setQuery(String query)
85+
{
86+
this.query = query;
87+
}
88+
89+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
/*
17+
* Copyright 2011 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
18+
*
19+
* Licensed under the Apache License, Version 2.0 (the "License");
20+
* you may not use this file except in compliance with the License.
21+
* You may obtain a copy of the License at
22+
*
23+
* http://www.apache.org/licenses/LICENSE-2.0
24+
*
25+
* Unless required by applicable law or agreed to in writing, software
26+
* distributed under the License is distributed on an "AS IS" BASIS,
27+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28+
* See the License for the specific language governing permissions and
29+
* limitations under the License.
30+
*/
31+
package org.ocpsoft.rewrite.faces.navigate;
32+
33+
import javax.servlet.ServletContext;
34+
35+
import org.ocpsoft.rewrite.config.Configuration;
36+
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
37+
import org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider;
38+
import org.ocpsoft.rewrite.servlet.config.rule.Join;
39+
40+
public class NavigateOutcomeConfig extends HttpConfigurationProvider
41+
{
42+
43+
@Override
44+
public Configuration getConfiguration(ServletContext context)
45+
{
46+
return ConfigurationBuilder.begin()
47+
.addRule(Join.path("/navigate").to("/navigate.xhtml"));
48+
}
49+
50+
@Override
51+
public int priority()
52+
{
53+
return 0;
54+
}
55+
56+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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&amp;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+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
3+
xmlns:f="http://java.sun.com/jsf/core">
4+
<h:body>
5+
6+
<f:metadata>
7+
<f:viewParam name="q" value="#{navigateOutcomeBean.query}" />
8+
</f:metadata>
9+
10+
<h:form id="form">
11+
12+
<p>Value = [#{navigateOutcomeBean.query}]</p>
13+
14+
<h:commandButton id="redirectSimpleString" action="#{navigateOutcomeBean.redirectSimpleString}" />
15+
16+
<h:commandButton id="redirectWithSpace" action="#{navigateOutcomeBean.redirectWithSpace}" />
17+
18+
<h:commandButton id="redirectWithAmpersand" action="#{navigateOutcomeBean.redirectWithAmpersand}" />
19+
20+
<h:commandButton id="redirectWithEquals" action="#{navigateOutcomeBean.redirectWithEquals}" />
21+
22+
<h:commandButton id="redirectWithChinese" action="#{navigateOutcomeBean.redirectWithChinese}" />
23+
24+
<h:commandButton id="navigateNoParams" action="#{navigateOutcomeBean.navigateNoParams}" />
25+
26+
</h:form>
27+
28+
</h:body>
29+
</html>

0 commit comments

Comments
 (0)