annotate test/org/tmatesoft/hg/test/ComplexTest.java @ 677:1c49c0cee540

Report line number at the first appearance, like 'hg annotate -l' does
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 18 Jul 2013 18:47:45 +0200
parents 4a0bab2c6da1
children 4ffc17c0b534
rev   line source
635
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2013 TMate Software Ltd
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.test;
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import static org.junit.Assert.*;
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.io.File;
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import org.junit.Rule;
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import org.junit.Test;
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import org.tmatesoft.hg.core.HgAddRemoveCommand;
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import org.tmatesoft.hg.core.HgCheckoutCommand;
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import org.tmatesoft.hg.core.HgCommitCommand;
637
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 636
diff changeset
28 import org.tmatesoft.hg.core.HgInitCommand;
635
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 import org.tmatesoft.hg.core.HgRevertCommand;
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import org.tmatesoft.hg.repo.HgManifest;
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 import org.tmatesoft.hg.repo.HgRepository;
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 import org.tmatesoft.hg.util.Path;
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 /**
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 * @author Artem Tikhomirov
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 * @author TMate Software Ltd.
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 */
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 public class ComplexTest {
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 @Rule
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 public ErrorCollectorExt errorCollector = new ErrorCollectorExt();
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 /**
636
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
44 * Regular work sequence with checkout, add, remove, revert and commit
635
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 */
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 @Test
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 public void testLocalScenario1() throws Exception {
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 File repoLoc = RepoUtils.createEmptyDir("composite-scenario-1");
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 // init empty
637
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 636
diff changeset
50 HgRepository hgRepo = new HgInitCommand().location(repoLoc).revlogV1().execute();
635
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 assertFalse("[sanity]", hgRepo.isInvalid());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 assertEquals("[sanity]", 0, hgRepo.getChangelog().getRevisionCount());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 // add 2 files
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 Path fa = Path.create("a"), fb = Path.create("b");
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 final File fileA = new File(repoLoc, fa.toString());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 final File fileB = new File(repoLoc, fb.toString());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 RepoUtils.createFile(fileA, "first file");
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 RepoUtils.createFile(fileB, "second file");
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 new HgAddRemoveCommand(hgRepo).add(fa, fb).execute();
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 new HgCommitCommand(hgRepo).message("FIRST").execute();
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 // add one more file
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 // remove one initial file
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 Path fc = Path.create("c");
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 final File fileC = new File(repoLoc, fc.toString());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 RepoUtils.createFile(fileC, "third file");
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 fileB.delete();
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 // TODO HgAddRemoveCommand needs #copy(from, to) method
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 new HgAddRemoveCommand(hgRepo).add(fc).remove(fb).execute();
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 new HgCommitCommand(hgRepo).message("SECOND").execute();
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 //
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 assertEquals(2, hgRepo.getChangelog().getRevisionCount());
636
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
72 errorCollector.assertEquals("SECOND", hgRepo.getCommitLastMessage());
635
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 // checkout previous version
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 new HgCheckoutCommand(hgRepo).changeset(0).clean(true).execute();
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 assertTrue(fileA.isFile());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 assertTrue(fileB.isFile());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 assertFalse(fileC.isFile());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 // branch/two heads
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 RepoUtils.modifyFileAppend(fileA, "A1");
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 RepoUtils.modifyFileAppend(fileB, "B1");
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 new HgCommitCommand(hgRepo).message("THIRD").execute();
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 //
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 new HgCheckoutCommand(hgRepo).changeset(1).clean(true).execute();
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 assertTrue(fileA.isFile());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 assertFalse(fileB.isFile());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 assertTrue(fileC.isFile());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 RepoUtils.modifyFileAppend(fileA, "A2");
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 RepoUtils.modifyFileAppend(fileC, "C1");
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 new HgRevertCommand(hgRepo).changeset(1).file(fa).execute();
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 errorCollector.assertTrue(new File(fileA.getParent(), fileA.getName() + ".orig").isFile());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 new HgCommitCommand(hgRepo).message("FOURTH").execute();
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 // TODO merge and HgMergeCommand
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 errorCollector.assertEquals(2, hgRepo.getFileNode(fa).getRevisionCount());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 errorCollector.assertEquals(2, hgRepo.getFileNode(fb).getRevisionCount());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 errorCollector.assertEquals(2, hgRepo.getFileNode(fc).getRevisionCount());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 final HgManifest mf = hgRepo.getManifest();
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 errorCollector.assertEquals(mf.getFileRevision(0, fa), mf.getFileRevision(3, fa)); // "A2" was reverted
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 }
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 }