Mercurial > hg4j
comparison hg4j/src/test/java/org/tmatesoft/hg/test/TestIncoming.java @ 213:6ec4af642ba8 gradle
Project uses Gradle for build - actual changes
author | Alexander Kitaev <kitaev@gmail.com> |
---|---|
date | Tue, 10 May 2011 10:52:53 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
212:edb2e2829352 | 213:6ec4af642ba8 |
---|---|
1 /* | |
2 * Copyright (c) 2011 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.hamcrest.CoreMatchers.equalTo; | |
20 import static org.tmatesoft.hg.internal.RequiresFile.*; | |
21 | |
22 import java.io.File; | |
23 import java.io.IOException; | |
24 import java.util.ArrayList; | |
25 import java.util.HashSet; | |
26 import java.util.List; | |
27 | |
28 import org.junit.Assert; | |
29 import org.junit.Rule; | |
30 import org.junit.Test; | |
31 import org.tmatesoft.hg.core.HgChangeset; | |
32 import org.tmatesoft.hg.core.HgIncomingCommand; | |
33 import org.tmatesoft.hg.core.HgLogCommand; | |
34 import org.tmatesoft.hg.core.Nodeid; | |
35 import org.tmatesoft.hg.internal.Internals; | |
36 import org.tmatesoft.hg.repo.HgLookup; | |
37 import org.tmatesoft.hg.repo.HgRemoteRepository; | |
38 import org.tmatesoft.hg.repo.HgRepository; | |
39 | |
40 /** | |
41 * | |
42 * @author Artem Tikhomirov | |
43 * @author TMate Software Ltd. | |
44 */ | |
45 public class TestIncoming { | |
46 | |
47 @Rule | |
48 public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); | |
49 | |
50 public static void main(String[] args) throws Throwable { | |
51 Configuration.get().remoteServers("http://localhost:8000/"); | |
52 TestIncoming t = new TestIncoming(); | |
53 t.testSimple(); | |
54 t.errorCollector.verify(); | |
55 } | |
56 | |
57 public TestIncoming() { | |
58 // Configuration.get().remoteServers("http://localhost:8000/"); | |
59 } | |
60 | |
61 @Test | |
62 public void testSimple() throws Exception { | |
63 int x = 0; | |
64 HgLookup lookup = new HgLookup(); | |
65 for (HgRemoteRepository hgRemote : Configuration.get().allRemote()) { | |
66 File dest = initEmptyTempRepo("test-incoming-" + x++); | |
67 HgRepository localRepo = lookup.detect(dest); | |
68 // Idea: | |
69 // hg in, hg4j in, compare | |
70 // hg pull total/2 | |
71 // hg in, hg4j in, compare | |
72 List<Nodeid> incoming = runAndCompareIncoming(localRepo, hgRemote); | |
73 Assert.assertTrue("Need remote repository of reasonable size to test incoming command for partially filled case", incoming.size() >= 5); | |
74 // | |
75 Nodeid median = incoming.get(incoming.size() / 2); | |
76 System.out.println("About to pull up to revision " + median.shortNotation()); | |
77 new ExecHelper(new OutputParser.Stub(), dest).run("hg", "pull", "-r", median.toString(), hgRemote.getLocation()); | |
78 // | |
79 // shall re-read repository to pull up new changes | |
80 localRepo = lookup.detect(dest); | |
81 runAndCompareIncoming(localRepo, hgRemote); | |
82 } | |
83 } | |
84 | |
85 private List<Nodeid> runAndCompareIncoming(HgRepository localRepo, HgRemoteRepository hgRemote) throws Exception { | |
86 // need new command instance as subsequence exec[Lite|Full] on the same command would yield same result, | |
87 // regardless of the pull in between. | |
88 HgIncomingCommand cmd = new HgIncomingCommand(localRepo); | |
89 cmd.against(hgRemote); | |
90 HgLogCommand.CollectHandler collector = new HgLogCommand.CollectHandler(); | |
91 LogOutputParser outParser = new LogOutputParser(true); | |
92 ExecHelper eh = new ExecHelper(outParser, new File(localRepo.getLocation())); | |
93 cmd.executeFull(collector); | |
94 eh.run("hg", "incoming", "--debug", hgRemote.getLocation()); | |
95 List<Nodeid> liteResult = cmd.executeLite(null); | |
96 report(collector, outParser, liteResult, errorCollector); | |
97 return liteResult; | |
98 } | |
99 | |
100 static void report(HgLogCommand.CollectHandler collector, LogOutputParser outParser, List<Nodeid> liteResult, ErrorCollectorExt errorCollector) { | |
101 TestHistory.report("hg vs execFull", collector.getChanges(), outParser.getResult(), false, errorCollector); | |
102 // | |
103 ArrayList<Nodeid> expected = new ArrayList<Nodeid>(outParser.getResult().size()); | |
104 for (LogOutputParser.Record r : outParser.getResult()) { | |
105 Nodeid nid = Nodeid.fromAscii(r.changesetNodeid); | |
106 expected.add(nid); | |
107 } | |
108 checkNodeids("hg vs execLite:", liteResult, expected, errorCollector); | |
109 // | |
110 expected = new ArrayList<Nodeid>(outParser.getResult().size()); | |
111 for (HgChangeset cs : collector.getChanges()) { | |
112 expected.add(cs.getNodeid()); | |
113 } | |
114 checkNodeids("execFull vs execLite:", liteResult, expected, errorCollector); | |
115 } | |
116 | |
117 static void checkNodeids(String what, List<Nodeid> liteResult, List<Nodeid> expected, ErrorCollectorExt errorCollector) { | |
118 HashSet<Nodeid> set = new HashSet<Nodeid>(liteResult); | |
119 for (Nodeid nid : expected) { | |
120 boolean removed = set.remove(nid); | |
121 errorCollector.checkThat(what + " Missing " + nid.shortNotation() + " in HgIncomingCommand.execLite result", removed, equalTo(true)); | |
122 } | |
123 errorCollector.checkThat(what + " Superfluous cset reported by HgIncomingCommand.execLite", set.isEmpty(), equalTo(true)); | |
124 } | |
125 | |
126 static File createEmptyDir(String dirName) throws IOException { | |
127 File dest = new File(Configuration.get().getTempDir(), dirName); | |
128 if (dest.exists()) { | |
129 TestClone.rmdir(dest); | |
130 } | |
131 dest.mkdirs(); | |
132 return dest; | |
133 } | |
134 | |
135 static File initEmptyTempRepo(String dirName) throws IOException { | |
136 File dest = createEmptyDir(dirName); | |
137 Internals implHelper = new Internals(); | |
138 implHelper.setStorageConfig(1, STORE | FNCACHE | DOTENCODE); | |
139 implHelper.initEmptyRepository(new File(dest, ".hg")); | |
140 return dest; | |
141 } | |
142 } |