Skip to content

Commit 06e2a6e

Browse files
committed
adding simple-servlet module
1 parent 3867803 commit 06e2a6e

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed

servlet/simple-servlet/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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.servlet</groupId>
6+
<artifactId>servlet-samples</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<relativePath>../pom.xml</relativePath>
9+
</parent>
10+
11+
<groupId>org.javaee7.servlet</groupId>
12+
<artifactId>simple-servlet</artifactId>
13+
<version>1.0-SNAPSHOT</version>
14+
<packaging>war</packaging>
15+
</project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.javaee7.servlet.simple;
2+
3+
import java.io.IOException;
4+
import javax.servlet.ServletException;
5+
import javax.servlet.annotation.WebServlet;
6+
import javax.servlet.http.HttpServlet;
7+
import javax.servlet.http.HttpServletRequest;
8+
import javax.servlet.http.HttpServletResponse;
9+
10+
/**
11+
* @author Arun Gupta
12+
*/
13+
@WebServlet("/SimpleServlet")
14+
public class SimpleServlet extends HttpServlet {
15+
@Override
16+
protected void doGet(HttpServletRequest request, HttpServletResponse response)
17+
throws ServletException, IOException {
18+
response.getWriter().print("my GET");
19+
}
20+
21+
@Override
22+
protected void doPost(HttpServletRequest request, HttpServletResponse response)
23+
throws ServletException, IOException {
24+
response.getWriter().print("my POST");
25+
}
26+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<%@page contentType="text/html" pageEncoding="UTF-8"%>
2+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
3+
"http://www.w3.org/TR/html4/loose.dtd">
4+
5+
<html>
6+
<head>
7+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
8+
<title>Simple Servlet</title>
9+
</head>
10+
<body>
11+
<h1>Simple Servlet</h1>
12+
Call the <a href="${pageContext.request.contextPath}/SimpleServlet"/>servlet</a>.
13+
</body>
14+
</html>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.javaee7.servlet.metadata.complete;
2+
3+
import org.javaee7.servlet.simple.SimpleServlet;
4+
import com.gargoylesoftware.htmlunit.HttpMethod;
5+
import com.gargoylesoftware.htmlunit.TextPage;
6+
import com.gargoylesoftware.htmlunit.WebClient;
7+
import com.gargoylesoftware.htmlunit.WebRequest;
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 static org.junit.Assert.*;
17+
import org.junit.Before;
18+
import org.junit.Test;
19+
import org.junit.runner.RunWith;
20+
import org.xml.sax.SAXException;
21+
22+
/**
23+
* @author Arun Gupta
24+
*/
25+
@RunWith(Arquillian.class)
26+
public class SimpleServletTest {
27+
28+
@ArquillianResource
29+
private URL base;
30+
31+
WebClient webClient;
32+
33+
@Deployment(testable = false)
34+
public static WebArchive createDeployment() {
35+
WebArchive war = ShrinkWrap.create(WebArchive.class)
36+
.addClass(SimpleServlet.class);
37+
return war;
38+
}
39+
40+
@Before
41+
public void setup() {
42+
webClient = new WebClient();
43+
}
44+
45+
@Test
46+
public void testGet() throws IOException, SAXException {
47+
TextPage page = webClient.getPage(base + "/SimpleServlet");
48+
assertEquals("my GET", page.getContent());
49+
}
50+
51+
@Test
52+
public void testPost() throws IOException, SAXException {
53+
WebRequest request = new WebRequest(new URL(base + "/SimpleServlet"), HttpMethod.POST);
54+
TextPage page = webClient.getPage(request);
55+
assertEquals("my POST", page.getContent());
56+
}
57+
}

0 commit comments

Comments
 (0)