view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialUrlSupportTest.java @ 1068:2d8aab94494f Lakhnau-2020.2.x release-86063

TW-70693
author victory.bedrosova
date Thu, 18 Mar 2021 18:30:34 +0100
parents 471eaf5420c8
children 776adc1cf2ad
line wrap: on
line source
/*
 * Copyright 2000-2018 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package jetbrains.buildServer.buildTriggers.vcs.mercurial;

import jetbrains.buildServer.vcs.Credentials;
import jetbrains.buildServer.vcs.VcsException;
import jetbrains.buildServer.vcs.VcsUrl;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.util.Map;

import static jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialSupportBuilder.mercurialSupport;
import static junit.framework.Assert.*;

@Test
public class MercurialUrlSupportTest extends BaseMercurialTestCase {
  private MercurialUrlSupport myUrlSupport;

  @BeforeMethod
  @Override
  public void setUp() throws Exception {
    super.setUp();

    ServerPluginConfig myPluginConfig = new ServerPluginConfigBuilder()
            .cachesDir(myTempFiles.createTempDir())
            .build();
    MercurialVcsSupport vcsSupport = mercurialSupport().withConfig(myPluginConfig).build();
    myUrlSupport = new MercurialUrlSupport(vcsSupport);
  }

  public void maven_like_url() throws VcsException {
    VcsUrl url = new VcsUrl("scm:hg:http://host/v3", new Credentials("user1", "pass1"));
    Map<String, String> props = myUrlSupport.convertToVcsRootProperties(url);
    assertNotNull(props);

    assertEquals("http://host/v3", props.get(Constants.REPOSITORY_PROP));
    assertEquals("user1", props.get(Constants.USERNAME));
    assertEquals("pass1", props.get(Constants.PASSWORD));
  }

  public void http_protocol_mercurial_repo() throws VcsException {
    VcsUrl url = new VcsUrl("http://hg.jetbrains.org/hg/mercurial/", new Credentials("user1", "pass1"));
    Map<String, String> props = myUrlSupport.convertToVcsRootProperties(url);
    assertNotNull(props);

    assertEquals("http://hg.jetbrains.org/hg/mercurial/", props.get(Constants.REPOSITORY_PROP));
    assertEquals("user1", props.get(Constants.USERNAME));
    assertEquals("pass1", props.get(Constants.PASSWORD));
  }

  public void ssh_protocol_mercurial_repo() throws VcsException {
    VcsUrl url = new VcsUrl("ssh://hg@bitbucket.org/user/repo");
    Map<String, String> props = myUrlSupport.convertToVcsRootProperties(url);
    assertNotNull(props);

    assertEquals("ssh://hg@bitbucket.org/user/repo", props.get(Constants.REPOSITORY_PROP));
  }

  public void http_protocol_svn_repo() throws VcsException {
    VcsUrl url = new VcsUrl("http://svn.jetbrains.org/teamcity/plugins/xml-tests-reporting/trunk");
    Map<String, String> props = myUrlSupport.convertToVcsRootProperties(url);
    assertNull(props);
  }
}