Skip to content

Commit d0f8466

Browse files
committed
Added a new test for @FlowScoped bean and EL injection
1 parent 5f837b9 commit d0f8466

File tree

7 files changed

+120
-0
lines changed

7 files changed

+120
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.javaee7.cdi</groupId>
6+
<artifactId>cdi-samples</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<relativePath>../pom.xml</relativePath>
9+
</parent>
10+
11+
<artifactId>nobeans-el-injection-flowscoped</artifactId>
12+
<packaging>war</packaging>
13+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.javaee7.cdi.nobeans.el.injection.flowscoped;
2+
3+
import javax.enterprise.context.RequestScoped;
4+
import javax.inject.Named;
5+
6+
/**
7+
* @author Arun Gupta
8+
*/
9+
@Named
10+
@RequestScoped
11+
public class FlowScopedBean {
12+
public String sayHello() {
13+
return "Hello there!";
14+
}
15+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
3+
<context-param>
4+
<param-name>javax.faces.PROJECT_STAGE</param-name>
5+
<param-value>Development</param-value>
6+
</context-param>
7+
<servlet>
8+
<servlet-name>Faces Servlet</servlet-name>
9+
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
10+
<load-on-startup>1</load-on-startup>
11+
</servlet>
12+
<servlet-mapping>
13+
<servlet-name>Faces Servlet</servlet-name>
14+
<url-pattern>/faces/*</url-pattern>
15+
</servlet-mapping>
16+
<session-config>
17+
<session-timeout>
18+
30
19+
</session-timeout>
20+
</session-config>
21+
<welcome-file-list>
22+
<welcome-file>faces/index.xhtml</welcome-file>
23+
</welcome-file-list>
24+
</web-app>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version='1.0' encoding='UTF-8' ?>
2+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3+
<html xmlns="http://www.w3.org/1999/xhtml"
4+
xmlns:h="http://xmlns.jcp.org/jsf/html">
5+
<h:head>
6+
<title>Flow Scoped Page</title>
7+
</h:head>
8+
<h:body>
9+
<h1>Flow Scoped Page</h1>
10+
#{flowScopedBean.sayHello()}
11+
</h:body>
12+
</html>
13+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version='1.0' encoding='UTF-8' ?>
2+
<faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="
5+
http://xmlns.jcp.org/xml/ns/javaee
6+
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
7+
8+
<flow-definition id="myflow"/>
9+
10+
</faces-config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.javaee7.cdi.nobeans.el.injection.flowscoped;
2+
3+
import org.javaee7.cdi.nobeans.el.injection.flowscoped.FlowScopedBean;
4+
import com.meterware.httpunit.GetMethodWebRequest;
5+
import com.meterware.httpunit.WebConversation;
6+
import java.io.File;
7+
import java.net.URL;
8+
import org.jboss.arquillian.container.test.api.Deployment;
9+
import org.jboss.arquillian.junit.Arquillian;
10+
import org.jboss.shrinkwrap.api.ShrinkWrap;
11+
import org.junit.Test;
12+
import org.junit.runner.RunWith;
13+
14+
import org.jboss.arquillian.test.api.ArquillianResource;
15+
import org.jboss.shrinkwrap.api.spec.WebArchive;
16+
17+
/**
18+
* @author Arun Gupta
19+
*/
20+
@RunWith(Arquillian.class)
21+
public class FlowScopedBeanTest {
22+
23+
private static final String WEBAPP_SRC = "src/main/webapp";
24+
25+
@ArquillianResource
26+
private URL base;
27+
28+
@Deployment(testable=false)
29+
public static WebArchive deploy() {
30+
return ShrinkWrap.create(WebArchive.class)
31+
.addClass(FlowScopedBean.class)
32+
.addAsWebInfResource((new File(WEBAPP_SRC + "/WEB-INF", "web.xml")))
33+
.addAsWebResource((new File(WEBAPP_SRC, "myflow/myflow-flow.xml")), "myflow/myflow-flow.xml")
34+
.addAsWebResource((new File(WEBAPP_SRC, "myflow/index.xhtml")), "myflow/index.xhtml");
35+
}
36+
37+
@Test
38+
public void checkRenderedPage() throws Exception {
39+
WebConversation conv = new WebConversation();
40+
GetMethodWebRequest getRequest = new GetMethodWebRequest(base + "/faces/myflow/index.xhtml");
41+
String responseText = conv.getResponse(getRequest).getText();
42+
assert(responseText.contains("Hello there!"));
43+
}
44+
}

cdi/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
<module>scopes</module>
3232
<module>alternatives</module>
3333
<module>nobeans-el-injection</module>
34+
<module>nobeans-el-injection-flowscoped</module>
3435
</modules>
3536
</project>

0 commit comments

Comments
 (0)