comparison test/org/tmatesoft/hg/test/TestBundle.java @ 668:d25f0324a27a

Delete bundle with push/pull changes once command completes successfully. Test for bundle generator
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 11 Jul 2013 18:41:40 +0200
parents
children
comparison
equal deleted inserted replaced
667:fba85bc1dfb8 668:d25f0324a27a
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.*;
20
21 import java.io.File;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collections;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 import org.junit.Rule;
30 import org.junit.Test;
31 import org.tmatesoft.hg.core.Nodeid;
32 import org.tmatesoft.hg.internal.BundleGenerator;
33 import org.tmatesoft.hg.repo.HgBundle;
34 import org.tmatesoft.hg.repo.HgBundle.GroupElement;
35 import org.tmatesoft.hg.repo.HgInternals;
36 import org.tmatesoft.hg.repo.HgLookup;
37 import org.tmatesoft.hg.repo.HgRepository;
38 import org.tmatesoft.hg.repo.HgRuntimeException;
39
40 /**
41 *
42 * @author Artem Tikhomirov
43 * @author TMate Software Ltd.
44 */
45 public class TestBundle {
46 @Rule
47 public ErrorCollectorExt errorCollector = new ErrorCollectorExt();
48
49 @Test
50 public void testCreateBundle() throws Exception {
51 final HgRepository hgRepo = Configuration.get().own();
52 BundleGenerator bg = new BundleGenerator(HgInternals.getImplementationRepo(hgRepo));
53 ArrayList<Nodeid> l = new ArrayList<Nodeid>();
54 l.add(Nodeid.fromAscii("9ef1fab9f5e3d51d70941121dc27410e28069c2d")); // 640
55 l.add(Nodeid.fromAscii("2f33f102a8fa59274a27ebbe1c2903cecac6c5d5")); // 639
56 l.add(Nodeid.fromAscii("d074971287478f69ab0a64176ce2284d8c1e91c3")); // 638
57 File bundleFile = bg.create(l);
58 HgBundle b = new HgLookup().loadBundle(bundleFile);
59 //
60 DumbInspector insp = new DumbInspector();
61 b.inspectChangelog(insp);
62 errorCollector.assertTrue(insp.clogEnter && insp.clogExit);
63 errorCollector.assertFalse(insp.csets.isEmpty());
64 errorCollector.assertFalse(insp.manifestEnter || insp.manifestExit);
65 Collections.sort(l);
66 Collections.sort(insp.csets);
67 errorCollector.assertEquals(l, insp.csets);
68 errorCollector.assertEquals(0, insp.filesEnter);
69 errorCollector.assertEquals(0, insp.filesExit);
70 errorCollector.assertTrue(insp.manifests == null || insp.manifests.isEmpty());
71 errorCollector.assertTrue(insp.files.isEmpty());
72 //
73 insp = new DumbInspector();
74 b.inspectFiles(insp);
75 errorCollector.assertFalse(insp.clogEnter && insp.clogExit);
76 errorCollector.assertFalse(insp.manifestEnter || insp.manifestExit);
77 // $ hg log -r 638:640 --debug | grep files
78 List<String> affectedFiles = Arrays.asList("src/org/tmatesoft/hg/repo/HgDataFile.java", "COPYING", "build.gradle", ".hgtags");
79 // "src/org/tmatesoft/hg/repo/HgBlameInspector.java" was deleted in r638 and hence not part of the bundle
80 ArrayList<String> foundFiles = new ArrayList<String>(insp.files.keySet());
81 Collections.sort(affectedFiles);
82 Collections.sort(foundFiles);
83 errorCollector.assertEquals(affectedFiles, foundFiles);
84 errorCollector.assertEquals(affectedFiles.size(), insp.filesEnter);
85 errorCollector.assertEquals(affectedFiles.size(), insp.filesExit);
86 b.unlink();
87 }
88
89 private static class DumbInspector implements HgBundle.Inspector {
90 public boolean clogEnter, clogExit, manifestEnter, manifestExit;
91 public int filesEnter, filesExit;
92 public List<Nodeid> csets, manifests;
93 public Map<String, List<Nodeid>> files = new HashMap<String, List<Nodeid>>();
94 private List<Nodeid> actual;
95
96 public void changelogStart() throws HgRuntimeException {
97 assertFalse(clogEnter);
98 assertFalse(clogExit);
99 clogEnter = true;
100 actual = csets = new ArrayList<Nodeid>();
101 }
102
103 public void changelogEnd() throws HgRuntimeException {
104 assertTrue(clogEnter);
105 assertFalse(clogExit);
106 clogExit = true;
107 actual = null;
108 }
109
110 public void manifestStart() throws HgRuntimeException {
111 assertFalse(manifestEnter);
112 assertFalse(manifestExit);
113 manifestEnter = true;
114 actual = manifests = new ArrayList<Nodeid>();
115 }
116
117 public void manifestEnd() throws HgRuntimeException {
118 assertTrue(manifestEnter);
119 assertFalse(manifestExit);
120 manifestExit = true;
121 actual = null;
122 }
123
124 public void fileStart(String name) throws HgRuntimeException {
125 assertEquals(filesEnter, filesExit);
126 filesEnter++;
127 files.put(name, actual = new ArrayList<Nodeid>());
128 }
129
130 public void fileEnd(String name) throws HgRuntimeException {
131 assertEquals(filesEnter, 1 + filesExit);
132 filesExit++;
133 actual = null;
134 }
135
136 public boolean element(GroupElement element) throws HgRuntimeException {
137 actual.add(element.node());
138 return true;
139 }
140 }
141 }