Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestOutgoing.java @ 203:66fd2c73c56f
Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 26 Apr 2011 15:52:33 +0200 |
parents | |
children | 883f1efbcf27 |
comparison
equal
deleted
inserted
replaced
202:706bcc7cfee4 | 203:66fd2c73c56f |
---|---|
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 java.io.File; | |
20 import java.io.FileWriter; | |
21 import java.io.IOException; | |
22 import java.util.List; | |
23 | |
24 import org.junit.Assert; | |
25 import org.junit.Rule; | |
26 import org.junit.Test; | |
27 import org.tmatesoft.hg.core.HgLogCommand; | |
28 import org.tmatesoft.hg.core.HgOutgoingCommand; | |
29 import org.tmatesoft.hg.core.Nodeid; | |
30 import org.tmatesoft.hg.repo.HgLookup; | |
31 import org.tmatesoft.hg.repo.HgRemoteRepository; | |
32 | |
33 /** | |
34 * | |
35 * @author Artem Tikhomirov | |
36 * @author TMate Software Ltd. | |
37 */ | |
38 public class TestOutgoing { | |
39 | |
40 @Rule | |
41 public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); | |
42 | |
43 public static void main(String[] args) throws Throwable { | |
44 Configuration.get().remoteServers("http://localhost:8000/"); | |
45 TestOutgoing t = new TestOutgoing(); | |
46 t.testSimple(); | |
47 t.errorCollector.verify(); | |
48 } | |
49 | |
50 public TestOutgoing() { | |
51 Configuration.get().remoteServers("http://localhost:8000/"); | |
52 } | |
53 | |
54 @Test | |
55 public void testSimple() throws Exception { | |
56 int x = 0; | |
57 HgLookup lookup = new HgLookup(); | |
58 for (HgRemoteRepository hgRemote : Configuration.get().allRemote()) { | |
59 File dest = TestIncoming.createEmptyDir("test-outgoing-" + x++); | |
60 ExecHelper eh0 = new ExecHelper(new OutputParser.Stub(false), null); | |
61 eh0.run("hg", "clone", hgRemote.getLocation(), dest.toString()); | |
62 eh0.cwd(dest); | |
63 Assert.assertEquals("initial clone failed", 0, eh0.getExitValue()); | |
64 HgOutgoingCommand cmd = new HgOutgoingCommand(lookup.detect(dest)).against(hgRemote); | |
65 LogOutputParser outParser = new LogOutputParser(true); | |
66 ExecHelper eh = new ExecHelper(outParser, dest); | |
67 HgLogCommand.CollectHandler collector = new HgLogCommand.CollectHandler(); | |
68 // | |
69 cmd.executeFull(collector); | |
70 List<Nodeid> liteResult = cmd.executeLite(null); | |
71 eh.run("hg", "outgoing", "--debug", hgRemote.getLocation()); | |
72 TestIncoming.report(collector, outParser, liteResult, errorCollector); | |
73 // | |
74 File f = new File(dest, "Test.txt"); | |
75 append(f, "1"); | |
76 eh0.run("hg", "add"); | |
77 eh0.run("hg", "commit", "-m", "1"); | |
78 append(f, "2"); | |
79 eh0.run("hg", "commit", "-m", "2"); | |
80 // | |
81 cmd = new HgOutgoingCommand(lookup.detect(dest)).against(hgRemote); | |
82 cmd.executeFull(collector = new HgLogCommand.CollectHandler()); | |
83 liteResult = cmd.executeLite(null); | |
84 outParser.reset(); | |
85 eh.run("hg", "outgoing", "--debug", hgRemote.getLocation()); | |
86 TestIncoming.report(collector, outParser, liteResult, errorCollector); | |
87 } | |
88 } | |
89 | |
90 static void append(File f, String s) throws IOException { | |
91 FileWriter fw = new FileWriter(f); | |
92 fw.append(s); | |
93 fw.close(); | |
94 } | |
95 } |