view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialModificationInfoBuilderTest.java @ 909:b2ecc56f456c Hajipur-9.0.x

Create branch Hajipur-9.0.x
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Tue, 09 Dec 2014 12:20:05 +0100
parents 31a1aca3305c
children 31ac1d822fd7
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.vcs.ChangesConsumer;
import jetbrains.buildServer.vcs.CheckoutRules;
import jetbrains.buildServer.vcs.VcsRoot;
import jetbrains.vcs.api.ChangeData;
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.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialSupportBuilder.mercurialSupport;
import static jetbrains.buildServer.buildTriggers.vcs.mercurial.ServerPluginConfigBuilder.serverPluginConfig;
import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot;
import static org.testng.AssertJUnit.assertEquals;

@RequiredHgVersion(min = "1.7.0")
@Test(dataProviderClass = HgVersionConstraint.class, dataProvider = "installedHgVersion")
public class MercurialModificationInfoBuilderTest extends BaseMercurialTestCase {

  private File myRemoteRepository;
  private MercurialModificationInfoBuilder myModInfoBuilder;
  private MercurialVcsSupport myVcs;

  @BeforeMethod
  public void setUp() throws Exception {
    super.setUp();
    ServerPluginConfig config = serverPluginConfig()
            .cachesDir(myTempFiles.createTempDir())
            .hgPath(Util.getHgPath())
            .build();

    myRemoteRepository = myTempFiles.createTempDir();
    Util.copyRepository(new File("mercurial-tests/testData/rep2"), myRemoteRepository);
    MercurialSupportBuilder hgBuilder = mercurialSupport().withConfig(config);
    MercurialVcsSupport vcs = hgBuilder.build();
    myVcs = vcs;
    myModInfoBuilder = new MercurialModificationInfoBuilder(vcs, hgBuilder.getHgRootFactory(), hgBuilder.getHgRepoFactory(), hgBuilder.getHgPathProvider());
  }


  public void should_return_commits_for_every_revision_in_state(HgVersion _) throws Exception {
    VcsRoot root = vcsRoot().withUrl(myRemoteRepository.getAbsolutePath()).build();
    final List<ChangeData> changes = new ArrayList<ChangeData>();
    myVcs.syncRepository(root);
    myModInfoBuilder.fetchChangesInfo(root, CheckoutRules.DEFAULT, Arrays.asList("505c5b9d01e6", "9ec402c74298"), new ChangesConsumer() {
      public void consumeChange(@NotNull ChangeData change) {
        changes.add(change);
      }
    });

    for (ChangeData change : changes) {
      if (change.getVersion().equals("505c5b9d01e6")) {
        Assert.assertEquals(change.getParentRevisions(), Arrays.asList("78e67807f916"));
      } else if (change.getVersion().equals("9ec402c74298")) {
        Assert.assertEquals(change.getParentRevisions(), Arrays.asList("96b78d73081d"));
      } else {
        Assert.fail("Unexpected revision: " + change.getVersion());
      }
    }

    assertEquals(2, changes.size());
  }


  public void should_return_commits_for_every_revision_in_state_parent_child(HgVersion _) throws Exception {
    VcsRoot root = vcsRoot().withUrl(myRemoteRepository.getAbsolutePath()).build();
    final List<ChangeData> changes = new ArrayList<ChangeData>();
    myVcs.syncRepository(root);
    myModInfoBuilder.fetchChangesInfo(root, CheckoutRules.DEFAULT, Arrays.asList("505c5b9d01e6", "9ec402c74298", "96b78d73081d"), new ChangesConsumer() {
      public void consumeChange(@NotNull ChangeData change) {
        changes.add(change);
      }
    });

    for (ChangeData change : changes) {
      if (change.getVersion().equals("505c5b9d01e6")) {
        Assert.assertEquals(change.getParentRevisions(), Arrays.asList("78e67807f916"));
      } else if (change.getVersion().equals("9ec402c74298")) {
        Assert.assertEquals(change.getParentRevisions(), Arrays.asList("96b78d73081d"));
      } else if (change.getVersion().equals("96b78d73081d")) {
        Assert.assertEquals(change.getParentRevisions(), Arrays.asList("dec47d2d49bf"));
      } else {
        Assert.fail("Unexpected revision: " + change.getVersion());
      }
    }

    assertEquals(3, changes.size());
  }

  public void should_return_commits_for_every_revision_in_state_parent_gap_child(HgVersion _) throws Exception {
    VcsRoot root = vcsRoot().withUrl(myRemoteRepository.getAbsolutePath()).build();
    final List<ChangeData> changes = new ArrayList<ChangeData>();
    myVcs.syncRepository(root);
    myModInfoBuilder.fetchChangesInfo(root, CheckoutRules.DEFAULT, Arrays.asList("505c5b9d01e6", "9ec402c74298", "dec47d2d49bf"), new ChangesConsumer() {
      public void consumeChange(@NotNull ChangeData change) {
        changes.add(change);
      }
    });


    for (ChangeData change : changes) {
      if (change.getVersion().equals("505c5b9d01e6")) {
        Assert.assertEquals(change.getParentRevisions(), Arrays.asList("78e67807f916"));
      } else if (change.getVersion().equals("9ec402c74298")) {
        Assert.assertEquals(change.getParentRevisions(), Arrays.asList("96b78d73081d"));
      } else if (change.getVersion().equals("dec47d2d49bf")) {
        Assert.assertEquals(change.getParentRevisions(), Arrays.asList("1e620196c4b6"));
      } else {
        Assert.fail("Unexpected revision: " + change.getVersion());
      }
    }

    assertEquals(3, changes.size());
  }
}