Skip to content

Commit a5fca2d

Browse files
author
Bruno Novais
committed
LocaleTranspositionTest for outbound rewriting.
1 parent 5330d7d commit a5fca2d

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎api-tests/src/test/java/org/ocpsoft/rewrite/transposition/LocaleTranspositionConfigurationProvider.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public int priority()
4343
public Configuration getConfiguration(final ServletContext context)
4444
{
4545
Configuration config = ConfigurationBuilder.begin()
46+
.addRule(Join.path("/{lang}/{path}.xhtml").to("/{path}.xhtml"))
47+
.where("path").transposedBy(LocaleTransposition.bundle("bundle", "lang"))
48+
4649
.addRule(Join.path("/{lang}/{path}").to("/{path}"))
4750
.where("path").configuredBy(LocaleTransposition.bundle("bundle", "lang"))
4851

‎api-tests/src/test/java/org/ocpsoft/rewrite/transposition/LocaleTranspositionTest.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ public static WebArchive getDeployment()
4646
WebArchive deployment = RewriteTest
4747
.getDeployment()
4848
.addPackages(true, Root.class.getPackage())
49+
.setWebXML(new File("src/test/webapp/WEB-INF/web.xml"))
4950
.addAsServiceProvider(ConfigurationProvider.class, LocaleTranspositionConfigurationProvider.class)
5051
.addAsWebResource(new StringAsset("search page"), "search")
5152
.addAsWebResource(new StringAsset("library page"), "library")
53+
.addAsWebResource(new File("src/test/webapp/search.xhtml"))
5254
.addAsResource(new File("src/test/resources/bundle_fr.properties"))
5355
.addAsResource(new File("src/test/resources/bundle_en.properties"));
5456
return deployment;
@@ -77,6 +79,14 @@ public void testI18nSupportWithAccent() throws Exception
7779
Assert.assertEquals("library page", action.getResponseContent());
7880
}
7981

82+
@Test
83+
public void testI18nSupportOutbound() throws Exception
84+
{
85+
HttpAction<HttpGet> action = get("/en/search.xhtml");
86+
Assert.assertEquals(200, action.getResponse().getStatusLine().getStatusCode());
87+
Assert.assertThat(action.getResponseContent(), org.junit.matchers.JUnitMatchers.containsString("/en/search"));
88+
}
89+
8090
/**
8191
* Expected behavior(default) when used as a Transposition and Constraint is to abort the rule so 404 is expected.
8292
*
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
5+
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
6+
<context-param>
7+
<param-name>javax.faces.PROJECT_STAGE</param-name>
8+
<param-value>Development</param-value>
9+
</context-param>
10+
<servlet>
11+
<servlet-name>Faces Servlet</servlet-name>
12+
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
13+
</servlet>
14+
<servlet-mapping>
15+
<servlet-name>Faces Servlet</servlet-name>
16+
<url-pattern>*.xhtml</url-pattern>
17+
</servlet-mapping>
18+
</web-app>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core">
3+
<h:head>
4+
<meta charset="utf-8" />
5+
</h:head>
6+
<h:body>
7+
<h:link outcome="/search.xhtml" value="Test"></h:link>
8+
</h:body>
9+
</html>

0 commit comments

Comments
 (0)