You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RemoteSetUrlCommandTest.java 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. import static org.junit.Assert.assertArrayEquals;
  12. import static org.junit.Assert.assertEquals;
  13. import org.eclipse.jgit.api.RemoteSetUrlCommand.UriType;
  14. import org.eclipse.jgit.transport.RemoteConfig;
  15. import org.eclipse.jgit.transport.URIish;
  16. import org.junit.Test;
  17. public class RemoteSetUrlCommandTest extends AbstractRemoteCommandTest {
  18. @Test
  19. public void testSetUrl() throws Exception {
  20. // setup an initial remote
  21. setupRemote();
  22. // execute the command to change the fetch url
  23. RemoteSetUrlCommand cmd = Git.wrap(db).remoteSetUrl();
  24. cmd.setRemoteName(REMOTE_NAME);
  25. URIish newUri = new URIish("git://test.com/test");
  26. cmd.setRemoteUri(newUri);
  27. RemoteConfig remote = cmd.call();
  28. // assert that the changed remote has the new fetch url
  29. assertEquals(REMOTE_NAME, remote.getName());
  30. assertArrayEquals(new URIish[] { newUri }, remote.getURIs().toArray());
  31. // assert that the changed remote is available in the git configuration
  32. assertRemoteConfigEquals(remote,
  33. new RemoteConfig(db.getConfig(), REMOTE_NAME));
  34. }
  35. @Test
  36. public void testSetPushUrl() throws Exception {
  37. // setup an initial remote
  38. RemoteConfig remoteConfig = setupRemote();
  39. // execute the command to change the push url
  40. RemoteSetUrlCommand cmd = Git.wrap(db).remoteSetUrl();
  41. cmd.setRemoteName(REMOTE_NAME);
  42. URIish newUri = new URIish("git://test.com/test");
  43. cmd.setRemoteUri(newUri);
  44. cmd.setUriType(UriType.PUSH);
  45. RemoteConfig remote = cmd.call();
  46. // assert that the changed remote has the old fetch url and the new push
  47. // url
  48. assertEquals(REMOTE_NAME, remote.getName());
  49. assertEquals(remoteConfig.getURIs(), remote.getURIs());
  50. assertArrayEquals(new URIish[] { newUri },
  51. remote.getPushURIs().toArray());
  52. // assert that the changed remote is available in the git configuration
  53. assertRemoteConfigEquals(remote,
  54. new RemoteConfig(db.getConfig(), REMOTE_NAME));
  55. }
  56. }