Add a few simple merge test cases
[egit/charleso.git] / org.spearce.jgit.test / tst / org / spearce / jgit / transport / TransportTest.java
blobc6e3335e9ac5f9fe9a3eb22bb53bd47fca6023c6
1 /*
2 * Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
8 * conditions are met:
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * - Neither the name of the Git Development Community nor the
19 * names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior
21 * written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 package org.spearce.jgit.transport;
40 import java.io.IOException;
41 import java.util.Arrays;
42 import java.util.Collection;
43 import java.util.Collections;
45 import org.spearce.jgit.lib.RepositoryConfig;
46 import org.spearce.jgit.lib.RepositoryTestCase;
48 public class TransportTest extends RepositoryTestCase {
49 private Transport transport;
51 private RemoteConfig remoteConfig;
53 @Override
54 public void setUp() throws Exception {
55 super.setUp();
56 final RepositoryConfig config = db.getConfig();
57 remoteConfig = new RemoteConfig(config, "test");
58 remoteConfig.addURI(new URIish("http://everyones.loves.git/u/2"));
59 transport = null;
62 @Override
63 protected void tearDown() throws Exception {
64 if (transport != null) {
65 transport.close();
66 transport = null;
68 super.tearDown();
71 /**
72 * Test RefSpec to RemoteRefUpdate conversion with simple RefSpec - no
73 * wildcard, no tracking ref in repo configuration.
75 * @throws IOException
77 public void testFindRemoteRefUpdatesNoWildcardNoTracking()
78 throws IOException {
79 transport = Transport.open(db, remoteConfig);
80 final Collection<RemoteRefUpdate> result = transport
81 .findRemoteRefUpdatesFor(Collections.nCopies(1, new RefSpec(
82 "refs/heads/master:refs/heads/x")));
84 assertEquals(1, result.size());
85 final RemoteRefUpdate rru = result.iterator().next();
86 assertNull(rru.getExpectedOldObjectId());
87 assertFalse(rru.isForceUpdate());
88 assertEquals("refs/heads/master", rru.getSrcRef());
89 assertEquals(db.resolve("refs/heads/master"), rru.getNewObjectId());
90 assertEquals("refs/heads/x", rru.getRemoteName());
93 /**
94 * Test RefSpec to RemoteRefUpdate conversion with no-destination RefSpec
95 * (destination should be set up for the same name as source).
97 * @throws IOException
99 public void testFindRemoteRefUpdatesNoWildcardNoDestination()
100 throws IOException {
101 transport = Transport.open(db, remoteConfig);
102 final Collection<RemoteRefUpdate> result = transport
103 .findRemoteRefUpdatesFor(Collections.nCopies(1, new RefSpec(
104 "+refs/heads/master")));
106 assertEquals(1, result.size());
107 final RemoteRefUpdate rru = result.iterator().next();
108 assertNull(rru.getExpectedOldObjectId());
109 assertTrue(rru.isForceUpdate());
110 assertEquals("refs/heads/master", rru.getSrcRef());
111 assertEquals(db.resolve("refs/heads/master"), rru.getNewObjectId());
112 assertEquals("refs/heads/master", rru.getRemoteName());
116 * Test RefSpec to RemoteRefUpdate conversion with wildcard RefSpec.
118 * @throws IOException
120 public void testFindRemoteRefUpdatesWildcardNoTracking() throws IOException {
121 transport = Transport.open(db, remoteConfig);
122 final Collection<RemoteRefUpdate> result = transport
123 .findRemoteRefUpdatesFor(Collections.nCopies(1, new RefSpec(
124 "+refs/heads/*:refs/heads/test/*")));
126 assertEquals(9, result.size());
127 boolean foundA = false;
128 boolean foundB = false;
129 for (final RemoteRefUpdate rru : result) {
130 if ("refs/heads/a".equals(rru.getSrcRef())
131 && "refs/heads/test/a".equals(rru.getRemoteName()))
132 foundA = true;
133 if ("refs/heads/b".equals(rru.getSrcRef())
134 && "refs/heads/test/b".equals(rru.getRemoteName()))
135 foundB = true;
137 assertTrue(foundA);
138 assertTrue(foundB);
142 * Test RefSpec to RemoteRefUpdate conversion for more than one RefSpecs
143 * handling.
145 * @throws IOException
147 public void testFindRemoteRefUpdatesTwoRefSpecs() throws IOException {
148 transport = Transport.open(db, remoteConfig);
149 final RefSpec specA = new RefSpec("+refs/heads/a:refs/heads/b");
150 final RefSpec specC = new RefSpec("+refs/heads/c:refs/heads/d");
151 final Collection<RefSpec> specs = Arrays.asList(specA, specC);
152 final Collection<RemoteRefUpdate> result = transport
153 .findRemoteRefUpdatesFor(specs);
155 assertEquals(2, result.size());
156 boolean foundA = false;
157 boolean foundC = false;
158 for (final RemoteRefUpdate rru : result) {
159 if ("refs/heads/a".equals(rru.getSrcRef())
160 && "refs/heads/b".equals(rru.getRemoteName()))
161 foundA = true;
162 if ("refs/heads/c".equals(rru.getSrcRef())
163 && "refs/heads/d".equals(rru.getRemoteName()))
164 foundC = true;
166 assertTrue(foundA);
167 assertTrue(foundC);
171 * Test RefSpec to RemoteRefUpdate conversion for tracking ref search.
173 * @throws IOException
175 public void testFindRemoteRefUpdatesTrackingRef() throws IOException {
176 remoteConfig.addFetchRefSpec(new RefSpec(
177 "refs/heads/*:refs/remotes/test/*"));
178 transport = Transport.open(db, remoteConfig);
179 final Collection<RemoteRefUpdate> result = transport
180 .findRemoteRefUpdatesFor(Collections.nCopies(1, new RefSpec(
181 "+refs/heads/a:refs/heads/a")));
183 assertEquals(1, result.size());
184 final TrackingRefUpdate tru = result.iterator().next()
185 .getTrackingRefUpdate();
186 assertEquals("refs/remotes/test/a", tru.getLocalName());
187 assertEquals("refs/heads/a", tru.getRemoteName());
188 assertEquals(db.resolve("refs/heads/a"), tru.getNewObjectId());
189 assertNull(tru.getOldObjectId());