Skip to content

Commit 64c512f

Browse files
committed
Added new tests
1 parent 928b65f commit 64c512f

File tree

6 files changed

+97
-18
lines changed

6 files changed

+97
-18
lines changed

jsf/http-get/src/main/java/org/javaee7/jsf/http/get/User.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class User {
5454
private String name;
5555

5656
public String getName() {
57+
System.out.println("getName: " + name);
5758
return name;
5859
}
5960

jsf/http-get/src/main/webapp/index.xhtml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@
99
<h:body>
1010
<h1>JSF and HTTP GET</h1>
1111

12-
h:link <h:link value="Login" outcome="login"/><br/><br/>
12+
h:link <h:link value="Login1" outcome="login" id="link1"/><br/><br/>
1313

14-
h:link with f:param: <h:link value="Login" outcome="login">
14+
h:link with f:param: <h:link value="Login2" outcome="login" id="link2">
1515
<f:param name="name" value="Jack"/>
1616
</h:link><br/><br/>
17-
h:link with f:param <h:link value="pre-process params before rendering" outcome="index2" >
17+
18+
h:link with f:param (pre-process) <h:link value="Login3" outcome="index2" id="link3">
1819
<f:param name="name" value="Jack"/>
1920
</h:link>
2021

2122
<br/><br/>
22-
h:button: <h:button value="login"/>
23+
h:button: <h:button value="Login4" id="button1" outcome="login"/>
2324
</h:body>
2425
</html>
2526

jsf/http-get/src/main/webapp/index2.xhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<f:viewParam name="name" value="#{user.name}">
1414
<f:validateLength minimum="1" maximum="5"/>
1515
</f:viewParam>
16-
<f:event type="preRenderView" listener="#{user.process2}"/>
1716
</f:metadata>
17+
1818
Post-processed name: <h:outputText value="#{user.name}"/>
1919
</h:body>
2020
</html>

jsf/http-get/src/main/webapp/login.xhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<html xmlns="http://www.w3.org/1999/xhtml"
44
xmlns:h="http://xmlns.jcp.org/jsf/html">
55
<h:head>
6-
<title>Facelet Title</title>
6+
<title>HTTP GET (Login)</title>
77
</h:head>
88
<h:body>
99
<h1>HTTP GET (Login)</h1>

jsf/http-get/src/main/webapp/resources/stylesheets/main.css

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package org.javaee7.jsf.http.get;
2+
3+
import com.gargoylesoftware.htmlunit.WebClient;
4+
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
5+
import com.gargoylesoftware.htmlunit.html.HtmlButtonInput;
6+
import com.gargoylesoftware.htmlunit.html.HtmlElement;
7+
import com.gargoylesoftware.htmlunit.html.HtmlPage;
8+
import java.io.File;
9+
import java.io.IOException;
10+
import java.net.URL;
11+
import org.jboss.arquillian.container.test.api.Deployment;
12+
import org.jboss.arquillian.junit.Arquillian;
13+
import org.jboss.arquillian.test.api.ArquillianResource;
14+
import org.jboss.shrinkwrap.api.ShrinkWrap;
15+
import org.jboss.shrinkwrap.api.spec.WebArchive;
16+
import org.junit.Before;
17+
import org.junit.Test;
18+
import static org.junit.Assert.*;
19+
import org.junit.runner.RunWith;
20+
21+
/**
22+
* @author Arun Gupta
23+
*/
24+
@RunWith(Arquillian.class)
25+
public class UserTest {
26+
27+
@ArquillianResource
28+
private URL base;
29+
30+
WebClient webClient;
31+
32+
private static final String WEBAPP_SRC = "src/main/webapp";
33+
HtmlPage page;
34+
35+
@Deployment(testable = false)
36+
public static WebArchive createDeployment() {
37+
return ShrinkWrap.create(WebArchive.class).
38+
addClass(User.class)
39+
.addAsWebResource(new File(WEBAPP_SRC, "index.xhtml"))
40+
.addAsWebResource(new File(WEBAPP_SRC, "index2.xhtml"))
41+
.addAsWebResource(new File(WEBAPP_SRC, "login.xhtml"))
42+
.addAsWebInfResource(new File(WEBAPP_SRC + "/WEB-INF", "web.xml"))
43+
.addAsWebInfResource(new File(WEBAPP_SRC + "/WEB-INF", "beans.xml"));
44+
}
45+
46+
@Before
47+
public void setup() throws IOException {
48+
webClient = new WebClient();
49+
page = webClient.getPage(base + "/faces/index.xhtml");
50+
}
51+
52+
@Test
53+
public void testLink() throws IOException {
54+
HtmlAnchor anchor = (HtmlAnchor)page.getElementById("link1");
55+
assertTrue(anchor.getHrefAttribute().contains("faces/login.xhtml"));
56+
assertEquals("Login1", anchor.asText());
57+
58+
HtmlPage output = anchor.click();
59+
assertEquals("HTTP GET (Login)", output.getTitleText());
60+
}
61+
62+
@Test
63+
public void testLinkWithParam() throws IOException {
64+
HtmlAnchor anchor = (HtmlAnchor)page.getElementById("link2");
65+
assertTrue(anchor.getHrefAttribute().contains("faces/login.xhtml"));
66+
assertTrue(anchor.getHrefAttribute().contains("?name=Jack"));
67+
assertEquals("Login2", anchor.asText());
68+
69+
HtmlPage output = anchor.click();
70+
assertEquals("HTTP GET (Login)", output.getTitleText());
71+
}
72+
73+
@Test
74+
public void testLinkWithPreProcessParams() {
75+
HtmlAnchor anchor = (HtmlAnchor)page.getElementById("link3");
76+
assertEquals("Login3", anchor.asText());
77+
assertTrue(anchor.getHrefAttribute().contains("faces/index2.xhtml"));
78+
assertTrue(anchor.getHrefAttribute().contains("?name=Jack"));
79+
}
80+
81+
@Test
82+
public void testButton() throws IOException {
83+
HtmlButtonInput button = (HtmlButtonInput)page.getElementById("button1");
84+
assertEquals("Login4", button.asText());
85+
86+
HtmlPage output = button.click();
87+
assertEquals("HTTP GET (Login)", output.getTitleText());
88+
}
89+
}

0 commit comments

Comments
 (0)