comparison test/org/tmatesoft/hg/test/TestMqExtension.java @ 475:0e34b8f3946a

Tests for MqManager
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 12 Jul 2012 16:57:40 +0200
parents
children d2f6ab541330
comparison
equal deleted inserted replaced
474:09f2d38ecf26 475:0e34b8f3946a
1 /*
2 * Copyright (c) 2012 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.util.Iterator;
22 import java.util.LinkedList;
23
24 import org.junit.Test;
25 import org.tmatesoft.hg.repo.HgRepository;
26 import org.tmatesoft.hg.repo.ext.MqManager;
27 import org.tmatesoft.hg.repo.ext.MqManager.PatchRecord;
28
29 /**
30 * {junit-test-repos}/test-mq/
31 *
32 * @author Artem Tikhomirov
33 * @author TMate Software Ltd.
34 */
35 public class TestMqExtension {
36
37 @Test
38 public void testMqManager() throws Exception {
39 HgRepository repo = Configuration.get().find("test-mq");
40 MqManager mqManager = new MqManager(repo);
41 mqManager.refresh();
42 OutputParser.Stub output = new OutputParser.Stub();
43 ExecHelper eh = new ExecHelper(output, repo.getWorkingDir());
44 // `hg qseries`
45 eh.run("hg", "qseries");
46 LinkedList<PatchRecord> allKnownPatches = new LinkedList<PatchRecord>(mqManager.getAllKnownPatches());
47 assertTrue("[sanity]", allKnownPatches.size() > 0);
48 for (CharSequence l : output.lines()) {
49 for (Iterator<PatchRecord> it = allKnownPatches.listIterator(); it.hasNext(); ) {
50 if (it.next().getName().equals(l)) {
51 it.remove();
52 }
53 }
54 }
55 assertTrue("Known patches shall match those from `hg qseries`", allKnownPatches.isEmpty());
56 //
57 // `hg qapplied`, patches from the queue already applied to the repo
58 eh.run("hg", "qapplied");
59 LinkedList<PatchRecord> appliedPatches = new LinkedList<PatchRecord>(mqManager.getAppliedPatches());
60 assertTrue("[sanity]", appliedPatches.size() > 0);
61 for (CharSequence l : output.lines()) {
62 for (Iterator<PatchRecord> it = appliedPatches.listIterator(); it.hasNext(); ) {
63 if (it.next().getName().equals(l)) {
64 it.remove();
65 }
66 }
67 }
68 assertTrue("Each patch reported as applied shall match thos from `hg qapplied`", appliedPatches.isEmpty());
69
70 assertTrue("[sanity] ",mqManager.getQueueSize() > 0);
71 boolean allAppliedAreKnown = mqManager.getAllKnownPatches().containsAll(mqManager.getAppliedPatches());
72 assertTrue(allAppliedAreKnown); // ensure instances are the same, ==
73
74 // `hg qqueue`
75 assertTrue("[sanity]",mqManager.getQueueNames().size() > 1);
76 assertTrue(mqManager.getActiveQueueName().length() > 0);
77 eh.run("hg", "qqueue");
78 boolean activeQueueFound = false;
79 LinkedList<String> queueNames = new LinkedList<String>(mqManager.getQueueNames());
80 for (String l : output.lines()) {
81 if (l.endsWith("(active)")) {
82 l = l.substring(0, l.length() - 8).trim();
83 assertEquals(l, mqManager.getActiveQueueName());
84 assertFalse("only single active queue", activeQueueFound);
85 activeQueueFound = true;
86 }
87 assertTrue(queueNames.remove(l));
88 }
89 assertTrue(activeQueueFound);
90 assertTrue(queueNames.isEmpty()); // every queue name we found matches `hg qqueue` output
91 }
92 }