view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/RevisionFormatTest.java @ 480:efba721f9a1d Faradi-7.1.x

TW-23382 agent logs with info, server logs with debug
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Wed, 26 Sep 2012 18:29:01 +0400
parents b47cfe5cbaba
children 774229a5fcd2
line wrap: on
line source
package jetbrains.buildServer.buildTriggers.vcs.mercurial;

import com.intellij.openapi.diagnostic.Logger;
import jetbrains.buildServer.TempFiles;
import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.AuthSettings;
import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.TestCommandSettingsFactory;
import jetbrains.buildServer.log.Log4jFactory;
import jetbrains.buildServer.vcs.*;
import jetbrains.buildServer.vcs.patches.PatchTestCase;
import org.jetbrains.annotations.NotNull;
import org.jmock.Mockery;
import org.testng.annotations.AfterMethod;
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.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 PatchTestCase {

  static {
    Logger.setFactory(new Log4jFactory());
  }

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

  @BeforeMethod
  public void setUp() throws Exception {
    myTempFiles = new TempFiles();
    Mockery context = new Mockery();
    ServerPluginConfig myPluginConfig = new ServerPluginConfigBuilder()
            .cachesDir(myTempFiles.createTempDir())
            .build();
    myVcs = Util.createMercurialServerSupport(context, myPluginConfig);

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

  @AfterMethod
  public void tearDown() {
    myTempFiles.cleanup();
  }


  public void collect_changes_result_does_not_depend_on_revnums() throws VcsException {
    List<ModificationData> changesWithRevnums = myVcs.collectChanges(myRoot,
            "1:1d446e82d356", "3:9522278aa38d", CheckoutRules.DEFAULT);
    List<ModificationData> changesWithoutRevnums = myVcs.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 {
    RepositoryState state = myVcs.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.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());
  }

}