/
HelloJSFTest.java
107 lines (90 loc) · 4.22 KB
/
HelloJSFTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.jsfunit.example.hellojsf;
import java.io.File;
import java.io.IOException;
import javax.faces.component.UIComponent;
import junit.framework.Assert;
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.jsfunit.api.InitialPage;
import org.jboss.jsfunit.jsfsession.JSFClientSession;
import org.jboss.jsfunit.jsfsession.JSFServerSession;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.DependencyResolvers;
import org.jboss.shrinkwrap.resolver.api.maven.MavenDependencyResolver;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Version of the HelloJSFTest that uses Arquillian
*
* @author Stan Silvert
*/
@RunWith(Arquillian.class)
public class HelloJSFTest
{
// property surefire sys prop setting
public static final boolean IS_JETTY = (System.getProperty("jetty-embedded") != null);
@Deployment
public static WebArchive createDeployment() {
WebArchive war =
ShrinkWrap.create(WebArchive.class, "test.war")
.setWebXML(new File("src/main/webapp/WEB-INF/web.xml"))
.addPackage(Package.getPackage("org.jboss.jsfunit.example.hellojsf")) // my test package
.addAsWebResource(new File("src/main/webapp", "index.xhtml"))
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsWebInfResource(new File("src/main/webapp/WEB-INF/faces-config.xml"), "faces-config.xml");
prepareForJetty(war);
// System.out.println(war.toString(true)); // for debugging
return war;
}
private static void prepareForJetty(WebArchive war)
{
if (!IS_JETTY) return;
war.setWebXML(new File("src/main/jetty/web.xml")) // jetty web.xml needs extra declarations
.addAsWebInfResource(new File("src/main/jetty/jetty-env.xml"), "jetty-env.xml")
.addAsLibraries(
DependencyResolvers.use(MavenDependencyResolver.class).artifacts(
"com.sun.faces:jsf-api:2.0.4-b03",
"com.sun.faces:jsf-impl:2.0.4-b03",
"org.glassfish.web:el-impl:2.2",
"javax.annotation:jsr250-api:1.0",
"javax.servlet:jstl:1.2").resolveAsFiles());
}
@Test
@InitialPage("/index.faces")
public void testInitialPage(JSFServerSession server, JSFClientSession client) throws IOException
{
// Test navigation to initial viewID
Assert.assertEquals("/index.xhtml", server.getCurrentViewID());
// Set the param and submit
client.setValue("name", "Stan");
client.click("submit_button");
// Assert that the greeting component is in the component tree and rendered
UIComponent greeting = server.findComponent("greeting");
Assert.assertTrue(greeting.isRendered());
// Test a managed bean using EL. We cheat and use the request object.
Assert.assertEquals("Stan", server.getManagedBeanValue("#{request.getParameter('form1:name')}"));
}
}