Skip to content

Commit 1fd1d69

Browse files
committed
Adding a new sample/test to check for EL injection without beans.xml
1 parent fc60687 commit 1fd1d69

File tree

5 files changed

+106
-0
lines changed

5 files changed

+106
-0
lines changed

cdi/nobeans-el-injection/pom.xml

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</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;
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 ScopedBean {
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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>Facelet Title</title>
7+
</h:head>
8+
<h:body>
9+
#{scopedBean.sayHello()}
10+
</h:body>
11+
</html>
12+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.javaee7.cdi.nobeans.el.injection;
2+
3+
import com.meterware.httpunit.GetMethodWebRequest;
4+
import com.meterware.httpunit.WebConversation;
5+
import java.io.File;
6+
import java.net.URL;
7+
import org.jboss.arquillian.container.test.api.Deployment;
8+
import org.jboss.arquillian.junit.Arquillian;
9+
import org.jboss.shrinkwrap.api.ShrinkWrap;
10+
import org.junit.Test;
11+
import org.junit.runner.RunWith;
12+
13+
import org.jboss.arquillian.test.api.ArquillianResource;
14+
import org.jboss.shrinkwrap.api.spec.WebArchive;
15+
16+
/**
17+
* @author Arun Gupta
18+
*/
19+
@RunWith(Arquillian.class)
20+
public class ScopedBeanTest {
21+
22+
private static final String WEBAPP_SRC = "src/main/webapp";
23+
24+
@ArquillianResource
25+
private URL base;
26+
27+
@Deployment(testable=false)
28+
public static WebArchive deploy() {
29+
return ShrinkWrap.create(WebArchive.class)
30+
.addClass(ScopedBean.class)
31+
.addAsWebInfResource((new File(WEBAPP_SRC + "/WEB-INF", "web.xml")))
32+
.addAsWebResource((new File(WEBAPP_SRC, "index.xhtml")));
33+
}
34+
35+
@Test
36+
public void checkRenderedPage() throws Exception {
37+
WebConversation conv = new WebConversation();
38+
GetMethodWebRequest getRequest = new GetMethodWebRequest(base + "/faces/index.xhtml");
39+
String responseText = conv.getResponse(getRequest).getText();
40+
assert(responseText.contains("Hello there!"));
41+
}
42+
}

0 commit comments

Comments
 (0)