KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > bootstrappers > AlienBrainBootstrapperTest


1 package net.sourceforge.cruisecontrol.bootstrappers;
2
3 import junit.framework.TestCase;
4 import net.sourceforge.cruisecontrol.CruiseControlException;
5
6 public class AlienBrainBootstrapperTest extends TestCase {
7
8     public void testValidate() {
9         AlienBrainBootstrapper bootStrapper = new AlienBrainBootstrapper();
10
11         try {
12             bootStrapper.validate();
13             fail("should throw an exception when no attributes are set");
14         } catch (CruiseControlException e) {
15         }
16
17         bootStrapper.setPath("alienbrain://A/File/That/I/Want.txt");
18
19         try {
20             bootStrapper.validate();
21         } catch (CruiseControlException e) {
22             fail("should not throw exceptions when required "
23                 + "attributes are set.\n" + e);
24         }
25
26         bootStrapper.setOverwriteWritable("notSkip");
27         try {
28             bootStrapper.validate();
29             fail("should throw an exception when an attribute has an invalid value");
30         } catch (CruiseControlException e) {
31         }
32         
33         bootStrapper.setOverwriteWritable("notReplace");
34         try {
35             bootStrapper.validate();
36             fail("should throw an exception when an attribute has an invalid value");
37         } catch (CruiseControlException e) {
38         }
39
40         //test both non-default valid value and capital handling.
41
bootStrapper.setOverwriteWritable("RePlaCe");
42         try {
43             bootStrapper.validate();
44         } catch (CruiseControlException e) {
45             fail("should not throw exceptions when required "
46                 + "attributes are set.\n" + e);
47         }
48     }
49
50     public void testBuildBootstrapCommand() {
51         AlienBrainBootstrapper bootStrapper = new AlienBrainBootstrapper();
52
53         String JavaDoc user = "foo";
54         String JavaDoc path = "alienbrain://A/File/That/I/Want.txt";
55         String JavaDoc password = "foobar";
56         String JavaDoc localpath = "c:\\My Projects";
57
58         bootStrapper.setPath(path);
59         assertEquals("ab getlatest " + path + " -overwritewritable skip",
60             bootStrapper.buildBootstrapCommand().toString());
61         
62         bootStrapper.setUser(user);
63         assertEquals("ab -u " + user + " getlatest " + path
64             + " -overwritewritable skip",
65             bootStrapper.buildBootstrapCommand().toString());
66         
67         bootStrapper.setPassword(password);
68         assertEquals("ab -u " + user + " -p " + password + " getlatest "
69             + path + " -overwritewritable skip",
70             bootStrapper.buildBootstrapCommand().toString());
71
72         bootStrapper.setLocalPath(localpath);
73         assertEquals("ab -u " + user + " -p " + password + " getlatest " + path
74             + " -localpath \"" + localpath + "\" -overwritewritable skip",
75             bootStrapper.buildBootstrapCommand().toString());
76         
77         bootStrapper.setForceFileUpdate(true);
78         assertEquals("ab -u " + user + " -p " + password + " getlatest " + path
79             + " -localpath \"" + localpath + "\" -forcefileupdate"
80             + " -overwritewritable skip",
81             bootStrapper.buildBootstrapCommand().toString());
82         
83         bootStrapper.setOverwriteWritable("replace");
84         assertEquals("ab -u " + user + " -p " + password + " getlatest " + path
85             + " -localpath \"" + localpath + "\" -forcefileupdate"
86             + " -overwritewritable replace",
87             bootStrapper.buildBootstrapCommand().toString());
88         
89     }
90
91     //The following tests all actually use the AlienBrain executable and
92
//may need to access a server. Therefore they can only be run if you
93
//have a licensed command-line client and access to a server.
94
/*
95     //In order for some of the following tests to pass, these members must
96     //be assigned values valid for your AlienBrain server.
97     private static final String TESTING_PATH = "alienbrain://Projects/Code/Over.sln";
98     private static final String TESTING_BRANCH = "Root Branch/SubBranch";
99     // Set any of the following to null if you do not want to
100     // override any NXN_AB_* environment variables you may be using.
101     private static final String TESTING_USERNAME = null; //"sjacobs";
102     private static final String TESTING_PASSWORD = null; //"pass123";
103     private static final String TESTING_SERVER = null; //"abserver";
104     private static final String TESTING_DATABASE = null; //"StudioVault";
105
106     public void testBootstrapper() throws java.io.IOException {
107         AlienBrainBootstrapper bootStrapper = new AlienBrainBootstrapper();
108
109         bootStrapper.setUser(TESTING_USERNAME);
110         bootStrapper.setPassword(TESTING_PASSWORD);
111         bootStrapper.setServer(TESTING_SERVER);
112         bootStrapper.setDatabase(TESTING_DATABASE);
113         bootStrapper.setBranch(TESTING_BRANCH);
114         bootStrapper.setPath(TESTING_PATH);
115         bootStrapper.setForceFileUpdate(true);
116
117         java.io.File tempFile = java.io.File.createTempFile("AlienBrainBootstrapperTest", null);
118         tempFile.deleteOnExit();
119         bootStrapper.setLocalPath(tempFile.getCanonicalPath());
120         bootStrapper.setOverwriteWritable("replace");
121
122         bootStrapper.bootstrap();
123
124         System.out.println(tempFile.getCanonicalPath());
125         assertTrue("Can't find " + tempFile.getCanonicalPath(), tempFile.exists());
126         assertTrue(tempFile.getCanonicalPath() + " is not a file.", tempFile.isFile());
127         assertTrue(tempFile.getCanonicalPath() + " is size 0.", tempFile.length() > 0);
128         tempFile.delete();
129     }
130
131
132 */
// End of tests that require an actual AlienBrain installation.
133
}
134
Popular Tags