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 junit.framework.*;
06: import junit.swingui.TestRunner;
07: import fitnesse.util.FileUtil;
08: import fitnesse.authentication.*;
09: import fitnesse.testutil.FitNesseUtil;
10:
11: import java.io.*;
12:
13: public class FitNesseMainTest extends TestCase {
14: private static final String TEST_FITNESSE_ROOT = System
15: .getProperty("java.io.tmpdir")
16: + File.separator + "testFitnesseRoot";
17:
18: private FitNesseContext context;
19:
20: public static void main(String[] args) {
21: TestRunner.main(new String[] { "FitNesseMainTest" });
22: }
23:
24: public void setUp() throws Exception {
25: context = new FitNesseContext();
26: }
27:
28: public void tearDown() throws Exception {
29: FileUtil.deleteFileSystemDirectory(TEST_FITNESSE_ROOT);
30: }
31:
32: public void testDirCreations() throws Exception {
33: context.port = 80;
34: context.rootPagePath = TEST_FITNESSE_ROOT;
35: new FitNesse(context);
36:
37: assertTrue(new File(TEST_FITNESSE_ROOT).exists());
38: assertTrue(new File(TEST_FITNESSE_ROOT, "files").exists());
39: }
40:
41: public void testMakeNullAuthenticator() throws Exception {
42: Authenticator a = FitNesse.makeAuthenticator(null,
43: new ComponentFactory("blah"));
44: assertTrue(a instanceof PromiscuousAuthenticator);
45: }
46:
47: public void testMakeOneUserAuthenticator() throws Exception {
48: Authenticator a = FitNesse.makeAuthenticator("bob:uncle",
49: new ComponentFactory("blah"));
50: assertTrue(a instanceof OneUserAuthenticator);
51: OneUserAuthenticator oua = (OneUserAuthenticator) a;
52: assertEquals("bob", oua.getUser());
53: assertEquals("uncle", oua.getPassword());
54: }
55:
56: public void testMakeMultiUserAuthenticator() throws Exception {
57: final String passwordFilename = "testpasswd";
58: File passwd = new File(passwordFilename);
59: passwd.createNewFile();
60: Authenticator a = FitNesse.makeAuthenticator(passwordFilename,
61: new ComponentFactory("blah"));
62: assertTrue(a instanceof MultiUserAuthenticator);
63: passwd.delete();
64: }
65:
66: public void testContextFitNesseGetSet() throws Exception {
67: FitNesse fitnesse = new FitNesse(context, false);
68: assertSame(fitnesse, context.fitnesse);
69: }
70:
71: public void testIsRunning() throws Exception {
72: context.port = FitNesseUtil.port;
73: FitNesse fitnesse = new FitNesse(context, false);
74:
75: assertFalse(fitnesse.isRunning());
76:
77: fitnesse.start();
78: assertTrue(fitnesse.isRunning());
79:
80: fitnesse.stop();
81: assertFalse(fitnesse.isRunning());
82: }
83: }
|