Skip to content

Commit 1a95973

Browse files
committed
Fixes issue #109 - Add a JSP HelloWorld example
1 parent 2d90e37 commit 1a95973

File tree

8 files changed

+172
-0
lines changed

8 files changed

+172
-0
lines changed

jsp/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# JSP Examples
2+
3+
1. [A JSP HelloWorld example](helloWorld/README.md)

jsp/helloWorld/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# A h:outputText example
2+
3+
This example demonstrates how to use h:outputText.

jsp/helloWorld/pom.xml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
<parent>
8+
<artifactId>project</artifactId>
9+
<groupId>jakartaee.examples.jsp</groupId>
10+
<version>8-SNAPSHOT</version>
11+
</parent>
12+
<artifactId>jspHelloWorld</artifactId>
13+
<packaging>war</packaging>
14+
<name>A JSP HelloWorld example</name>
15+
<dependencies>
16+
<dependency>
17+
<groupId>javax</groupId>
18+
<artifactId>javaee-web-api</artifactId>
19+
<scope>provided</scope>
20+
</dependency>
21+
</dependencies>
22+
<properties>
23+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24+
</properties>
25+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<web-app version="3.0"
4+
xmlns="http://java.sun.com/xml/ns/javaee"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
7+
<welcome-file-list>
8+
<welcome-file>index.jsp</welcome-file>
9+
</welcome-file-list>
10+
</web-app>
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<%@page contentType="text/html" pageEncoding="UTF-8"%>
2+
3+
<!DOCTYPE html>
4+
<html>
5+
<head>
6+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
7+
<title>Hello World example</title>
8+
</head>
9+
<body>
10+
<h1>Hello World!</h1>
11+
</body>
12+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Permission to use, copy, modify, and/or distribute this software for any
3+
* purpose with or without fee is hereby granted.
4+
*
5+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIMS ALL WARRANTIES
6+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
7+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR
8+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
9+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
10+
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
11+
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
12+
*/
13+
package jakartaee.examples.jsp.helloworld;
14+
15+
import com.gargoylesoftware.htmlunit.WebClient;
16+
import com.gargoylesoftware.htmlunit.html.HtmlPage;
17+
import jakartaee.examples.test.commons.JakartaEEServer;
18+
import java.io.File;
19+
import java.net.URL;
20+
import org.arquillian.container.chameleon.runner.ArquillianChameleon;
21+
import org.jboss.arquillian.container.test.api.Deployment;
22+
import org.jboss.arquillian.container.test.api.RunAsClient;
23+
import org.jboss.arquillian.test.api.ArquillianResource;
24+
import static org.jboss.shrinkwrap.api.ShrinkWrap.create;
25+
import org.jboss.shrinkwrap.api.spec.WebArchive;
26+
import org.junit.After;
27+
import static org.junit.Assert.assertTrue;
28+
import org.junit.Before;
29+
import org.junit.Test;
30+
import org.junit.runner.RunWith;
31+
32+
/**
33+
* The JUnit tests for the JSP HelloWorld example.
34+
*
35+
* @author Manfred Riem ([email protected])
36+
*/
37+
@RunWith(ArquillianChameleon.class)
38+
@JakartaEEServer
39+
public class HelloWorldTest {
40+
41+
/**
42+
* Stores the base URL.
43+
*/
44+
@ArquillianResource
45+
private URL baseUrl;
46+
47+
/**
48+
* Stores the web client.
49+
*/
50+
private WebClient webClient;
51+
52+
/**
53+
* Setup before testing.
54+
*/
55+
@Before
56+
public void before() {
57+
webClient = new WebClient();
58+
}
59+
60+
/**
61+
* Create the deployment web archive.
62+
*
63+
* @return the deployment web archive.
64+
*/
65+
@Deployment
66+
public static WebArchive createDeployment() {
67+
return create(WebArchive.class).
68+
addAsWebResource(new File("src/main/webapp/index.jsp")).
69+
addAsWebInfResource(new File("src/main/webapp/WEB-INF/web.xml"));
70+
}
71+
72+
/**
73+
* Tear down after testing.
74+
*/
75+
@After
76+
public void after() {
77+
webClient.close();
78+
}
79+
80+
/**
81+
* Test the JSP HelloWorld example.
82+
*
83+
* @throws Exception when a serious error occurs.
84+
*/
85+
@RunAsClient
86+
@Test
87+
public void testHelloWorld() throws Exception {
88+
HtmlPage page = webClient.getPage(baseUrl);
89+
assertTrue(page.asXml().contains("Hello World!"));
90+
}
91+
}

jsp/pom.xml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
<parent>
8+
<groupId>jakartaee.examples</groupId>
9+
<artifactId>project</artifactId>
10+
<version>8-SNAPSHOT</version>
11+
</parent>
12+
<groupId>jakartaee.examples.jsp</groupId>
13+
<artifactId>project</artifactId>
14+
<packaging>pom</packaging>
15+
<name>JSP Examples</name>
16+
<modules>
17+
<module>helloWorld</module>
18+
</modules>
19+
<dependencies>
20+
<dependency>
21+
<groupId>jakartaee.examples</groupId>
22+
<artifactId>test-commons</artifactId>
23+
<version>${project.version}</version>
24+
<scope>test</scope>
25+
</dependency>
26+
</dependencies>
27+
</project>

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
<module>jaxrs</module>
131131
<module>jpa</module>
132132
<module>jsf</module>
133+
<module>jsp</module>
133134
<module>jsonb</module>
134135
<module>jsonp</module>
135136
<module>servlet</module>

0 commit comments

Comments
 (0)