| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
package nl.toolforge.karma.core.test; |
| 20 |
|
|
| 21 |
|
import nl.toolforge.core.util.file.MyFileUtils; |
| 22 |
|
import nl.toolforge.karma.core.Version; |
| 23 |
|
import nl.toolforge.karma.core.cmd.CommandResponse; |
| 24 |
|
import nl.toolforge.karma.core.module.Module; |
| 25 |
|
import nl.toolforge.karma.core.module.SourceModule; |
| 26 |
|
import nl.toolforge.karma.core.vc.AuthenticationException; |
| 27 |
|
import nl.toolforge.karma.core.vc.Runner; |
| 28 |
|
import nl.toolforge.karma.core.vc.cvsimpl.CVSException; |
| 29 |
|
import nl.toolforge.karma.core.vc.cvsimpl.CVSRepository; |
| 30 |
|
import nl.toolforge.karma.core.vc.cvsimpl.CVSRunner; |
| 31 |
|
import org.apache.commons.io.FileUtils; |
| 32 |
|
import org.apache.commons.logging.Log; |
| 33 |
|
import org.apache.commons.logging.LogFactory; |
| 34 |
|
import org.apache.tools.ant.Project; |
| 35 |
|
import org.apache.tools.ant.taskdefs.Copy; |
| 36 |
|
import org.apache.tools.ant.types.FileSet; |
| 37 |
|
|
| 38 |
|
import java.io.File; |
| 39 |
|
import java.io.IOException; |
| 40 |
|
import java.io.InputStream; |
| 41 |
|
import java.util.Properties; |
| 42 |
|
import java.util.Random; |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
390 |
public class LocalCVSInitializer extends BaseTest { |
| 61 |
|
|
| 62 |
208 |
private static Log logger = LogFactory.getLog(LocalCVSInitializer.class); |
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
protected static final String DEFAULT_MODULE_1 = "CORE-test-module-1"; |
| 68 |
|
|
| 69 |
104 |
private static CVSRepository location = null; |
| 70 |
390 |
private File localCVSRepository = null; |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
104 |
protected static Random randomizer = new Random(); |
| 76 |
|
|
| 77 |
|
public void setUp() throws InitializationException { |
| 78 |
|
|
| 79 |
390 |
super.setUp(); |
| 80 |
|
|
| 81 |
390 |
String localPath = null; |
| 82 |
|
|
| 83 |
|
try { |
| 84 |
390 |
Properties props = new Properties(); |
| 85 |
390 |
InputStream stream = getClass().getClassLoader().getResourceAsStream("test/test-cvs.properties"); |
| 86 |
390 |
if (stream == null) { |
| 87 |
|
|
| 88 |
|
|
| 89 |
0 |
logger.error("could not find properties file: test-cvs.properties"); |
| 90 |
|
} |
| 91 |
390 |
props.load(stream); |
| 92 |
390 |
localPath = props.getProperty("cvs.local.path"); |
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
390 |
Copy copy = new Copy(); |
| 98 |
390 |
copy.setProject(new Project()); |
| 99 |
|
|
| 100 |
390 |
FileSet set = new FileSet(); |
| 101 |
390 |
set.setDir(new File(localPath)); |
| 102 |
390 |
set.setIncludes("**/*"); |
| 103 |
|
|
| 104 |
390 |
copy.addFileset(set); |
| 105 |
|
|
| 106 |
390 |
localCVSRepository = MyFileUtils.createTempDirectory(); |
| 107 |
|
|
| 108 |
390 |
copy.setTodir(localCVSRepository); |
| 109 |
390 |
copy.execute(); |
| 110 |
|
|
| 111 |
390 |
logger.debug("cvs.local.path = " + localPath); |
| 112 |
|
|
| 113 |
390 |
location = new CVSRepository("test-id-1"); |
| 114 |
390 |
location.setProtocol(CVSRepository.LOCAL); |
| 115 |
390 |
location.setRepository(localCVSRepository.getPath()); |
| 116 |
|
|
| 117 |
390 |
location.setWorkingContext(getWorkingContext()); |
| 118 |
|
|
| 119 |
0 |
} catch (Exception e) { |
| 120 |
0 |
throw new InitializationException("Local CVS repository could not be initialized. Trying to initialize repository at : ".concat(localPath)); |
| 121 |
390 |
} |
| 122 |
|
|
| 123 |
390 |
} |
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
|
| 128 |
|
public void tearDown() { |
| 129 |
|
|
| 130 |
390 |
super.tearDown(); |
| 131 |
|
|
| 132 |
|
try { |
| 133 |
390 |
FileUtils.deleteDirectory(localCVSRepository); |
| 134 |
0 |
} catch (IOException e) { |
| 135 |
0 |
fail(e.getMessage()); |
| 136 |
390 |
} |
| 137 |
390 |
} |
| 138 |
|
|
| 139 |
|
|
| 140 |
|
|
| 141 |
|
|
| 142 |
|
protected CVSRepository getTestLocation() { |
| 143 |
806 |
return location; |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
|
| 150 |
|
protected String getTestFileName() throws InitializationException { |
| 151 |
|
|
| 152 |
52 |
int someInt = randomizer.nextInt(); |
| 153 |
52 |
someInt = (someInt < 0 ? someInt * -1 : someInt); |
| 154 |
|
|
| 155 |
52 |
return "test_" + someInt + ".nobody.txt"; |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
| 160 |
|
|
| 161 |
|
public final Module checkoutDefaultModule1() { |
| 162 |
|
|
| 163 |
|
try { |
| 164 |
182 |
Runner runner = getTestRunner(); |
| 165 |
|
|
| 166 |
182 |
Module module = new SourceModule(DEFAULT_MODULE_1, location); |
| 167 |
182 |
module.setBaseDir(new File(getWorkingContext().getProjectBaseDirectory(), module.getName())); |
| 168 |
70 |
|
| 169 |
|
|
| 170 |
182 |
runner.checkout(module); |
| 171 |
|
|
| 172 |
182 |
return module; |
| 173 |
|
|
| 174 |
0 |
} catch (Exception e) { |
| 175 |
0 |
fail(e.getMessage()); |
| 176 |
|
} |
| 177 |
0 |
return null; |
| 178 |
|
} |
| 179 |
|
|
| 180 |
|
public final Module checkoutDefaultModuleWithVersion() { |
| 181 |
|
|
| 182 |
|
try { |
| 183 |
78 |
Runner runner = getTestRunner(); |
| 184 |
|
|
| 185 |
78 |
Module module = new SourceModule(DEFAULT_MODULE_1, location, class="keyword">new Version("0-0")); |
| 186 |
78 |
module.setBaseDir(new File(getWorkingContext().getProjectBaseDirectory(), module.getName())); |
| 187 |
30 |
|
| 188 |
|
|
| 189 |
78 |
runner.checkout(module); |
| 190 |
|
|
| 191 |
78 |
return module; |
| 192 |
|
|
| 193 |
0 |
} catch (Exception e) { |
| 194 |
0 |
fail(e.getMessage()); |
| 195 |
|
} |
| 196 |
0 |
return null; |
| 197 |
|
} |
| 198 |
|
|
| 199 |
|
|
| 200 |
|
|
| 201 |
|
|
| 202 |
|
|
| 203 |
|
|
| 204 |
|
|
| 205 |
|
protected final Runner getTestRunner() throws CVSException, AuthenticationException { |
| 206 |
390 |
return getTestRunner(new CommandResponseFaker(null)); |
| 207 |
|
} |
| 208 |
|
|
| 209 |
|
|
| 210 |
|
|
| 211 |
|
|
| 212 |
|
|
| 213 |
|
|
| 214 |
|
|
| 215 |
|
|
| 216 |
|
protected final Runner getTestRunner(CommandResponse response) throws CVSException, AuthenticationException { |
| 217 |
|
|
| 218 |
442 |
CVSRunner runner = new CVSRunner(getTestLocation()); |
| 219 |
|
|
| 220 |
442 |
if (response != null) { |
| 221 |
442 |
runner.setCommandResponse(response); |
| 222 |
|
} |
| 223 |
|
|
| 224 |
442 |
return runner; |
| 225 |
|
} |
| 226 |
|
|
| 227 |
|
|
| 228 |
|
|
| 229 |
|
|
| 230 |
|
public void testNothing() { |
| 231 |
104 |
assertTrue(true); |
| 232 |
104 |
} |
| 233 |
|
} |