Mercurial > hg > mercurial
view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java @ 44:1490e2981799
labeling/tagging support
author | Pavel.Sher |
---|---|
date | Fri, 05 Sep 2008 01:15:29 +0400 |
parents | ecea5b48a830 |
children | a758eaf781c7 |
line wrap: on
line source
/* * Copyright 2000-2007 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 com.intellij.execution.configurations.GeneralCommandLine; import jetbrains.buildServer.ExecResult; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.CommandUtil; import jetbrains.buildServer.serverSide.SBuildServer; import jetbrains.buildServer.serverSide.ServerPaths; import jetbrains.buildServer.vcs.*; import jetbrains.buildServer.vcs.impl.VcsRootImpl; import jetbrains.buildServer.vcs.patches.PatchBuilderImpl; import org.jmock.Mock; 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.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @Test public class MercurialVcsSupportTest extends BaseMercurialTestCase { private MercurialVcsSupport myVcs; @BeforeMethod protected void setUp() throws Exception { super.setUp(); Mock vcsManagerMock = new Mock(VcsManager.class); vcsManagerMock.stubs().method("registerVcsSupport"); Mock serverMock = new Mock(SBuildServer.class); ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); serverMock.stubs().method("getExecutor").will(myMockSupport.returnValue(executor)); File systemDir = myTempFiles.createTempDir(); ServerPaths sp = new ServerPaths(systemDir.getAbsolutePath(), systemDir.getAbsolutePath()); assertTrue(new File(sp.getCachesDir()).mkdirs()); myVcs = new MercurialVcsSupport((VcsManager)vcsManagerMock.proxy(), sp, (SBuildServer)serverMock.proxy()); } protected String getTestDataPath() { return "mercurial-tests/testData"; } public void testGetCurrentVersion() throws Exception { VcsRootImpl vcsRoot = createVcsRoot(); assertEquals(myVcs.getCurrentVersion(vcsRoot), "6:b9deb9a1c6f4"); } public void testCollectChanges() throws Exception { VcsRootImpl vcsRoot = createVcsRoot(); List<ModificationData> changes = myVcs.collectBuildChanges(vcsRoot, "0:9875b412a788", "3:9522278aa38d", new CheckoutRules("")); assertEquals(3, changes.size()); ModificationData md1 = changes.get(0); ModificationData md2 = changes.get(1); ModificationData md3 = changes.get(2); assertEquals(md1.getVersion(), "1:1d446e82d356"); assertEquals(md1.getDescription(), "new file added"); List<VcsChange> files1 = md1.getChanges(); assertEquals(1, files1.size()); assertEquals(VcsChangeInfo.Type.ADDED, files1.get(0).getType()); assertEquals(normalizePath(files1.get(0).getRelativeFileName()), "dir1/file3.txt"); assertEquals(md2.getVersion(), "2:7209b1f1d793"); assertEquals(md2.getDescription(), "file4.txt added"); List<VcsChange> files2 = md2.getChanges(); assertEquals(1, files2.size()); assertEquals(files2.get(0).getType(), VcsChangeInfo.Type.ADDED); assertEquals(normalizePath(files2.get(0).getRelativeFileName()), "dir1/file4.txt"); assertEquals(md3.getVersion(), "3:9522278aa38d"); assertEquals(md3.getDescription(), "file removed"); List<VcsChange> files3 = md3.getChanges(); assertEquals(1, files3.size()); assertEquals(files3.get(0).getType(), VcsChangeInfo.Type.REMOVED); assertEquals(normalizePath(files3.get(0).getRelativeFileName()), "dir1/file4.txt"); } public void testCollectChangesWithCheckoutRules() throws Exception { VcsRootImpl vcsRoot = createVcsRoot(); List<ModificationData> changes = myVcs.collectBuildChanges(vcsRoot, "0:9875b412a788", "3:9522278aa38d", new CheckoutRules("-:.\n+:dir1/subdir")); assertEquals(changes.size(), 0); changes = myVcs.collectBuildChanges(vcsRoot, "0:9875b412a788", "5:1d2cc6f3bc29", new CheckoutRules("-:.\n+:dir1/subdir")); assertEquals(changes.size(), 1); ModificationData md = changes.get(0); assertEquals(md.getDescription(), "modified in subdir"); } public void testBuildFullPatch() throws IOException, VcsException { setName("cleanPatch1"); VcsRootImpl vcsRoot = createVcsRoot(); final ByteArrayOutputStream output = new ByteArrayOutputStream(); final PatchBuilderImpl builder = new PatchBuilderImpl(output); myVcs.buildPatch(vcsRoot, null, "4:b06a290a363b", builder, new CheckoutRules("")); builder.close(); checkPatchResult(output.toByteArray()); } public void testBuildIncrementalPatch() throws IOException, VcsException { setName("patch1"); VcsRootImpl vcsRoot = createVcsRoot(); final ByteArrayOutputStream output = new ByteArrayOutputStream(); final PatchBuilderImpl builder = new PatchBuilderImpl(output); myVcs.buildPatch(vcsRoot, "3:9522278aa38d", "4:b06a290a363b", builder, new CheckoutRules("")); builder.close(); checkPatchResult(output.toByteArray()); } public void testBuildIncrementalPatch_FileWithSpaceInChangeSet() throws IOException, VcsException { setName("patch2"); VcsRootImpl vcsRoot = createVcsRoot(); final ByteArrayOutputStream output = new ByteArrayOutputStream(); final PatchBuilderImpl builder = new PatchBuilderImpl(output); myVcs.buildPatch(vcsRoot, "3:9522278aa38d", "6:b9deb9a1c6f4", builder, new CheckoutRules("")); builder.close(); checkPatchResult(output.toByteArray()); } public void testGetContent() throws IOException, VcsException { VcsRootImpl vcsRoot = createVcsRoot(); byte[] content = myVcs.getContent("dir1/subdir/file2.txt", vcsRoot, "4:b06a290a363b"); assertEquals(new String(content), "bbb"); content = myVcs.getContent("dir1/subdir/file2.txt", vcsRoot, "5:1d2cc6f3bc29"); assertEquals(new String(content), "modified\r\nbbb"); } public void testTestConnection() throws IOException, VcsException { VcsRootImpl vcsRoot = createVcsRoot(); System.out.println(myVcs.testConnection(vcsRoot)); vcsRoot.addProperty(Constants.REPOSITORY_PROP, "/some/non/existent/path"); try { myVcs.testConnection(vcsRoot); fail("Exception expected"); } catch (VcsException e) { } } public void testTagging() throws IOException, VcsException { VcsRootImpl vcsRoot = createVcsRoot(); cleanRepositoryAfterTest(); String actualTag = myVcs.label("new:tag", "1:1d446e82d356", vcsRoot, new CheckoutRules("")); assertEquals(actualTag, "new_tag"); // check the tag is pushed to the parent repository GeneralCommandLine cli = new GeneralCommandLine(); cli.setExePath(vcsRoot.getProperty(Constants.HG_COMMAND_PATH_PROP)); cli.setWorkDirectory(vcsRoot.getProperty(Constants.REPOSITORY_PROP)); cli.addParameter("tags"); ExecResult res = CommandUtil.runCommand(cli); assertTrue(res.getStdout().contains("new_tag")); assertTrue(res.getStdout().contains("1:1d446e82d356")); } private Object normalizePath(final String path) { return path.replace(File.separatorChar, '/'); } }