01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse;
04:
05: import fitnesse.testutil.AbstractRegex;
06: import fitnesse.http.ResponseParser;
07: import java.net.UnknownHostException;
08:
09: public class ShutdownTest extends AbstractRegex {
10: private Shutdown shutdown;
11:
12: public void setUp() throws Exception {
13: shutdown = new Shutdown();
14: }
15:
16: public void tearDown() throws Exception {
17: }
18:
19: public void testArgs() throws Exception {
20: assertTrue(shutdown.parseArgs(new String[] {}));
21: assertEquals("localhost", shutdown.hostname);
22: assertEquals(80, shutdown.port);
23: assertEquals(null, shutdown.username);
24: assertEquals(null, shutdown.password);
25:
26: assertTrue(shutdown.parseArgs(new String[] { "-h", "host.com",
27: "-p", "1234", "-c", "user", "pass" }));
28: assertEquals("host.com", shutdown.hostname);
29: assertEquals(1234, shutdown.port);
30: assertEquals("user", shutdown.username);
31: assertEquals("pass", shutdown.password);
32: }
33:
34: public void testBuildRequest() throws Exception {
35: String request = shutdown.buildRequest().getText();
36: assertSubString("GET /?responder=shutdown", request);
37: assertNotSubString("Authorization: ", request);
38:
39: shutdown.username = "user";
40: shutdown.password = "pass";
41: request = shutdown.buildRequest().getText();
42: assertSubString("Authorization: ", request);
43: }
44:
45: public void testBadServer() throws Exception {
46: try {
47: shutdown.hostname = "www.google.com";
48: ResponseParser response = shutdown.buildAndSendRequest();
49: String status = shutdown.checkResponse(response);
50: assertEquals("Not a FitNesse server", status);
51: } catch (UnknownHostException e) {
52: }
53: }
54: }
|