Skip to content

Commit fa25a99

Browse files
committed
Test for encoding of JSF action outcomes
1 parent 0edbdc2 commit fa25a99

5 files changed

Lines changed: 250 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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.outcome;
32+
33+
import javax.faces.bean.ManagedBean;
34+
import javax.faces.bean.RequestScoped;
35+
36+
@ManagedBean
37+
@RequestScoped
38+
public class OutcomeEncodingBean
39+
{
40+
41+
public String redirectSimple()
42+
{
43+
return "/page.xhtml?faces-redirect=true&param=foo&query=foo";
44+
}
45+
46+
public String redirectWithSpace()
47+
{
48+
return "/page.xhtml?faces-redirect=true&param=foo+bar&query=foo+bar";
49+
}
50+
51+
public String redirectWithEqual()
52+
{
53+
54+
return "/page.xhtml?faces-redirect=true&param=foo%3Dbar&query=foo%3Dbar";
55+
}
56+
57+
public String redirectWithAmpersand()
58+
{
59+
return "/page.xhtml?faces-redirect=true&param=foo%26bar&query=foo%26bar";
60+
}
61+
62+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.outcome;
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 OutcomeEncodingConfig extends HttpConfigurationProvider
41+
{
42+
43+
@Override
44+
public Configuration getConfiguration(ServletContext context)
45+
{
46+
return ConfigurationBuilder.begin()
47+
.addRule(Join.path("/start").to("/start.xhtml"))
48+
.addRule(Join.path("/page/{param}").to("/page.xhtml"));
49+
}
50+
51+
@Override
52+
public int priority()
53+
{
54+
return 0;
55+
}
56+
57+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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.outcome;
17+
18+
import static org.hamcrest.Matchers.endsWith;
19+
import static org.junit.Assert.assertThat;
20+
21+
import org.jboss.arquillian.container.test.api.Deployment;
22+
import org.jboss.arquillian.junit.Arquillian;
23+
import org.jboss.shrinkwrap.api.spec.WebArchive;
24+
import org.junit.Ignore;
25+
import org.junit.Test;
26+
import org.junit.runner.RunWith;
27+
import org.ocpsoft.rewrite.config.ConfigurationProvider;
28+
import org.ocpsoft.rewrite.faces.test.FacesBase;
29+
import org.ocpsoft.rewrite.test.RewriteTestBase;
30+
31+
import com.gargoylesoftware.htmlunit.html.HtmlPage;
32+
33+
@RunWith(Arquillian.class)
34+
public class OutcomeEncodingTest extends RewriteTestBase
35+
{
36+
37+
@Deployment(testable = false)
38+
public static WebArchive getDeployment()
39+
{
40+
return FacesBase.getDeployment()
41+
.addClass(OutcomeEncodingBean.class)
42+
.addAsServiceProviderAndClasses(ConfigurationProvider.class, OutcomeEncodingConfig.class)
43+
.addAsWebResource("outcome-encoding-start.xhtml", "start.xhtml")
44+
.addAsWebResource("outcome-encoding-page.xhtml", "page.xhtml");
45+
}
46+
47+
@Test
48+
public void testOutcomeRedirectSimple() throws Exception
49+
{
50+
51+
HtmlPage startPage = getWebClient("/start").getPage();
52+
HtmlPage secondPage = startPage.getElementById("form:redirectSimple").click();
53+
54+
assertThat(secondPage.getUrl().toString(), endsWith("/page/foo?query=foo"));
55+
56+
}
57+
58+
@Test
59+
// TODO: Fix this
60+
@Ignore
61+
public void testOutcomeRedirectWithSpace() throws Exception
62+
{
63+
64+
HtmlPage startPage = getWebClient("/start").getPage();
65+
HtmlPage secondPage = startPage.getElementById("form:redirectWithSpace").click();
66+
67+
assertThat(secondPage.getUrl().toString(), endsWith("/page/foo%20bar?query=foo+bar"));
68+
69+
}
70+
71+
@Test
72+
// TODO: Fix this
73+
@Ignore
74+
public void testOutcomeRedirectWithEqual() throws Exception
75+
{
76+
77+
HtmlPage startPage = getWebClient("/start").getPage();
78+
HtmlPage secondPage = startPage.getElementById("form:redirectWithEqual").click();
79+
80+
assertThat(secondPage.getUrl().toString(), endsWith("/page/foo%3Dbar&query=foo%3Dbar"));
81+
82+
}
83+
84+
@Test
85+
// TODO: Fix this
86+
@Ignore
87+
public void testOutcomeRedirectWithAmpersand() throws Exception
88+
{
89+
90+
HtmlPage startPage = getWebClient("/start").getPage();
91+
HtmlPage secondPage = startPage.getElementById("form:redirectWithAmpersand").click();
92+
93+
assertThat(secondPage.getUrl().toString(), endsWith("/page/foo%26bar&query=foo%26bar"));
94+
95+
}
96+
97+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version='1.0' encoding='UTF-8' ?>
2+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets">
4+
5+
Empty
6+
7+
</html>
8+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version='1.0' encoding='UTF-8' ?>
2+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets">
4+
5+
<h:body>
6+
7+
<h:form id="form">
8+
9+
<h:commandButton id="redirectSimple" value="redirectSimple"
10+
action="#{outcomeEncodingBean.redirectSimple}" />
11+
12+
<h:commandButton id="redirectWithSpace" value="redirectWithSpace"
13+
action="#{outcomeEncodingBean.redirectWithSpace}" />
14+
15+
<h:commandButton id="redirectWithEqual" value="redirectWithEqual"
16+
action="#{outcomeEncodingBean.redirectWithEqual}" />
17+
18+
<h:commandButton id="redirectWithAmpersand" value="redirectWithAmpersand"
19+
action="#{outcomeEncodingBean.redirectWithAmpersand}" />
20+
21+
</h:form>
22+
23+
</h:body>
24+
25+
</html>
26+

0 commit comments

Comments
 (0)