1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.http.test;
12
13 import static org.junit.Assert.assertEquals;
14
15 import java.net.HttpURLConnection;
16 import java.net.URI;
17
18 import org.eclipse.jetty.servlet.ServletContextHandler;
19 import org.eclipse.jetty.servlet.ServletHolder;
20 import org.eclipse.jgit.http.server.glue.ErrorServlet;
21 import org.eclipse.jgit.junit.http.AppServer;
22 import org.junit.After;
23 import org.junit.Before;
24 import org.junit.Test;
25
26 public class ErrorServletTest {
27 private AppServer server;
28
29 @Before
30 public void setUp() throws Exception {
31
32 server = new AppServer();
33
34 ServletContextHandler ctx = server.addContext("/");
35 ctx.addServlet(new ServletHolder(new ErrorServlet(404)), "/404");
36 ctx.addServlet(new ServletHolder(new ErrorServlet(500)), "/500");
37
38 server.setUp();
39 }
40
41 @After
42 public void tearDown() throws Exception {
43 if (server != null) {
44 server.tearDown();
45 }
46 }
47
48 @Test
49 public void testHandler() throws Exception {
50 final URI uri = server.getURI();
51 assertEquals(404, ((HttpURLConnection) uri.resolve("/404").toURL()
52 .openConnection()).getResponseCode());
53 assertEquals(500, ((HttpURLConnection) uri.resolve("/500").toURL()
54 .openConnection()).getResponseCode());
55 }
56 }