view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CommitsInfoBuilderSupportTest.java @ 732:31a1aca3305c

Update copyright
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Tue, 14 Jan 2014 12:45:10 +0100
parents 501cb1911d4b
children 1e4021519ff3
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.TestLogger;
import jetbrains.buildServer.vcs.*;
import jetbrains.vcs.api.CommitInfo;
import org.jetbrains.annotations.NotNull;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.util.*;

import static jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialSupportBuilder.mercurialSupport;
import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository;
import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot;

/**
 * Created 30.09.13 13:07
 *
 * @author Eugene Petrenko (eugene.petrenko@jetbrains.com)
 */
public class CommitsInfoBuilderSupportTest extends BaseMercurialTestCase {
  private File myRemoteRepo;
  private MercurialVcsSupport myVcs;
  private MercurialCommitsInfoBuilderSupport mySupport;

  @Override
  @BeforeMethod
  public void setUp() throws Exception {
    super.setUp();
    ServerPluginConfig pluginConfig = new ServerPluginConfigBuilder()
//            .hgPath("hg")
            .cachesDir(myTempFiles.createTempDir())
            .build();
    MercurialSupportBuilder mercurialBuilder = mercurialSupport().withConfig(pluginConfig);
    myVcs = mercurialBuilder.build();
    mySupport = new MercurialCommitsInfoBuilderSupport(myVcs, mercurialBuilder.getHgRootFactory());
    myRemoteRepo = myTempFiles.createTempDir();
    copyRepository(new File("mercurial-tests/testData/rep2"), myRemoteRepo);
  }

  @Test
  public void simpleTest() throws IOException, VcsException {
    TestLogger.enableMainAndVCSLoggerDebug();

    VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build();


    final List<CommitInfo> commitInfos = new ArrayList<CommitInfo>();
    mySupport.collectCommits(root, CheckoutRules.DEFAULT, new CommitsInfoBuilder.CommitsConsumer() {
      public void consumeCommit(@NotNull CommitInfo commit) {
        commitInfos.add(commit);
      }
    });
    Assert.assertFalse(commitInfos.isEmpty());

    for (CommitInfo commitInfo : commitInfos) {
      System.out.println(commitInfo);
    }

    final Set<String> branches = new TreeSet<String>();
    final Set<String> tags = new TreeSet<String>();
    final Set<String> commits = new TreeSet<String>();
    final Set<String> parents = new TreeSet<String>();
    for (CommitInfo commitInfo : commitInfos) {
      branches.addAll(commitInfo.getBranches());
      tags.addAll(commitInfo.getTags());

      //commit should be returned once
      Assert.assertTrue(commits.add(commitInfo.getVersion()));
      Assert.assertNotNull(commitInfo.getCommitAuthor());
      parents.addAll(commitInfo.getParentRevisions());
    }

    Assert.assertEquals(branches, new TreeSet<String>(Arrays.asList("default", "personal-branch", "test", "topic", "<TEST> Branch with exitics)(*&^%$#@!", "NULL")));
    Assert.assertEquals(tags, new TreeSet<String>(Arrays.asList("t1")));

    //check all parent commits are included into the set
    Assert.assertTrue(commits.containsAll(parents), "Unknown commits: " + new TreeSet<String>(parents){{removeAll(commits);}});

    final String v = "4780519e01aa"; ///30
    Assert.assertFalse(parents.contains(v));
  }

  @Test
  public void should_not_have_parse_errors() throws IOException, VcsException {
    TestLogger.enableMainAndVCSLoggerDebug();

    VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build();

    final List<CommitInfo> commitInfos = new ArrayList<CommitInfo>();
    mySupport.collectCommits(root, CheckoutRules.DEFAULT, new CommitsInfoBuilder.CommitsConsumer() {
      public void consumeCommit(@NotNull CommitInfo commit) {
        commitInfos.add(commit);
      }
    });
    Assert.assertFalse(commitInfos.isEmpty());

    for (CommitInfo commitInfo : commitInfos) {
      System.out.println(commitInfo);
    }
  }

  @Test(enabled = false)
  public void should_return_graphcommits() throws Exception {
    VcsRoot root = vcsRoot().withLocalRepository(new File("F:\\Work\\ReSharper")).build();

    final long start = System.currentTimeMillis();
    mySupport.collectCommits(root, CheckoutRules.DEFAULT, new CommitsInfoBuilder.CommitsConsumer() {
      public void consumeCommit(@NotNull CommitInfo commit) {

      }
    });

    final long actual = System.currentTimeMillis() - start;
    System.out.println("computed in " + actual + " ms");
  }


}