annotate test/org/tmatesoft/hg/test/ComplexTest.java @ 636:ffce73efa2c2

HgCommitCommand: save last commit message
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 06 Jun 2013 19:39:06 +0200
parents 4ec2d44e2bf3
children 4a0bab2c6da1
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;
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 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
29 import org.tmatesoft.hg.repo.HgLookup;
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
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 // TODO HgInitCommand
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 RepoUtils.exec(repoLoc, 0, "hg", "init");
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 HgRepository hgRepo = new HgLookup().detect(repoLoc);
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 assertFalse("[sanity]", hgRepo.isInvalid());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 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
55 // add 2 files
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 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
57 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
58 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
59 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
60 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
61 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
62 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
63 // add one more file
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 // remove one initial file
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 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
66 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
67 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
68 fileB.delete();
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 // 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
70 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
71 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
72 //
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 assertEquals(2, hgRepo.getChangelog().getRevisionCount());
636
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
74 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
75 // checkout previous version
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 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
77 assertTrue(fileA.isFile());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 assertTrue(fileB.isFile());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 assertFalse(fileC.isFile());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 // branch/two heads
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 RepoUtils.modifyFileAppend(fileA, "A1");
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 RepoUtils.modifyFileAppend(fileB, "B1");
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 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
84 //
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 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
86 assertTrue(fileA.isFile());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 assertFalse(fileB.isFile());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 assertTrue(fileC.isFile());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 RepoUtils.modifyFileAppend(fileA, "A2");
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 RepoUtils.modifyFileAppend(fileC, "C1");
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 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
92 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
93 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
94 // TODO merge and HgMergeCommand
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95
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(fa).getRevisionCount());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 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
98 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
99 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
100 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
101 }
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 }