1 37 46 package net.sourceforge.cruisecontrol.sourcecontrols; 47 48 import java.io.BufferedReader ; 49 import java.io.IOException ; 50 import java.io.InputStream ; 51 import java.io.InputStreamReader ; 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 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 { 82 mockRunner = null; 83 } 84 85 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 } 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 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 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 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 190 public boolean parseStream(InputStream iStream) throws CruiseControlException { 191 BufferedReader reader = new BufferedReader (new InputStreamReader (iStream)); 192 String 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 e) { 201 throw new CruiseControlException("Error reading Accurev output"); 202 } 203 return accurevSupportFound; 204 } 205 208 public void testCommandLineSynctime() { 209 fake("accurev_synctime.txt", 0); 210 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 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 path, int returnCode) { 237 mockRunner.addScript(path, returnCode); 238 } 239 240 } 241 | Popular Tags |