view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/RevisionFormatTest.java @ 694:6e33b89c682b

do not sync repository (assume it was synced beforehand)
author eugene.petrenko@gmail.com
date Thu, 19 Dec 2013 19:22:16 +0100
parents 817a15a54de8
children a07f685ce394
line wrap: on
line source
package jetbrains.buildServer.buildTriggers.vcs.mercurial;

import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.AuthSettings;
import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.TestCommandSettingsFactory;
import jetbrains.buildServer.vcs.*;
import org.jetbrains.annotations.NotNull;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

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

@Test
public class RevisionFormatTest extends BaseMercurialPatchTestCase {

  private MercurialVcsSupport myVcs;
  private VcsRoot myRoot;
  private File myRemoteRepoDir;

  @BeforeMethod
  public void setUp() throws Exception {
    super.setUp();
    ServerPluginConfig pluginConfig = new ServerPluginConfigBuilder()
            .cachesDir(myTempFiles.createTempDir())
            .build();
    myVcs = mercurialSupport().withConfig(pluginConfig).build();

    myRemoteRepoDir = copyRepository(myTempFiles, new File("mercurial-tests/testData/rep1").getAbsolutePath());
    myRoot = vcsRoot().withUrl(myRemoteRepoDir.getAbsolutePath()).build();
  }


  public void collect_changes_result_does_not_depend_on_revnums() throws VcsException {
    List<ModificationData> changesWithRevnums = myVcs.getCollectChangesPolicy().collectChanges(myRoot,
            "1:1d446e82d356", "3:9522278aa38d", CheckoutRules.DEFAULT);
    List<ModificationData> changesWithoutRevnums = myVcs.getCollectChangesPolicy().collectChanges(myRoot,
            "1d446e82d356", "9522278aa38d", CheckoutRules.DEFAULT);
    assertEquals(changesWithoutRevnums, changesWithRevnums);
  }


  public void labeling_does_not_depend_on_revnums() throws Exception {
    myVcs.label("tag1", "3:9522278aa38d", myRoot, CheckoutRules.DEFAULT);
    myVcs.label("tag2", "9522278aa38d", myRoot, CheckoutRules.DEFAULT);
    HgRepo repo = createRepo(myRemoteRepoDir);
    String tag1 = repo.id().inLocalRepository().namedRevision("tag1").call();
    String tag2 = repo.id().inLocalRepository().namedRevision("tag2").call();
    assertEquals(tag2, tag1);
  }


  public void get_file_content_does_not_depend_on_revnums() throws Exception {
    byte[] contentWithRevnums = myVcs.getContent("dir1/file4.txt", myRoot, "2:7209b1f1d793");
    byte[] contentWithoutRevnums = myVcs.getContent("dir1/file4.txt", myRoot, "7209b1f1d793");
    assertEquals(contentWithoutRevnums, contentWithRevnums);
  }


  public void clean_patch_does_not_depend_on_revnums() throws Exception {
    setName("cleanPatch1_checkout_rules");
    ByteArrayOutputStream output = buildPatch(myVcs, myRoot, null, "4:b06a290a363b", new CheckoutRules("+:dir1/subdir=>."));
    checkPatchResult(output.toByteArray());
    output = buildPatch(myVcs, myRoot, null, "b06a290a363b", new CheckoutRules("+:dir1/subdir=>."));
    checkPatchResult(output.toByteArray());
  }

  public void incremental_patch_does_not_depend_on_revnums() throws Exception {
    setName("patch2");
    ByteArrayOutputStream output = buildPatch(myVcs, myRoot, "3:9522278aa38d", "6:b9deb9a1c6f4", CheckoutRules.DEFAULT);
    checkPatchResult(output.toByteArray());
    output = buildPatch(myVcs, myRoot, "9522278aa38d", "6:b9deb9a1c6f4", CheckoutRules.DEFAULT);
    checkPatchResult(output.toByteArray());
    output = buildPatch(myVcs, myRoot, "3:9522278aa38d", "b9deb9a1c6f4", CheckoutRules.DEFAULT);
    checkPatchResult(output.toByteArray());
    output = buildPatch(myVcs, myRoot, "9522278aa38d", "b9deb9a1c6f4", CheckoutRules.DEFAULT);
    checkPatchResult(output.toByteArray());
  }


  public void should_not_include_revnum_in_current_version() throws VcsException {
    String currentVersion = myVcs.getCurrentVersion(myRoot);
    assertFalse(currentVersion.contains(":"));
  }


  public void should_not_include_revnum_in_current_state() throws VcsException {
    RepositoryStateData state = myVcs.getCollectChangesPolicy().getCurrentState(myRoot);
    for (Map.Entry<String, String> entry : state.getBranchRevisions().entrySet()) {
      String branchName = entry.getKey();
      String revision = entry.getKey();
      assertFalse(revision.contains(":"), "Revision of branch " + branchName + " contains revnum: " + revision);
    }
  }


  public void should_not_include_revnum_in_collected_changes() throws VcsException {
    List<ModificationData> changes = myVcs.getCollectChangesPolicy().collectChanges(myRoot, "1d446e82d356", "9522278aa38d", CheckoutRules.DEFAULT);
    for (ModificationData c : changes) {
      assertFalse(c.getVersion().contains(":"), "Change version contains revnum: " + c.toString());
      for (String parentVersion : c.getParentRevisions()) {
        assertFalse(parentVersion.contains(":"), "Parent version contains revnum: " + c.toString());
      }
      for (VcsChange changedFile : c.getChanges()) {
        assertFalse(changedFile.getAfterChangeRevisionNumber().contains(":"),
                "Vcs change contains revnum : " + changedFile.toString());
        assertFalse(changedFile.getBeforeChangeRevisionNumber().contains(":"),
                "Vcs change contains revnum : " + changedFile.toString());
      }
    }
  }


  @Override
  protected String getTestDataPath() {
    return "mercurial-tests/testData";
  }

  private HgRepo createRepo(@NotNull File dir) throws IOException {
    return new HgRepo(new TestCommandSettingsFactory(), dir, Util.getHgPath(), new AuthSettings());
  }

}