comparison mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java @ 444:a05eca69fc01

Ensure plugin works without revnums in revisions
author Dmitry Neverov <dmitry.neverov@gmail.com>
date Wed, 20 Jun 2012 22:54:13 +0400
parents d0f80762461a
children b47cfe5cbaba
comparison
equal deleted inserted replaced
443:d0f80762461a 444:a05eca69fc01
31 import java.io.FilenameFilter; 31 import java.io.FilenameFilter;
32 import java.io.IOException; 32 import java.io.IOException;
33 import java.util.*; 33 import java.util.*;
34 34
35 import static com.intellij.openapi.util.io.FileUtil.*; 35 import static com.intellij.openapi.util.io.FileUtil.*;
36 import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.buildPatch;
36 import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository; 37 import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository;
37 import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot; 38 import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot;
38 39
39 @Test 40 @Test
40 public class MercurialVcsSupportTest extends BaseMercurialTestCase { 41 public class MercurialVcsSupportTest extends BaseMercurialTestCase {
118 assertEquals(1, files3.size()); 119 assertEquals(1, files3.size());
119 assertEquals(files3.get(0).getType(), VcsChangeInfo.Type.REMOVED); 120 assertEquals(files3.get(0).getType(), VcsChangeInfo.Type.REMOVED);
120 assertEquals(normalizePath(files3.get(0).getRelativeFileName()), "dir1/file4.txt"); 121 assertEquals(normalizePath(files3.get(0).getRelativeFileName()), "dir1/file4.txt");
121 } 122 }
122 123
123 private ByteArrayOutputStream buildPatch(VcsRoot vcsRoot, String from, String to, CheckoutRules rules) throws IOException, VcsException {
124 final ByteArrayOutputStream output = new ByteArrayOutputStream();
125 final PatchBuilderImpl builder = new PatchBuilderImpl(output);
126 myVcs.buildPatch(vcsRoot, from, to, builder, rules);
127 builder.close();
128 return output;
129 }
130
131 @Test 124 @Test
132 public void test_build_patch() throws IOException, VcsException { 125 public void test_build_patch() throws IOException, VcsException {
133 setName("cleanPatch1"); 126 setName("cleanPatch1");
134 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); 127 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo());
135 128
136 ByteArrayOutputStream output = buildPatch(vcsRoot, null, "4:b06a290a363b", new CheckoutRules("")); 129 ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, null, "4:b06a290a363b", new CheckoutRules(""));
137 checkPatchResult(output.toByteArray()); 130 checkPatchResult(output.toByteArray());
138 131
139 File clonedReposParentDir = myPluginConfig.getCachesDir(); 132 File clonedReposParentDir = myPluginConfig.getCachesDir();
140 assertTrue(clonedReposParentDir.isDirectory()); 133 assertTrue(clonedReposParentDir.isDirectory());
141 assertTrue(1 == clonedReposParentDir.list(new FilenameFilter() { 134 assertTrue(1 == clonedReposParentDir.list(new FilenameFilter() {
147 140
148 public void test_build_incremental_patch() throws IOException, VcsException { 141 public void test_build_incremental_patch() throws IOException, VcsException {
149 setName("patch1"); 142 setName("patch1");
150 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); 143 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo());
151 144
152 ByteArrayOutputStream output = buildPatch(vcsRoot, "3:9522278aa38d", "4:b06a290a363b", new CheckoutRules("")); 145 ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, "3:9522278aa38d", "4:b06a290a363b", new CheckoutRules(""));
153 146
154 checkPatchResult(output.toByteArray()); 147 checkPatchResult(output.toByteArray());
155 } 148 }
156 149
157 public void test_build_incremental_patch_checkout_rules() throws IOException, VcsException { 150 public void test_build_incremental_patch_checkout_rules() throws IOException, VcsException {
158 setName("patch1_checkout_rules"); 151 setName("patch1_checkout_rules");
159 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); 152 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo());
160 153
161 ByteArrayOutputStream output = buildPatch(vcsRoot, "3:9522278aa38d", "4:b06a290a363b", new CheckoutRules("+:dir1=>path")); 154 ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, "3:9522278aa38d", "4:b06a290a363b", new CheckoutRules("+:dir1=>path"));
162 155
163 checkPatchResult(output.toByteArray()); 156 checkPatchResult(output.toByteArray());
164 } 157 }
165 158
166 public void test_build_clean_patch_checkout_rules() throws IOException, VcsException { 159 public void test_build_clean_patch_checkout_rules() throws IOException, VcsException {
167 setName("cleanPatch1_checkout_rules"); 160 setName("cleanPatch1_checkout_rules");
168 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); 161 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo());
169 162
170 ByteArrayOutputStream output = buildPatch(vcsRoot, null, "4:b06a290a363b", new CheckoutRules("+:dir1/subdir=>.")); 163 ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, null, "4:b06a290a363b", new CheckoutRules("+:dir1/subdir=>."));
171 164
172 checkPatchResult(output.toByteArray()); 165 checkPatchResult(output.toByteArray());
173 } 166 }
174 167
175 public void test_build_incremental_patch_file_with_space() throws IOException, VcsException { 168 public void test_build_incremental_patch_file_with_space() throws IOException, VcsException {
176 setName("patch2"); 169 setName("patch2");
177 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); 170 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo());
178 171
179 ByteArrayOutputStream output = buildPatch(vcsRoot, "3:9522278aa38d", "6:b9deb9a1c6f4", new CheckoutRules("")); 172 ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, "3:9522278aa38d", "6:b9deb9a1c6f4", new CheckoutRules(""));
180 173
181 checkPatchResult(output.toByteArray()); 174 checkPatchResult(output.toByteArray());
182 } 175 }
183 176
184 public void test_clean_patch_with_subrepositories() throws Exception { 177 public void test_clean_patch_with_subrepositories() throws Exception {
190 moveDirWithContent(new File(r3, "hg"), new File(r3, ".hg")); 183 moveDirWithContent(new File(r3, "hg"), new File(r3, ".hg"));
191 184
192 VcsRootImpl root = vcsRoot().withUrl(r1.getAbsolutePath()).build(); 185 VcsRootImpl root = vcsRoot().withUrl(r1.getAbsolutePath()).build();
193 186
194 setName("clean_patch_with_subrepositories"); 187 setName("clean_patch_with_subrepositories");
195 checkPatchResult(buildPatch(root, null, "3:d350e7209906", CheckoutRules.DEFAULT).toByteArray()); 188 checkPatchResult(buildPatch(myVcs, root, null, "3:d350e7209906", CheckoutRules.DEFAULT).toByteArray());
196 } 189 }
197 190
198 public void test_get_content() throws IOException, VcsException { 191 public void test_get_content() throws IOException, VcsException {
199 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); 192 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo());
200 193
336 329
337 public void test_full_patch_from_branch() throws IOException, VcsException { 330 public void test_full_patch_from_branch() throws IOException, VcsException {
338 setName("patch3"); 331 setName("patch3");
339 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo(), "test_branch"); 332 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo(), "test_branch");
340 333
341 ByteArrayOutputStream output = buildPatch(vcsRoot, null, "7:376dcf05cd2a", new CheckoutRules("")); 334 ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, null, "7:376dcf05cd2a", new CheckoutRules(""));
342 335
343 checkPatchResult(output.toByteArray()); 336 checkPatchResult(output.toByteArray());
344 } 337 }
345 338
346 public void test_full_patch_from_branch_with_checkout_rules() throws IOException, VcsException { 339 public void test_full_patch_from_branch_with_checkout_rules() throws IOException, VcsException {
347 setName("patch3_checkout_rules1"); 340 setName("patch3_checkout_rules1");
348 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo(), "test_branch"); 341 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo(), "test_branch");
349 342
350 ByteArrayOutputStream output = buildPatch(vcsRoot, null, "7:376dcf05cd2a", new CheckoutRules("+:.=>path")); 343 ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, null, "7:376dcf05cd2a", new CheckoutRules("+:.=>path"));
351 344
352 checkPatchResult(output.toByteArray()); 345 checkPatchResult(output.toByteArray());
353 } 346 }
354 347
355 public void test_full_patch_from_branch_with_checkout_rules_mapped_and_skipped() throws IOException, VcsException { 348 public void test_full_patch_from_branch_with_checkout_rules_mapped_and_skipped() throws IOException, VcsException {
356 setName("patch3_checkout_rules2"); 349 setName("patch3_checkout_rules2");
357 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo(), "test_branch"); 350 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo(), "test_branch");
358 351
359 ByteArrayOutputStream output = buildPatch(vcsRoot, null, "7:376dcf05cd2a", new CheckoutRules("+:dir1=>path/dir1\n+:dir with space")); 352 ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, null, "7:376dcf05cd2a", new CheckoutRules("+:dir1=>path/dir1\n+:dir with space"));
360 353
361 checkPatchResult(output.toByteArray()); 354 checkPatchResult(output.toByteArray());
362 } 355 }
363 356
364 public void test_incremental_patch_from_branch() throws IOException, VcsException { 357 public void test_incremental_patch_from_branch() throws IOException, VcsException {
365 setName("patch4"); 358 setName("patch4");
366 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo(), "test_branch"); 359 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo(), "test_branch");
367 360
368 ByteArrayOutputStream output = buildPatch(vcsRoot, "7:376dcf05cd2a", "8:04c3ae4c6312", new CheckoutRules("")); 361 ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, "7:376dcf05cd2a", "8:04c3ae4c6312", new CheckoutRules(""));
369 362
370 checkPatchResult(output.toByteArray()); 363 checkPatchResult(output.toByteArray());
371 } 364 }
372 365
373 @Test(enabled = false) 366 @Test(enabled = false)
391 setName("cleanPatch1"); 384 setName("cleanPatch1");
392 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); 385 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo());
393 File cloneDir = myTempFiles.createTempDir(); 386 File cloneDir = myTempFiles.createTempDir();
394 vcsRoot.addProperty(Constants.SERVER_CLONE_PATH_PROP, cloneDir.getAbsolutePath()); 387 vcsRoot.addProperty(Constants.SERVER_CLONE_PATH_PROP, cloneDir.getAbsolutePath());
395 388
396 ByteArrayOutputStream output = buildPatch(vcsRoot, null, "4:b06a290a363b", new CheckoutRules("")); 389 ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, null, "4:b06a290a363b", new CheckoutRules(""));
397 390
398 checkPatchResult(output.toByteArray()); 391 checkPatchResult(output.toByteArray());
399 392
400 assertTrue(new File(cloneDir, new File(vcsRoot.getProperty(Constants.REPOSITORY_PROP)).getName()).isDirectory()); 393 assertTrue(new File(cloneDir, new File(vcsRoot.getProperty(Constants.REPOSITORY_PROP)).getName()).isDirectory());
401 } 394 }
402 395
403 public void build_patch_from_newer_revision_to_earlier() throws Exception { 396 public void build_patch_from_newer_revision_to_earlier() throws Exception {
404 setName("patch5"); 397 setName("patch5");
405 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); 398 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo());
406 ByteArrayOutputStream output = buildPatch(vcsRoot, "6:b9deb9a1c6f4", "3:9522278aa38d", CheckoutRules.DEFAULT); 399 ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, "6:b9deb9a1c6f4", "3:9522278aa38d", CheckoutRules.DEFAULT);
407 checkPatchResult(output.toByteArray()); 400 checkPatchResult(output.toByteArray());
408 } 401 }
409 402
410 public void build_patch_from_unknown_revision() throws Exception { 403 public void build_patch_from_unknown_revision() throws Exception {
411 setName("patch6"); 404 setName("patch6");
412 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); 405 VcsRootImpl vcsRoot = createVcsRoot(simpleRepo());
413 ByteArrayOutputStream output = buildPatch(vcsRoot, "6:hahahahahaha", "3:9522278aa38d", new CheckoutRules("+:.=>path")); 406 ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, "6:hahahahahaha", "3:9522278aa38d", new CheckoutRules("+:.=>path"));
414 checkPatchResult(output.toByteArray()); 407 checkPatchResult(output.toByteArray());
415 } 408 }
416 409
417 private String mergeCommittsRepo() { 410 private String mergeCommittsRepo() {
418 return new File("mercurial-tests/testData/rep2").getAbsolutePath(); 411 return new File("mercurial-tests/testData/rep2").getAbsolutePath();