Mercurial > hg4j
annotate test/org/tmatesoft/hg/test/TestClone.java @ 201:a736f42ed75b
Primitive test for clone command
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 21 Apr 2011 19:16:45 +0200 |
parents | |
children | 706bcc7cfee4 |
rev | line source |
---|---|
201
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2011 TMate Software Ltd |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.test; |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import java.io.File; |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 import java.io.IOException; |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import java.util.Arrays; |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import java.util.LinkedList; |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 import java.util.List; |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import junit.framework.Assert; |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import org.junit.Rule; |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 import org.tmatesoft.hg.core.HgCloneCommand; |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 import org.tmatesoft.hg.repo.HgRemoteRepository; |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 /** |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 * |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 * @author Artem Tikhomirov |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 * @author TMate Software Ltd. |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 */ |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 public class TestClone { |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 @Rule |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 public static void main(String[] args) throws Exception { |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 TestClone t = new TestClone(); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 t.testSimpleClone(); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 } |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 public TestClone() { |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 } |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 public void testSimpleClone() throws Exception { |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 int x = 0; |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 final File tempDir = new File(System.getProperty("java.io.tmpdir")); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 for (HgRemoteRepository hgRemote : Configuration.get().allRemote()) { |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 HgCloneCommand cmd = new HgCloneCommand(); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 cmd.source(hgRemote); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 File dest = new File(tempDir, "test-clone-" + x++); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 if (dest.exists()) { |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 rmdir(dest); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 } |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 cmd.destination(dest); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 cmd.execute(); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 verify(hgRemote, dest); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 } |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 } |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 private void verify(HgRemoteRepository hgRemote, File dest) throws Exception { |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 OutputParser noop = new OutputParser() { |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 public void parse(CharSequence seq) { |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 // no-op |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 } |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 }; |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 ExecHelper eh = new ExecHelper(noop, dest); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 eh.run("hg", "verify"); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 Assert.assertEquals(0, eh.getExitValue()); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 eh.run("hg", "out", hgRemote.getLocation()); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 Assert.assertEquals(1, eh.getExitValue()); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 eh.run("hg", "in", hgRemote.getLocation()); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 Assert.assertEquals(1, eh.getExitValue()); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 } |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 private static void rmdir(File dest) throws IOException { |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 LinkedList<File> queue = new LinkedList<File>(); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 queue.addAll(Arrays.asList(dest.listFiles())); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 while (!queue.isEmpty()) { |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 File next = queue.removeFirst(); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 if (next.isDirectory()) { |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 List<File> files = Arrays.asList(next.listFiles()); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 if (!files.isEmpty()) { |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 queue.addAll(files); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 queue.add(next); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 } |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 // fall through |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 } |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 next.delete(); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 } |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 dest.delete(); |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 } |
a736f42ed75b
Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 } |