01: package org.nanocontainer.webcontainer;
02:
03: import java.io.File;
04: import java.io.FileNotFoundException;
05: import java.io.IOException;
06: import java.net.URL;
07:
08: import org.picocontainer.alternatives.EmptyPicoContainer;
09:
10: public class StaticFileTestCase extends WebContainerTestCase {
11:
12: PicoJettyServer server;
13:
14: protected void tearDown() throws Exception {
15: if (server != null) {
16: server.stop();
17: }
18: }
19:
20: public void testStaticFile() throws InterruptedException,
21: IOException {
22:
23: File warFile = TestHelper.getTestWarFile();
24:
25: server = new PicoJettyServer("localhost", 8080,
26: new EmptyPicoContainer());
27: PicoContext barContext = server.createContext("/bar", false);
28: barContext.setStaticContext(warFile.getParentFile()
29: .getAbsolutePath());
30:
31: server.start();
32:
33: assertEquals("<html>\n" + " <body>\n" + " hello\n"
34: + " </body>\n" + "</html>",
35: getPage("http://localhost:8080/bar/hello.html"));
36:
37: }
38:
39: public void testDifferentWelcomePage() throws InterruptedException,
40: IOException {
41:
42: File warFile = TestHelper.getTestWarFile();
43:
44: server = new PicoJettyServer("localhost", 8080,
45: new EmptyPicoContainer());
46: PicoContext barContext = server.createContext("/bar", false);
47: barContext.setStaticContext(warFile.getParentFile()
48: .getAbsolutePath(), "hello.html");
49:
50: server.start();
51:
52: assertEquals("<html>\n" + " <body>\n" + " hello\n"
53: + " </body>\n" + "</html>",
54: getPage("http://localhost:8080/bar/"));
55:
56: }
57:
58: public void testMissingPage() throws InterruptedException,
59: IOException {
60:
61: File warFile = TestHelper.getTestWarFile();
62:
63: server = new PicoJettyServer("localhost", 8080,
64: new EmptyPicoContainer());
65: PicoContext barContext = server.createContext("/bar", false);
66: barContext.setStaticContext(warFile.getParentFile()
67: .getAbsolutePath());
68:
69: server.start();
70:
71: URL url = new URL("http://localhost:8080/bar/HearMeRoar!");
72: try {
73: url.openStream();
74: fail("should have barfed");
75: } catch (FileNotFoundException e) {
76: // expected
77: }
78:
79: }
80:
81: }
|