KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > sourcecontrols > AccurevTest


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2001, ThoughtWorks, Inc.
4  * 651 W Washington Ave. Suite 600
5  * Chicago, IL 60661 USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * + Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * + Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21  * names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior
23  * written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  ********************************************************************************/

37 /*
38  * Created on 30-Jun-2005 by norru
39  *
40  * Copyright (C) Sony Computer Entertainment Europe
41  * Studio Liverpool Server Group
42  *
43  * Authors:
44  * Nicola Orru' <Nicola_Orru@scee.net>
45  */

46 package net.sourceforge.cruisecontrol.sourcecontrols;
47
48 import java.io.BufferedReader JavaDoc;
49 import java.io.IOException JavaDoc;
50 import java.io.InputStream JavaDoc;
51 import java.io.InputStreamReader JavaDoc;
52
53 import junit.framework.TestCase;
54 import net.sourceforge.cruisecontrol.CruiseControlException;
55 import net.sourceforge.cruisecontrol.sourcecontrols.accurev.AccurevCommand;
56 import net.sourceforge.cruisecontrol.sourcecontrols.accurev.AccurevCommandline;
57 import net.sourceforge.cruisecontrol.sourcecontrols.accurev.AccurevInputParser;
58 import net.sourceforge.cruisecontrol.sourcecontrols.accurev.DateTimespec;
59 import net.sourceforge.cruisecontrol.sourcecontrols.accurev.Timespec;
60 import net.sourceforge.cruisecontrol.sourcecontrols.accurev.TransactionNumberTimespec;
61 import net.sourceforge.cruisecontrol.util.Commandline;
62
63 /**
64  * Basic test cases for the accurev command line utilities
65  *
66  * AccurevBootstrapper has its own test in
67  * net.sourceforge.cruisecontrol.bootstrappers.AccurevBootstrapperTest
68  *
69  * Accurev sourcecontrol has its own test in
70  * net.sourceforge.cruisecontrol.sourcecontrols.AccurevSourcecontrolTest
71  *
72  * @author <a HREF="mailto:Nicola_Orru@scee.net">Nicola Orru'</a>
73  */

74 public class AccurevTest extends TestCase implements AccurevInputParser {
75   private AccurevMockRunner mockRunner;
76   public void setUp() {
77     mockRunner = new AccurevMockRunner();
78     mockRunner.setScriptRoot("net/sourceforge/cruisecontrol/sourcecontrols");
79   }
80
81   protected void tearDown() throws Exception JavaDoc {
82     mockRunner = null;
83   }
84
85   /**
86    * Tests common "accurev hist" commandline configurations
87    */

88   public void testCommandLineHist() {
89     AccurevCommandline hist;
90     fake("accurev_hist_now.txt", 0);
91     fake("accurev_hist_now_highest.txt", 0);
92     fake("accurev_blank.txt", 1);
93     fake("accurev_blank.txt", 1);
94     fake("accurev_hist_highest.txt", 0);
95     fake("accurev_hist_1-now.txt", 0);
96     fake("accurev_syntax_error.txt", 0);
97     hist = AccurevCommand.HIST.create(getMockRunner());
98     hist.setTransactionRange(DateTimespec.NOW);
99     hist.run();
100     assertTrue(hist.isSuccess());
101     hist = AccurevCommand.HIST.create(getMockRunner());
102     hist.setTransactionRange(DateTimespec.NOW, TransactionNumberTimespec.HIGHEST);
103     hist.run();
104     assertTrue(hist.isSuccess());
105     hist = AccurevCommand.HIST.create(getMockRunner());
106     hist.setTransactionRange(new TransactionNumberTimespec(0), DateTimespec.NOW);
107     hist.run();
108     assertFalse(hist.isSuccess());
109     hist = AccurevCommand.HIST.create(getMockRunner());
110     hist.setTransactionRange(new TransactionNumberTimespec(0));
111     hist.run();
112     assertFalse(hist.isSuccess());
113     hist = AccurevCommand.HIST.create(getMockRunner());
114     hist.setTransactionRange(TransactionNumberTimespec.HIGHEST);
115     hist.run();
116     assertTrue(hist.isSuccess());
117     hist = AccurevCommand.HIST.create(getMockRunner());
118     hist.setTransactionRange(new TransactionNumberTimespec(1), DateTimespec.NOW);
119     hist.run();
120     assertTrue(hist.isSuccess());
121     try {
122       AccurevCommand.HIST.create().setWorkspaceLocalPath("ThisDirectoryIsNotSupposedToExist");
123       fail("setWorkspace should throw an exception when the workspace is not valid");
124     } catch (CruiseControlException e) {
125       // An exception must be thrown.
126
}
127     hist = AccurevCommand.HIST.create(getMockRunner());
128     assertFalse(hist.isSuccess());
129     AccurevCommand.HIST.create(getMockRunner());
130     hist.addArgument("--thisoptiondoesnotexist");
131     hist.run();
132     assertFalse(hist.isSuccess());
133   }
134   /**
135    * Checks the command line is built as expected
136    */

137   public void testCommandLineBuild() {
138     Timespec d1 = new DateTimespec(-24);
139     Timespec d2 = new DateTimespec(0);
140     AccurevCommandline cmdKeep = AccurevCommand.KEEP.create();
141     cmdKeep.selectModified();
142     cmdKeep.setTransactionRange(d1, d2);
143     cmdKeep.setComment("Automatic keep");
144     assertEquals("accurev keep -m -t \"" + d1.toString() + "-" + d2.toString() + "\" -c \"Automatic keep\"",
145         cmdKeep.toString());
146     AccurevCommandline cmdHist = AccurevCommand.HIST.create();
147     cmdHist.setTransactionRange(d1, d2);
148     assertEquals("accurev hist -t \"" + d1.toString() + "-" + d2.toString() + "\"", cmdHist.toString());
149     Commandline cmdUpdate = AccurevCommand.UPDATE.create();
150     assertEquals("accurev update", cmdUpdate.toString());
151     Commandline cmdSynctime = AccurevCommand.SYNCTIME.create();
152     assertEquals("accurev synctime", cmdSynctime.toString());
153   }
154   /**
155    * Tests common "accurev keep" commandline configuration
156    */

157   public void testCommandLineKeep() {
158     fake("accurev_keep_nofiles.txt", 0);
159     fake("accurev_keep.txt", 0);
160     AccurevCommandline keep;
161     keep = AccurevCommand.KEEP.create(getMockRunner());
162     assertFalse(keep.isSuccess());
163     keep = AccurevCommand.KEEP.create(getMockRunner());
164     keep.selectModified();
165     keep.setComment("Automatic keep");
166     keep.setVerbose(true);
167     keep.run();
168     assertTrue(keep.isSuccess());
169     keep = AccurevCommand.KEEP.create(getMockRunner());
170     keep.selectModified();
171     keep.setComment("Automatic keep");
172     keep.setVerbose(true);
173     keep.run();
174     assertTrue(keep.isSuccess());
175   }
176   /**
177    * Runs "accurev help" and looks for the support@accurev.com string. parseStream is defined as the
178    * parsing callback
179    */

180   public void testCommandLineParse() {
181     fake("accurev_help.txt", 0);
182     AccurevCommandline help = AccurevCommand.HELP.create(getMockRunner());
183     help.setInputParser(this);
184     help.run();
185     assertTrue(help.isSuccess());
186   }
187   /**
188    * Helper for testCommandLineParse
189    */

190   public boolean parseStream(InputStream JavaDoc iStream) throws CruiseControlException {
191     BufferedReader JavaDoc reader = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(iStream));
192     String JavaDoc line;
193     boolean accurevSupportFound = false;
194     try {
195       while ((line = reader.readLine()) != null) {
196         if (line.indexOf("support@accurev.com") >= 0) {
197           accurevSupportFound = true;
198         }
199       }
200     } catch (IOException JavaDoc e) {
201       throw new CruiseControlException("Error reading Accurev output");
202     }
203     return accurevSupportFound;
204   }
205   /**
206    * Runs "accurev synctime"
207    */

208   public void testCommandLineSynctime() {
209     fake("accurev_synctime.txt", 0);
210     // you only have success after run
211
AccurevCommandline synctime;
212     synctime = AccurevCommand.SYNCTIME.create(getMockRunner());
213     assertFalse(synctime.isSuccess());
214     synctime = AccurevCommand.SYNCTIME.create(getMockRunner());
215     synctime.run();
216     assertTrue(synctime.isSuccess());
217   }
218   /**
219    * Runs "accurev update" in the default workspace
220    */

221   public void testCommandLineUpdate() {
222     fake("accurev_update.txt", 0);
223     AccurevCommandline update;
224     update = AccurevCommand.UPDATE.create(getMockRunner());
225     assertFalse(update.isSuccess());
226     update = AccurevCommand.UPDATE.create(getMockRunner());
227     update.run();
228     assertTrue(update.isSuccess());
229   }
230   protected AccurevMockRunner getMockRunner() {
231     return mockRunner;
232   }
233   protected void setMockRunner(AccurevMockRunner mockRunner) {
234     this.mockRunner = mockRunner;
235   }
236   public void fake(String JavaDoc path, int returnCode) {
237     mockRunner.addScript(path, returnCode);
238   }
239
240 }
241
Popular Tags