view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CommitsInfoBuilderSupportTest.java @ 693:2c9f7f6d8a12

TODO
author eugene.petrenko@gmail.com
date Thu, 19 Dec 2013 19:17:12 +0100
parents e6d203e5c6e3
children d113beb9e519
line wrap: on
line source
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);
    }
  }

}