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