changeset 638:7c017b6aa438

Tests for merge support
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Mon, 19 Aug 2013 16:27:34 +0400
parents 49a03af60439
children 817a15a54de8
files mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialSupportBuilder.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MergeSupportTest.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ModificationDataMatcher.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java mercurial-tests/src/testng.xml mercurial-tests/testData/merge/no.subrepos/hg/00changelog.i mercurial-tests/testData/merge/no.subrepos/hg/bookmarks mercurial-tests/testData/merge/no.subrepos/hg/branch mercurial-tests/testData/merge/no.subrepos/hg/cache/branchheads-served mercurial-tests/testData/merge/no.subrepos/hg/cache/tags mercurial-tests/testData/merge/no.subrepos/hg/dirstate mercurial-tests/testData/merge/no.subrepos/hg/last-message.txt mercurial-tests/testData/merge/no.subrepos/hg/requires mercurial-tests/testData/merge/no.subrepos/hg/store/00changelog.i mercurial-tests/testData/merge/no.subrepos/hg/store/00manifest.i mercurial-tests/testData/merge/no.subrepos/hg/store/data/a.i mercurial-tests/testData/merge/no.subrepos/hg/store/data/b/c.i mercurial-tests/testData/merge/no.subrepos/hg/store/data/b/d.i mercurial-tests/testData/merge/no.subrepos/hg/store/fncache mercurial-tests/testData/merge/no.subrepos/hg/store/phaseroots mercurial-tests/testData/merge/no.subrepos/hg/store/undo mercurial-tests/testData/merge/no.subrepos/hg/store/undo.phaseroots mercurial-tests/testData/merge/no.subrepos/hg/undo.bookmarks mercurial-tests/testData/merge/no.subrepos/hg/undo.branch mercurial-tests/testData/merge/no.subrepos/hg/undo.desc mercurial-tests/testData/merge/no.subrepos/hg/undo.dirstate
diffstat 24 files changed, 147 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialSupportBuilder.java	Mon Aug 19 15:07:42 2013 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialSupportBuilder.java	Mon Aug 19 16:27:34 2013 +0400
@@ -56,4 +56,8 @@
     myRepoFactory = repoFactory;
     return this;
   }
+
+  public HgVcsRootFactory getHgRootFactory() {
+    return myHgRootFactory;
+  }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MergeSupportTest.java	Mon Aug 19 16:27:34 2013 +0400
@@ -0,0 +1,105 @@
+package jetbrains.buildServer.buildTriggers.vcs.mercurial;
+
+import jetbrains.buildServer.vcs.*;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+import static java.util.Arrays.asList;
+import static jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialSupportBuilder.mercurialSupport;
+import static jetbrains.buildServer.buildTriggers.vcs.mercurial.ModificationDataMatcher.modificationData;
+import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository;
+import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasItem;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
+
+@Test
+public class MergeSupportTest extends BaseMercurialTestCase {
+
+  private File myRemoteRepo;
+  private MercurialVcsSupport myVcs;
+  private MercurialMergeSupport myMergeSupport;
+
+  @Override
+  @BeforeMethod
+  public void setUp() throws Exception {
+    super.setUp();
+    ServerPluginConfig pluginConfig = new ServerPluginConfigBuilder()
+            .cachesDir(myTempFiles.createTempDir())
+            .build();
+    MercurialSupportBuilder mercurialBuilder = mercurialSupport().withConfig(pluginConfig);
+    myVcs = mercurialBuilder.build();
+    myMergeSupport = new MercurialMergeSupport(myVcs, mercurialBuilder.getHgRootFactory());
+    myRemoteRepo = myTempFiles.createTempDir();
+    copyRepository(new File("mercurial-tests/testData/merge/no.subrepos"), myRemoteRepo);
+  }
+
+
+  public void should_return_succesful_result_when_merge_succeeds() throws Exception {
+    VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build();
+    MergeResult mergeResult = myMergeSupport.merge(root, "2742914d19b2", "default", "merge topic1 into default", new MergeOptions());
+    assertTrue(mergeResult.isSuccess());
+  }
+
+
+  public void result_of_succesful_merge_should_appear_in_remote_repository() throws Exception {
+    final String mergeDestinationBranch = "default";
+    final String mergeCommitMessage = "merge topic1 into default";
+
+    VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build();
+    RepositoryStateData stateBeforeMerge = myVcs.getCollectChangesPolicy().getCurrentState(root);
+    String dstBranchRevBefore = stateBeforeMerge.getBranchRevisions().get(mergeDestinationBranch);
+
+    myMergeSupport.merge(root, "2742914d19b2", mergeDestinationBranch, mergeCommitMessage, new MergeOptions());
+    RepositoryStateData stateAfterMerge = myVcs.getCollectChangesPolicy().getCurrentState(root);
+    String dstBranchRevAfter = stateAfterMerge.getBranchRevisions().get(mergeDestinationBranch);
+
+    assertFalse("Revision of the destination branch is not changed", dstBranchRevAfter.equals(dstBranchRevBefore));
+
+    List<ModificationData> changes = myVcs.getCollectChangesPolicy().collectChanges(root, stateBeforeMerge, stateAfterMerge, CheckoutRules.DEFAULT);
+    assertThat(changes, hasItem(modificationData().withDescription(mergeCommitMessage)));
+  }
+
+
+  public void should_return_unsuccesful_result_when_merge_fails() throws Exception {
+    VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build();
+    MergeResult mergeResult = myMergeSupport.merge(root, "79d836707416", "default", "merge topic2 into default", new MergeOptions());
+    assertFalse(mergeResult.isSuccess());
+    assertThat(mergeResult.getConflicts(), hasItem("b/c"));
+  }
+
+
+  public void result_of_failed_merge_should_not_appear_in_remote_repository() throws Exception {
+    final String mergeDestinationBranch = "default";
+
+    VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build();
+    RepositoryStateData stateBeforeMerge = myVcs.getCollectChangesPolicy().getCurrentState(root);
+    String dstBranchRevBefore = stateBeforeMerge.getBranchRevisions().get(mergeDestinationBranch);
+
+    myMergeSupport.merge(root, "79d836707416", mergeDestinationBranch, "merge topic2 into default", new MergeOptions());
+    RepositoryStateData stateAfterMerge = myVcs.getCollectChangesPolicy().getCurrentState(root);
+    String dstBranchRevAfter = stateAfterMerge.getBranchRevisions().get(mergeDestinationBranch);
+
+    assertTrue("Revision of the destination branch changed after failed merge", dstBranchRevAfter.equals(dstBranchRevBefore));
+  }
+
+
+  public void try_merge_returns_correct_result_for_every_task() throws Exception {
+    VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build();
+
+    final MergeTask topic1ToDefault = new MergeTask("2742914d19b2", "09dd527b77ec");
+    final MergeTask topic2ToDefault = new MergeTask("79d836707416", "09dd527b77ec");
+    final MergeTask topic1ToTopic2 = new MergeTask("2742914d19b2", "79d836707416");
+    Map<MergeTask, MergeResult> results = myMergeSupport.tryMerge(root, asList(topic1ToDefault, topic2ToDefault, topic1ToTopic2), new MergeOptions());
+
+    assertTrue(results.get(topic1ToDefault).isSuccess());
+    assertFalse(results.get(topic2ToDefault).isSuccess());
+    assertThat(results.get(topic2ToDefault).getConflicts(), hasItem("b/c"));
+    assertTrue(results.get(topic1ToTopic2).isSuccess());
+  }
+}
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ModificationDataMatcher.java	Mon Aug 19 15:07:42 2013 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ModificationDataMatcher.java	Mon Aug 19 16:27:34 2013 +0400
@@ -11,6 +11,7 @@
 public class ModificationDataMatcher extends TypeSafeMatcher<ModificationData> {
 
   private String myVersion;
+  private String myDescription;
   private Map<String, String> myVcsRootProperties = new HashMap<String, String>();
   private Map<String, String> myAttributes = new HashMap<String, String>();
 
@@ -18,6 +19,8 @@
   public boolean matchesSafely(ModificationData m) {
     if (myVersion != null && !myVersion.equals(m.getDisplayVersion()))
       return false;
+    if (myDescription != null && !myDescription.equals(m.getDescription()))
+      return false;
     if (!myVcsRootProperties.isEmpty() && !myVcsRootProperties.equals(m.getVcsRootObject().getProperties()))
       return false;
     if (!myAttributes.isEmpty() && !containsAllAttributes(m.getAttributes()))
@@ -29,6 +32,8 @@
     description.appendText("modification");
     if (myVersion != null)
       description.appendText(" with version ").appendValue(myVersion);
+    if (myDescription != null)
+      description.appendText(" with description ").appendValue(myDescription);
     if (!myVcsRootProperties.isEmpty())
       description.appendText(" with vcs root properties ").appendValue(myVcsRootProperties);
     if (!myAttributes.isEmpty())
@@ -44,6 +49,11 @@
     return this;
   }
 
+  public ModificationDataMatcher withDescription(@NotNull String description) {
+    myDescription = description;
+    return this;
+  }
+
   public ModificationDataMatcher withVcsRootProperties(@NotNull Map<String, String> properties) {
     myVcsRootProperties.putAll(properties);
     return this;
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java	Mon Aug 19 15:07:42 2013 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java	Mon Aug 19 16:27:34 2013 +0400
@@ -74,6 +74,12 @@
   }
 
 
+  public VcsRootBuilder withUrl(@NotNull File repository) {
+    myRepository = repository.getAbsolutePath();
+    return this;
+  }
+
+
   public VcsRootBuilder withUserName(@NotNull String username) {
     myUsername = username;
     return this;
--- a/mercurial-tests/src/testng.xml	Mon Aug 19 15:07:42 2013 +0400
+++ b/mercurial-tests/src/testng.xml	Mon Aug 19 16:27:34 2013 +0400
@@ -32,6 +32,7 @@
       <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialXmlLogParserTest"/>
       <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.HgVcsRootFactoryTest"/>
       <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.SubRepoTest"/>
+      <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.MergeSupportTest"/>
     </classes>
   </test>
 </suite>
Binary file mercurial-tests/testData/merge/no.subrepos/hg/00changelog.i has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/merge/no.subrepos/hg/branch	Mon Aug 19 16:27:34 2013 +0400
@@ -0,0 +1,1 @@
+topic2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/merge/no.subrepos/hg/cache/branchheads-served	Mon Aug 19 16:27:34 2013 +0400
@@ -0,0 +1,4 @@
+79d8367074167bba5a1820ad757f4052b5777d20 4
+09dd527b77ec6e1ab9396bc16eb3b5cd09c55d11 default
+2742914d19b233227f753c51110959b407eeff6e topic1
+79d8367074167bba5a1820ad757f4052b5777d20 topic2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/merge/no.subrepos/hg/cache/tags	Mon Aug 19 16:27:34 2013 +0400
@@ -0,0 +1,3 @@
+3 2742914d19b233227f753c51110959b407eeff6e
+2 09dd527b77ec6e1ab9396bc16eb3b5cd09c55d11
+
Binary file mercurial-tests/testData/merge/no.subrepos/hg/dirstate has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/merge/no.subrepos/hg/last-message.txt	Mon Aug 19 16:27:34 2013 +0400
@@ -0,0 +1,1 @@
+create b/c conflicting with default
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/merge/no.subrepos/hg/requires	Mon Aug 19 16:27:34 2013 +0400
@@ -0,0 +1,4 @@
+dotencode
+fncache
+revlogv1
+store
Binary file mercurial-tests/testData/merge/no.subrepos/hg/store/00changelog.i has changed
Binary file mercurial-tests/testData/merge/no.subrepos/hg/store/00manifest.i has changed
Binary file mercurial-tests/testData/merge/no.subrepos/hg/store/data/a.i has changed
Binary file mercurial-tests/testData/merge/no.subrepos/hg/store/data/b/c.i has changed
Binary file mercurial-tests/testData/merge/no.subrepos/hg/store/data/b/d.i has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/merge/no.subrepos/hg/store/fncache	Mon Aug 19 16:27:34 2013 +0400
@@ -0,0 +1,3 @@
+data/b/c.i
+data/b/d.i
+data/a.i
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/merge/no.subrepos/hg/store/phaseroots	Mon Aug 19 16:27:34 2013 +0400
@@ -0,0 +1,1 @@
+1 7e3988f0f412b846df355cb77cf5b863dd42fb5f
Binary file mercurial-tests/testData/merge/no.subrepos/hg/store/undo has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/merge/no.subrepos/hg/store/undo.phaseroots	Mon Aug 19 16:27:34 2013 +0400
@@ -0,0 +1,1 @@
+1 7e3988f0f412b846df355cb77cf5b863dd42fb5f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/merge/no.subrepos/hg/undo.branch	Mon Aug 19 16:27:34 2013 +0400
@@ -0,0 +1,1 @@
+topic2
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/testData/merge/no.subrepos/hg/undo.desc	Mon Aug 19 16:27:34 2013 +0400
@@ -0,0 +1,2 @@
+4
+commit
Binary file mercurial-tests/testData/merge/no.subrepos/hg/undo.dirstate has changed