annotate test/org/tmatesoft/hg/test/Configuration.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 a05145db4d0c
children 706bcc7cfee4
rev   line source
147
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2011 TMate Software Ltd
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.test;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import static org.junit.Assert.*;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.io.File;
201
a736f42ed75b Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 147
diff changeset
22 import java.util.Collections;
a736f42ed75b Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 147
diff changeset
23 import java.util.List;
147
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import org.tmatesoft.hg.repo.HgLookup;
201
a736f42ed75b Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 147
diff changeset
26 import org.tmatesoft.hg.repo.HgRemoteRepository;
147
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import org.tmatesoft.hg.repo.HgRepository;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 /**
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 *
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 * @author Artem Tikhomirov
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 * @author TMate Software Ltd.
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 */
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 public class Configuration {
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 private static Configuration inst;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 private final File root;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 private final HgLookup lookup;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 private Configuration(File reposRoot) {
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 root = reposRoot;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 lookup = new HgLookup();
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 }
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 public static Configuration get() {
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 if (inst == null) {
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 String repo2 = System.getProperty("hg4j.tests.repos");
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 assertNotNull(repo2);
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 File rr = new File(repo2);
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 assertTrue(rr.exists());
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 inst = new Configuration(rr);
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 }
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 return inst;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 }
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 public HgRepository own() throws Exception {
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 return lookup.detectFromWorkingDir();
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 }
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 // fails if repo not found
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 public HgRepository find(String key) throws Exception {
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 HgRepository rv = lookup.detect(new File(root, key));
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 assertNotNull(rv);
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 assertFalse(rv.isInvalid());
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 return rv;
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 }
201
a736f42ed75b Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 147
diff changeset
67
a736f42ed75b Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 147
diff changeset
68 public List<HgRemoteRepository> allRemote() throws Exception {
a736f42ed75b Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 147
diff changeset
69 return Collections.singletonList(lookup.detectRemote("hg4j-gc", null));
a736f42ed75b Primitive test for clone command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 147
diff changeset
70 }
147
a05145db4d0c Bring test repos along with us to recreate testbench
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 }