Mercurial > hg > mercurial
view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CommitsInfoBuilderSupportTest.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 | 7fe4a31c5a76 |
children | cccd4e722ca4 |
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.TestLogger; import jetbrains.buildServer.vcs.*; import jetbrains.vcs.api.CommitInfo; 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.io.IOException; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialSupportBuilder.mercurialSupport; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot; /** * Created 30.09.13 13:07 * * @author Eugene Petrenko (eugene.petrenko@jetbrains.com) */ @RequiredHgVersion(min = "2.0.0") //support subrepos only for hg with revsets @Test(dataProviderClass = HgVersionConstraint.class, dataProvider = "installedHgVersion") public class CommitsInfoBuilderSupportTest extends BaseMercurialTestCase { private File myRemoteRepo; private MercurialVcsSupport myVcs; private MercurialCommitsInfoBuilderSupport mySupport; @Override @BeforeMethod public void setUp() throws Exception { super.setUp(); ServerPluginConfig pluginConfig = new ServerPluginConfigBuilder() // .hgPath("hg") .cachesDir(myTempFiles.createTempDir()) .build(); MercurialSupportBuilder mercurialBuilder = mercurialSupport().withConfig(pluginConfig); myVcs = mercurialBuilder.build(); mySupport = new MercurialCommitsInfoBuilderSupport(myVcs, mercurialBuilder.getHgRootFactory()); myRemoteRepo = myTempFiles.createTempDir(); copyRepository(new File("mercurial-tests/testData/rep2"), myRemoteRepo); } public void simpleTest(@NotNull HgVersion _) throws IOException, VcsException { TestLogger.enableMainAndVCSLoggerDebug(); VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build(); final List<CommitInfo> commitInfos = new ArrayList<CommitInfo>(); mySupport.collectCommits(root, CheckoutRules.DEFAULT, new CommitsInfoBuilder.CommitsConsumer() { public void consumeCommit(@NotNull CommitInfo commit) { commitInfos.add(commit); } }); Assert.assertFalse(commitInfos.isEmpty()); for (CommitInfo commitInfo : commitInfos) { System.out.println(commitInfo); } final Set<String> branches = new TreeSet<String>(); final Set<String> tags = new TreeSet<String>(); final Set<String> commits = new TreeSet<String>(); final Set<String> parents = new TreeSet<String>(); for (CommitInfo commitInfo : commitInfos) { branches.addAll(commitInfo.getBranches()); tags.addAll(commitInfo.getTags()); //commit should be returned once Assert.assertTrue(commits.add(commitInfo.getVersion())); Assert.assertNotNull(commitInfo.getCommitAuthor()); parents.addAll(commitInfo.getParentRevisions()); } Assert.assertEquals(branches, new TreeSet<String>(Arrays.asList("default", "personal-branch", "test", "topic", "<TEST> Branch with exitics)(*&^%$#@!", "NULL"))); Assert.assertEquals(tags, new TreeSet<String>(Arrays.asList("t1"))); //check all parent commits are included into the set Assert.assertTrue(commits.containsAll(parents), "Unknown commits: " + new TreeSet<String>(parents){{removeAll(commits);}}); final String v = "4780519e01aa"; ///30 Assert.assertFalse(parents.contains(v)); } public void should_not_have_parse_errors(@NotNull HgVersion _) throws IOException, VcsException { TestLogger.enableMainAndVCSLoggerDebug(); VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build(); final List<CommitInfo> commitInfos = new ArrayList<CommitInfo>(); mySupport.collectCommits(root, CheckoutRules.DEFAULT, new CommitsInfoBuilder.CommitsConsumer() { public void consumeCommit(@NotNull CommitInfo commit) { commitInfos.add(commit); } }); Assert.assertFalse(commitInfos.isEmpty()); for (CommitInfo commitInfo : commitInfos) { System.out.println(commitInfo); } } public void should_return_subrepos_graphcommits(@NotNull HgVersion _) throws Exception { myRemoteRepo = myTempFiles.createTempDir(); copyRepository(new File("mercurial-tests/testData/subrepos/r1"), myRemoteRepo); VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build(); final AtomicBoolean hasSubRepo = new AtomicBoolean(false); final long start = System.currentTimeMillis(); mySupport.collectCommits(root, CheckoutRules.DEFAULT, new CommitsInfoBuilder.CommitsConsumer() { public void consumeCommit(@NotNull CommitInfo commit) { if (commit.getMountPoints().size() > 0) hasSubRepo.set(true); } }); final long actual = System.currentTimeMillis() - start; System.out.println("computed in " + actual + " ms"); Assert.assertTrue(hasSubRepo.get(), "Must have sub-repos"); } @Test(enabled = false) public void should_return_graphcommits(@NotNull HgVersion _) throws Exception { VcsRoot root = vcsRoot().withLocalRepository(new File("F:\\Work\\ReSharper")).build(); final AtomicBoolean hasSubRepo = new AtomicBoolean(false); final long start = System.currentTimeMillis(); mySupport.collectCommits(root, CheckoutRules.DEFAULT, new CommitsInfoBuilder.CommitsConsumer() { public void consumeCommit(@NotNull CommitInfo commit) { if (commit.getMountPoints().size() > 0) hasSubRepo.set(true); } }); final long actual = System.currentTimeMillis() - start; System.out.println("computed in " + actual + " ms"); Assert.assertTrue(hasSubRepo.get(), "Must have sub-repos"); } }