Mercurial > hg4j
comparison hg4j/src/test/java/org/tmatesoft/hg/test/TestClone.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 java.io.File; | |
20 import java.io.IOException; | |
21 import java.util.Arrays; | |
22 import java.util.LinkedList; | |
23 import java.util.List; | |
24 | |
25 import org.hamcrest.CoreMatchers; | |
26 import org.junit.Rule; | |
27 import org.junit.Test; | |
28 import org.tmatesoft.hg.core.HgCloneCommand; | |
29 import org.tmatesoft.hg.repo.HgRemoteRepository; | |
30 | |
31 /** | |
32 * | |
33 * @author Artem Tikhomirov | |
34 * @author TMate Software Ltd. | |
35 */ | |
36 public class TestClone { | |
37 | |
38 @Rule | |
39 public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); | |
40 | |
41 public static void main(String[] args) throws Throwable { | |
42 TestClone t = new TestClone(); | |
43 t.testSimpleClone(); | |
44 t.errorCollector.verify(); | |
45 } | |
46 | |
47 public TestClone() { | |
48 } | |
49 | |
50 @Test | |
51 public void testSimpleClone() throws Exception { | |
52 int x = 0; | |
53 final File tempDir = Configuration.get().getTempDir(); | |
54 for (HgRemoteRepository hgRemote : Configuration.get().allRemote()) { | |
55 HgCloneCommand cmd = new HgCloneCommand(); | |
56 cmd.source(hgRemote); | |
57 File dest = new File(tempDir, "test-clone-" + x++); | |
58 if (dest.exists()) { | |
59 rmdir(dest); | |
60 } | |
61 cmd.destination(dest); | |
62 cmd.execute(); | |
63 verify(hgRemote, dest); | |
64 } | |
65 } | |
66 | |
67 private void verify(HgRemoteRepository hgRemote, File dest) throws Exception { | |
68 ExecHelper eh = new ExecHelper(new OutputParser.Stub(), dest); | |
69 eh.run("hg", "verify"); | |
70 errorCollector.checkThat("Verify", eh.getExitValue(), CoreMatchers.equalTo(0)); | |
71 eh.run("hg", "out", hgRemote.getLocation()); | |
72 errorCollector.checkThat("Outgoing", eh.getExitValue(), CoreMatchers.equalTo(1)); | |
73 eh.run("hg", "in", hgRemote.getLocation()); | |
74 errorCollector.checkThat("Incoming", eh.getExitValue(), CoreMatchers.equalTo(1)); | |
75 } | |
76 | |
77 static void rmdir(File dest) throws IOException { | |
78 LinkedList<File> queue = new LinkedList<File>(); | |
79 queue.addAll(Arrays.asList(dest.listFiles())); | |
80 while (!queue.isEmpty()) { | |
81 File next = queue.removeFirst(); | |
82 if (next.isDirectory()) { | |
83 List<File> files = Arrays.asList(next.listFiles()); | |
84 if (!files.isEmpty()) { | |
85 queue.addAll(files); | |
86 queue.add(next); | |
87 } | |
88 // fall through | |
89 } | |
90 next.delete(); | |
91 } | |
92 dest.delete(); | |
93 } | |
94 } |