View Javadoc
1   /*
2    * Copyright (C) 2015, Kaloyan Raev <kaloyan.r@zend.com> and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  package org.eclipse.jgit.api;
11  
12  import static org.junit.Assert.assertArrayEquals;
13  import static org.junit.Assert.assertEquals;
14  
15  import org.eclipse.jgit.api.RemoteSetUrlCommand.UriType;
16  import org.eclipse.jgit.transport.RemoteConfig;
17  import org.eclipse.jgit.transport.URIish;
18  import org.junit.Test;
19  
20  public class RemoteSetUrlCommandTest extends AbstractRemoteCommandTest {
21  
22  	@Test
23  	public void testSetUrl() throws Exception {
24  		// setup an initial remote
25  		setupRemote();
26  
27  		// execute the command to change the fetch url
28  		RemoteSetUrlCommand cmd = Git.wrap(db).remoteSetUrl();
29  		cmd.setRemoteName(REMOTE_NAME);
30  		URIish newUri = new URIish("git://test.com/test");
31  		cmd.setRemoteUri(newUri);
32  		RemoteConfig remote = cmd.call();
33  
34  		// assert that the changed remote has the new fetch url
35  		assertEquals(REMOTE_NAME, remote.getName());
36  		assertArrayEquals(new URIish[] { newUri }, remote.getURIs().toArray());
37  
38  		// assert that the changed remote is available in the git configuration
39  		assertRemoteConfigEquals(remote,
40  				new RemoteConfig(db.getConfig(), REMOTE_NAME));
41  	}
42  
43  	@Test
44  	public void testSetPushUrl() throws Exception {
45  		// setup an initial remote
46  		RemoteConfig remoteConfig = setupRemote();
47  
48  		// execute the command to change the push url
49  		RemoteSetUrlCommand cmd = Git.wrap(db).remoteSetUrl();
50  		cmd.setRemoteName(REMOTE_NAME);
51  		URIish newUri = new URIish("git://test.com/test");
52  		cmd.setRemoteUri(newUri);
53  		cmd.setUriType(UriType.PUSH);
54  		RemoteConfig remote = cmd.call();
55  
56  		// assert that the changed remote has the old fetch url and the new push
57  		// url
58  		assertEquals(REMOTE_NAME, remote.getName());
59  		assertEquals(remoteConfig.getURIs(), remote.getURIs());
60  		assertArrayEquals(new URIish[] { newUri },
61  				remote.getPushURIs().toArray());
62  
63  		// assert that the changed remote is available in the git configuration
64  		assertRemoteConfigEquals(remote,
65  				new RemoteConfig(db.getConfig(), REMOTE_NAME));
66  	}
67  
68  }