view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubRepoTest.java @ 951:0cf858cb793c

Describe mercurial VCS root parameters
author Dmitry Neverov <dmitry.neverov@gmail.com>
date Thu, 09 Jun 2016 16:57:06 +0200
parents d94cdfbd9e1c
children 7bf4d943d5bb
line wrap: on
line source
/*
 * Copyright 2000-2014 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.buildTriggers.vcs.mercurial.command.exception.WrongSubrepoUrlException;
import org.jetbrains.annotations.NotNull;
import org.testng.annotations.Test;

import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.fail;

@Test
public class SubRepoTest {

  public void url_resolution() throws Exception {
    //http://www.selenic.com/mercurial/hg.1.html#urls
    assertEquals("http://acme.org/subrepo", subrepoWithUrl("../subrepo").resolveUrl("http://acme.org/mainrepo"));
    assertEquals("http://acme.org/mainrepo/subrepo", subrepoWithUrl("./subrepo").resolveUrl("http://acme.org/mainrepo"));
    assertEquals("http://acme.org/mainrepo/subrepo", subrepoWithUrl("subrepo").resolveUrl("http://acme.org/mainrepo"));
    assertEquals("http://some.org/subrepo", subrepoWithUrl("http://some.org/subrepo").resolveUrl("http://acme.org/mainrepo"));
    assertEquals("c:/subrepo", subrepoWithUrl("c:/subrepo").resolveUrl("http://acme.org/mainrepo"));
    try {
      subrepoWithUrl("c:\\subrepo").resolveUrl("http://acme.org/mainrepo");
      fail();
    } catch (WrongSubrepoUrlException e) {
    }
    assertEquals("ssh://acme.org//subrepo", subrepoWithUrl("../subrepo").resolveUrl("ssh://acme.org//mainrepo"));
    assertEquals("ssh://acme.org/subrepo", subrepoWithUrl("../subrepo").resolveUrl("ssh://acme.org/mainrepo"));
    assertEquals("ssh://acme.org/subrepo", subrepoWithUrl("../subrepo ").resolveUrl("ssh://acme.org/mainrepo"));
  }

  private SubRepo subrepoWithUrl(@NotNull String subrepoUrl) {
    return new SubRepo("some/path", subrepoUrl, "some_revision");
  }

}