Skip to content

Commit 7c212cd

Browse files
committed
Added test for rewrite using 'url' attribute
1 parent 690a45f commit 7c212cd

2 files changed

Lines changed: 41 additions & 5 deletions

File tree

‎tests-jsf2/src/test/java/com/ocpsoft/pretty/faces/test/encoding/URLEncodingTest.java‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,42 @@ public static Archive<?> createDeployment()
5353
.setWebXML("jsf-web.xml");
5454
}
5555

56+
/**
57+
* Test a rewrite rule using the 'substitute' attribute to
58+
* modify the URL.
59+
*
60+
* @see http://code.google.com/p/prettyfaces/issues/detail?id=76
61+
*/
5662
@Test
57-
// http://code.google.com/p/prettyfaces/issues/detail?id=76
58-
public void testRewriteEncoding() throws Exception
63+
public void testRewriteEncodingSubstitute() throws Exception
5964
{
60-
String target = "/virtual";
65+
String target = "/virtual/rewrite/substitute";
66+
String expected = "/virtuální";
67+
68+
JSFSession jsfSession = new JSFSession(target);
69+
JSFServerSession server = jsfSession.getJSFServerSession();
70+
71+
JSFClientSession client = jsfSession.getJSFClientSession();
72+
String action = client.getElement("form").getAttribute("action");
73+
74+
FacesContext context = server.getFacesContext();
75+
PrettyContext prettyContext =
76+
PrettyContext.getCurrentInstance(context);
77+
78+
assertEquals(expected, prettyContext.getRequestURL().toString());
79+
assertEquals(prettyContext.getContextPath() + expected, action);
80+
}
81+
82+
/**
83+
* Test a rewrite rule using the 'url' attribute to
84+
* create a completely new URL.
85+
*
86+
* @see http://code.google.com/p/prettyfaces/issues/detail?id=76
87+
*/
88+
@Test
89+
public void testRewriteEncodingUrl() throws Exception
90+
{
91+
String target = "/virtual/rewrite/url";
6192
String expected = "/virtuální";
6293

6394
JSFSession jsfSession = new JSFSession(target);

‎tests-jsf2/src/test/resources/encoding/encoding-pretty-config.xml‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@
2828
<view-id> /encoding.jsf </view-id>
2929
</url-mapping>
3030

31-
<rewrite match="^/virtual$" substitute="/virtuální" redirect="301" />
31+
<!-- Rewrite using substitute -->
32+
<rewrite match="^/virtual/rewrite/substitute$" substitute="/virtuální" redirect="301" />
33+
34+
<!-- Rewrite using new URL -->
35+
<rewrite match="^/virtual/rewrite/url$" url="/test/virtuální" redirect="301" />
36+
3237
<!--
3338
<rewrite match="^/virtualencoded$" url="/virtu%C3%A1ln%C3%AD" redirect="301" />
3439
-->
35-
40+
3641
<url-mapping id="virtual">
3742
<pattern value="/virtuální"></pattern>
3843
<view-id>/encoding.jsf</view-id>

0 commit comments

Comments
 (0)