Mercurial > hg > mercurial
view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitSupportTest.java @ 888:207c4ec46d54
CommitSupport: return CommitResult instead of revision
author | Dmitry Neverov <dmitry.neverov@jetbrains.com> |
---|---|
date | Mon, 03 Nov 2014 12:53:47 +0100 |
parents | 5757f35cb22f |
children | 657882ca2b34 |
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.*; import org.jetbrains.annotations.NotNull; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.io.ByteArrayInputStream; import java.io.File; import java.io.InputStream; import java.util.List; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialSupportBuilder.mercurialSupport; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsChangeMatcher.vcsChange; 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.assertEquals; @RequiredHgVersion(min = "1.7.0") @Test(dataProviderClass = HgVersionConstraint.class, dataProvider = "installedHgVersion") public class MercurialCommitSupportTest extends BaseMercurialTestCase { private MercurialVcsSupport myVcs; private MercurialCommitSupport myCommitSupport; private File myRepo; @Override @BeforeMethod public void setUp() throws Exception { super.setUp(); myRepo = createRepo("mercurial-tests/testData/commit"); ServerPluginConfig pluginConfig = new ServerPluginConfigBuilder() .cachesDir(myTempFiles.createTempDir()) .build(); MercurialSupportBuilder mercurialBuilder = mercurialSupport().withConfig(pluginConfig); myVcs = mercurialBuilder.build(); myCommitSupport = new MercurialCommitSupport(myVcs, myVcs.getMirrorManager(), pluginConfig, mercurialBuilder.getHgRootFactory(), mercurialBuilder.getHgRepoFactory()); } public void test_commit(@NotNull HgVersion _) throws Exception { VcsRoot root = vcsRoot().withUrl(myRepo).build(); RepositoryStateData beforeCommit = myVcs.getCollectChangesPolicy().getCurrentState(root); String description = "Test commit support"; String author = "Joe Doe <joe@some.org>"; CommitPatchBuilder patchBuilder = myCommitSupport.getCommitPatchBuilder(root); patchBuilder.deleteDirectory("dir"); patchBuilder.deleteFile("x"); patchBuilder.createFile("a/b/c", stream("test")); patchBuilder.renameFile("y", "z", stream("rename")); CommitResult result = patchBuilder.commit(author, description); RepositoryStateData afterCommit = myVcs.getCollectChangesPolicy().getCurrentState(root); assertEquals(result.getCreatedRevision(), afterCommit.getBranchRevisions().get(afterCommit.getDefaultBranchName())); List<ModificationData> changes = myVcs.getCollectChangesPolicy().collectChanges(root, beforeCommit, afterCommit, CheckoutRules.DEFAULT); ModificationData m = changes.get(0); assertEquals(description, m.getDescription()); assertEquals(author, m.getUserName()); assertThat(m.getChanges(), hasItem(vcsChange().file("x").type(VcsChangeInfo.Type.REMOVED))); assertThat(m.getChanges(), hasItem(vcsChange().file("dir/x").type(VcsChangeInfo.Type.REMOVED))); assertThat(m.getChanges(), hasItem(vcsChange().file("a/b/c").type(VcsChangeInfo.Type.ADDED))); assertThat(m.getChanges(), hasItem(vcsChange().file("y").type(VcsChangeInfo.Type.REMOVED))); assertThat(m.getChanges(), hasItem(vcsChange().file("z").type(VcsChangeInfo.Type.ADDED))); } @NotNull private InputStream stream(@NotNull String content) { return new ByteArrayInputStream(content.getBytes()); } }