comparison test/org/tmatesoft/hg/test/TestAddRemove.java @ 529:95bdcf75e71e

Command to schedule addition/removal of repository files
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 21 Jan 2013 19:41:51 +0100
parents
children 2813a26b8999
comparison
equal deleted inserted replaced
528:f7fbf48b9383 529:95bdcf75e71e
1 /*
2 * Copyright (c) 2013 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.junit.Assert.assertEquals;
20
21 import java.io.File;
22 import java.io.FileOutputStream;
23 import java.io.IOException;
24
25 import org.junit.Rule;
26 import org.junit.Test;
27 import org.tmatesoft.hg.core.HgAddRemoveCommand;
28 import org.tmatesoft.hg.repo.HgLookup;
29 import org.tmatesoft.hg.repo.HgRepository;
30 import org.tmatesoft.hg.util.Path;
31
32 /**
33 *
34 * @author Artem Tikhomirov
35 * @author TMate Software Ltd.
36 */
37 public class TestAddRemove {
38
39 @Rule
40 public ErrorCollectorExt errorCollector = new ErrorCollectorExt();
41
42 private HgRepository repo;
43 private ExecHelper eh;
44
45 public TestAddRemove() {
46 }
47
48 @Test
49 public void testScheduleAddition() throws Exception {
50 File testRepoLoc = TestRevert.cloneRepoToTempLocation("log-1", "test-addremove-1", false);
51 repo = new HgLookup().detect(testRepoLoc);
52
53 StatusOutputParser statusParser = new StatusOutputParser();
54 eh = new ExecHelper(statusParser, testRepoLoc);
55 eh.run("hg", "status", "-A");
56 assertEquals("[sanity]", 0, statusParser.getUnknown().size());
57 assertEquals("[sanity]", 0, statusParser.getAdded().size());
58 //
59 createFile(new File(testRepoLoc, "one"), "1");
60 createFile(new File(testRepoLoc, "two"), "2");
61 statusParser.reset();
62 eh.run("hg", "status", "-A");
63 assertEquals("[sanity]", 2, statusParser.getUnknown().size());
64 assertEquals("[sanity]", 0, statusParser.getAdded().size());
65
66 new HgAddRemoveCommand(repo).add(Path.create("one"), Path.create("two")).execute();
67 statusParser.reset();
68 eh.run("hg", "status", "-A");
69 assertEquals(0, statusParser.getUnknown().size());
70 assertEquals(2, statusParser.getAdded().size());
71 }
72
73 @Test
74 public void testScheduleRemoval() throws Exception {
75 File testRepoLoc = TestRevert.cloneRepoToTempLocation("log-1", "test-addremove-2", false);
76 repo = new HgLookup().detect(testRepoLoc);
77
78 StatusOutputParser statusParser = new StatusOutputParser();
79 eh = new ExecHelper(statusParser, testRepoLoc);
80 eh.run("hg", "status", "-A");
81 assertEquals("[sanity]", 0, statusParser.getUnknown().size());
82 assertEquals("[sanity]", 0, statusParser.getRemoved().size());
83
84 new HgAddRemoveCommand(repo).remove(Path.create("b"), Path.create("d")).execute();
85 statusParser.reset();
86 eh.run("hg", "status", "-A");
87 assertEquals(2, statusParser.getRemoved().size());
88 }
89
90 private static void createFile(File f, Object content) throws IOException {
91 FileOutputStream fos = new FileOutputStream(f, true);
92 fos.write(String.valueOf(content).getBytes());
93 fos.close();
94 }
95
96 }