Skip to content

Commit f03411c

Browse files
committed
Added integration test for #120
1 parent b5df0fa commit f03411c

4 files changed

Lines changed: 139 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.ocpsoft.pretty.faces.test.dynaview;
2+
3+
import javax.faces.bean.ManagedBean;
4+
import javax.faces.bean.RequestScoped;
5+
6+
import com.ocpsoft.pretty.faces.annotation.URLMapping;
7+
8+
@ManagedBean
9+
@RequestScoped
10+
@URLMapping(id = "dynaview", pattern = "/dynaview/#{ pathParamDynaViewBean.value }",
11+
viewId = "#{pathParamDynaViewBean.computeViewId}")
12+
public class PathParamDynaViewBean
13+
{
14+
15+
/**
16+
* Injected value of the path parameter
17+
*/
18+
private String value;
19+
20+
/**
21+
* This method is used to compute the view id! It will return
22+
* <code>/correct.jsf</code> if the path parameter property contains the
23+
* string <code>correct</code>. In all other cases it will return
24+
* <code>/wrong.jsf</code>.
25+
*/
26+
public String computeViewId()
27+
{
28+
29+
if (value != null && value.equals("correct"))
30+
{
31+
return "/correct.jsf";
32+
}
33+
else
34+
{
35+
return "/wrong.jsf";
36+
}
37+
38+
}
39+
40+
public String getValue()
41+
{
42+
return value;
43+
}
44+
45+
public void setValue(String value)
46+
{
47+
this.value = value;
48+
}
49+
50+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.ocpsoft.pretty.faces.test.dynaview;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import org.jboss.arquillian.api.Deployment;
6+
import org.jboss.arquillian.junit.Arquillian;
7+
import org.jboss.jsfunit.jsfsession.JSFClientSession;
8+
import org.jboss.jsfunit.jsfsession.JSFSession;
9+
import org.jboss.shrinkwrap.api.spec.WebArchive;
10+
import org.junit.Test;
11+
import org.junit.runner.RunWith;
12+
13+
import com.ocpsoft.pretty.faces.test.PrettyFacesTestBase;
14+
15+
@RunWith(Arquillian.class)
16+
public class PathParamDynaViewTest extends PrettyFacesTestBase
17+
{
18+
19+
@Deployment
20+
public static WebArchive createDeployment()
21+
{
22+
return PrettyFacesTestBase.createDeployment()
23+
.addClass(PathParamDynaViewBean.class)
24+
.addResource("dynaview/index.xhtml", "index.xhtml")
25+
.addResource("dynaview/correct.xhtml", "correct.xhtml");
26+
}
27+
28+
@Test
29+
public void testInjectionHappensBeforeViewDetermination() throws Exception
30+
{
31+
32+
// First visit the start page
33+
JSFSession jsfSession = new JSFSession("/index.jsf");
34+
35+
// click on the link talking the user to /dynaview/correct
36+
JSFClientSession client = jsfSession.getJSFClientSession();
37+
client.click("link");
38+
39+
// the dynaview code should send the user to the correct page.
40+
assertTrue(client.getPageAsText().contains("The path parameter was correctly injected"));
41+
42+
}
43+
44+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3+
<html xmlns="http://www.w3.org/1999/xhtml"
4+
xmlns:f="http://java.sun.com/jsf/core"
5+
xmlns:h="http://java.sun.com/jsf/html"
6+
xmlns:pretty="http://ocpsoft.com/prettyfaces"
7+
xmlns:ui="http://java.sun.com/jsf/facelets">
8+
9+
<head>
10+
<title>DynaView Test</title>
11+
</head>
12+
13+
<body>
14+
15+
<p>
16+
The path parameter was correctly injected!
17+
</p>
18+
19+
</body>
20+
21+
</html>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3+
<html xmlns="http://www.w3.org/1999/xhtml"
4+
xmlns:f="http://java.sun.com/jsf/core"
5+
xmlns:h="http://java.sun.com/jsf/html"
6+
xmlns:pretty="http://ocpsoft.com/prettyfaces"
7+
xmlns:ui="http://java.sun.com/jsf/facelets">
8+
9+
<head>
10+
<title>DynaView Test</title>
11+
</head>
12+
13+
<body>
14+
15+
<p>
16+
<pretty:link id="link" mappingId="dynaview">
17+
<f:param value="correct"/>
18+
<h:outputText value="Click me!" />
19+
</pretty:link>
20+
</p>
21+
22+
</body>
23+
24+
</html>

0 commit comments

Comments
 (0)