Mercurial > hg > mercurial
changeset 443:d0f80762461a
Test refactoring: get rid of LocalRepositoryUtil
line wrap: on
line diff
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentMirrorCleanerTest.java Thu May 31 18:04:23 2012 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentMirrorCleanerTest.java Tue Jun 19 15:17:11 2012 +0400 @@ -17,7 +17,7 @@ import java.util.HashMap; import static java.util.Arrays.asList; -import static jetbrains.buildServer.buildTriggers.vcs.mercurial.LocalRepositoryUtil.copyRepository; +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot; /**
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java Thu May 31 18:04:23 2012 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java Tue Jun 19 15:17:11 2012 +0400 @@ -19,6 +19,7 @@ import jetbrains.buildServer.agent.BuildAgentConfiguration; import jetbrains.buildServer.agent.BuildProgressLogger; import jetbrains.buildServer.util.FileUtil; +import jetbrains.buildServer.util.TestFor; import jetbrains.buildServer.vcs.CheckoutRules; import jetbrains.buildServer.vcs.IncludeRule; import jetbrains.buildServer.vcs.VcsException; @@ -37,6 +38,8 @@ import java.util.Map; import java.util.concurrent.*; +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository; + /** * @author Pavel.Sher * Date: 30.07.2008 @@ -82,7 +85,7 @@ public void should_work_when_path_to_hg_is_property() throws Exception { VcsRootImpl root = new VcsRootBuilder() - .withUrl(LocalRepositoryUtil.prepareRepository(simpleRepo()).getAbsolutePath()) + .withUrl(copyRepository(myTempFiles, simpleRepo()).getAbsolutePath()) .withHgPath(HG_PATH_REFERENCE).build(); testUpdate(root, "4:b06a290a363b", "cleanPatch1/after", new IncludeRule(".", ".", null)); } @@ -253,10 +256,10 @@ assertTrue(hgrcContent.contains("default = " + root.getProperty(Constants.REPOSITORY_PROP))); } - //TW-19703 + @TestFor(issues = "TW-19703") public void should_work_when_repository_is_locked() throws Exception{ VcsRootImpl root = new VcsRootBuilder() - .withUrl(LocalRepositoryUtil.prepareRepository(simpleRepo()).getAbsolutePath()) + .withUrl(copyRepository(myTempFiles, simpleRepo()).getAbsolutePath()) .withHgPath(HG_PATH_REFERENCE).build(); File workingDir = doUpdate(root, "4:b06a290a363b");
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseMercurialTestCase.java Thu May 31 18:04:23 2012 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseMercurialTestCase.java Tue Jun 19 15:17:11 2012 +0400 @@ -25,6 +25,8 @@ import java.io.File; import java.io.IOException; +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository; + /** * @author Pavel.Sher * Date: 31.07.2008 @@ -45,19 +47,15 @@ } protected VcsRootImpl createVcsRoot(@NotNull String repPath) throws IOException { - File repository = LocalRepositoryUtil.prepareRepository(repPath); + File repository = copyRepository(myTempFiles, repPath); return new VcsRootBuilder().withUrl(repository.getAbsolutePath()).build(); } protected VcsRootImpl createVcsRoot(@NotNull String repPath, @NotNull String branchName) throws IOException { - File repository = LocalRepositoryUtil.prepareRepository(repPath); + File repository = copyRepository(myTempFiles, repPath); return new VcsRootBuilder().withUrl(repository.getAbsolutePath()).withBranch(branchName).build(); } - protected void cleanRepositoryAfterTest(@NotNull String repPath) { - LocalRepositoryUtil.forgetRepository(repPath); - } - protected String simpleRepo() { return new File("mercurial-tests/testData/rep1").getAbsolutePath(); }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/DagFeaturesTest.java Thu May 31 18:04:23 2012 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/DagFeaturesTest.java Tue Jun 19 15:17:11 2012 +0400 @@ -4,6 +4,7 @@ import jetbrains.buildServer.TempFiles; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.ChangeSetRevision; import jetbrains.buildServer.log.Log4jFactory; +import jetbrains.buildServer.util.TestFor; import jetbrains.buildServer.vcs.CheckoutRules; import jetbrains.buildServer.vcs.ModificationData; import jetbrains.buildServer.vcs.impl.VcsRootImpl; @@ -15,6 +16,7 @@ import java.io.File; import java.util.List; +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertTrue; @@ -42,7 +44,7 @@ File original = new File("mercurial-tests/testData/rep2"); File copy = new File(myTempFiles.createTempDir(), "rep2"); - LocalRepositoryUtil.copyRepository(original, copy); + copyRepository(original, copy); myRepository = copy.getAbsolutePath(); } @@ -51,7 +53,7 @@ } - //TW-17882 + @TestFor(issues = "TW-17882") public void should_detect_changes_from_named_branches() throws Exception { VcsRootImpl root = new VcsRootBuilder().withUrl(myRepository).build();
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ListFilesSupportTest.java Thu May 31 18:04:23 2012 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ListFilesSupportTest.java Tue Jun 19 15:17:11 2012 +0400 @@ -14,7 +14,7 @@ import java.io.File; import java.util.Collection; -import static jetbrains.buildServer.buildTriggers.vcs.mercurial.LocalRepositoryUtil.copyRepository; +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot; import static org.testng.AssertJUnit.assertNotNull; import static org.testng.AssertJUnit.assertTrue;
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/LocalRepositoryUtil.java Thu May 31 18:04:23 2012 +0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* - * Copyright 2000-2011 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.TempFiles; -import jetbrains.buildServer.util.FileUtil; -import org.jetbrains.annotations.NotNull; - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -/** - * @author Pavel.Sher - * Date: 14.07.2008 - */ -public class LocalRepositoryUtil { - private final static TempFiles myTempFiles = new TempFiles(); - private final static Map<String, File> myRepositories = new HashMap<String, File>(); - static { - Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { - public void run() { - myTempFiles.cleanup(); - } - })); - } - - public static File prepareRepository(@NotNull String repPath) throws IOException { - File repository = myRepositories.get(repPath); - if (repository != null) return repository; - final File tempDir = myTempFiles.createTempDir(); - copyRepository(new File(repPath), tempDir); - myRepositories.put(repPath, tempDir); - return tempDir; - } - - public static void forgetRepository(@NotNull String repPath) { - myRepositories.remove(repPath); - } - - - public static void copyRepository(File src, File dst) throws IOException { - FileUtil.copyDir(src, dst); - if (new File(dst, "hg").isDirectory()) - FileUtil.rename(new File(dst, "hg"), new File(dst, ".hg")); - } -}
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Thu May 31 18:04:23 2012 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Tue Jun 19 15:17:11 2012 +0400 @@ -33,6 +33,7 @@ import java.util.*; import static com.intellij.openapi.util.io.FileUtil.*; +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot; @Test @@ -249,7 +250,6 @@ public void test_tag() throws IOException, VcsException { VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); - cleanRepositoryAfterTest(simpleRepo()); String actualTag = myVcs.label("new:tag", "1:1d446e82d356", vcsRoot, new CheckoutRules("")); assertEquals(actualTag, "new_tag"); @@ -266,7 +266,6 @@ public void test_tag_in_branch() throws IOException, VcsException { VcsRootImpl vcsRoot = createVcsRoot(simpleRepo(), "test_branch"); - cleanRepositoryAfterTest(simpleRepo()); String actualTag = myVcs.label("branch_tag", "7:376dcf05cd2a", vcsRoot, new CheckoutRules("")); assertEquals(actualTag, "branch_tag"); @@ -284,9 +283,8 @@ public void test_tag_with_specified_username() throws IOException, VcsException { final String customUserForTag = "John Doe <john@some.org>"; - File repository = LocalRepositoryUtil.prepareRepository(simpleRepo()); + File repository = copyRepository(myTempFiles, simpleRepo()); VcsRoot root = vcsRoot().withUrl(repository.getAbsolutePath()).withUserForTag(customUserForTag).build(); - cleanRepositoryAfterTest(simpleRepo()); myVcs.label("tag_by_specified_user", "10:9c6a6b4aede0", root, CheckoutRules.DEFAULT); @@ -299,7 +297,6 @@ public void labeling_should_not_populate_files_in_local_mirror() throws Exception { VcsRootImpl root = createVcsRoot(simpleRepo()); - cleanRepositoryAfterTest(simpleRepo()); myVcs.getCurrentVersion(root); File mirror = myVcs.getMirrorManager().getMirrorDir(root.getProperty(Constants.REPOSITORY_PROP)); File[] files = mirror.listFiles(); @@ -530,7 +527,6 @@ public void labeling_should_not_change_vcs_root_settings() throws Exception { VcsRootImpl root = createVcsRoot(simpleRepo(), "test_branch"); - cleanRepositoryAfterTest(simpleRepo()); assertNull(root.getProperty(Constants.SERVER_CLONE_PATH_PROP)); myVcs.label("branch_tag", "7:376dcf05cd2a", root, CheckoutRules.DEFAULT); assertNull(root.getProperty(Constants.SERVER_CLONE_PATH_PROP));
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/UnrelatedResitoriesTest.java Thu May 31 18:04:23 2012 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/UnrelatedResitoriesTest.java Tue Jun 19 15:17:11 2012 +0400 @@ -84,7 +84,7 @@ } private void copyRepository(@NotNull final File src) throws IOException { - LocalRepositoryUtil.copyRepository(src, myRepositoryLocation); + Util.copyRepository(src, myRepositoryLocation); } private MercurialVcsSupport createVcs() throws IOException {
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Util.java Thu May 31 18:04:23 2012 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Util.java Tue Jun 19 15:17:11 2012 +0400 @@ -1,8 +1,10 @@ package jetbrains.buildServer.buildTriggers.vcs.mercurial; +import jetbrains.buildServer.TempFiles; import jetbrains.buildServer.serverSide.BuildServerListener; import jetbrains.buildServer.serverSide.SBuildServer; import jetbrains.buildServer.util.EventDispatcher; +import jetbrains.buildServer.util.FileUtil; import jetbrains.buildServer.util.cache.ResetCacheRegister; import jetbrains.buildServer.vcs.VcsManager; import org.jetbrains.annotations.NotNull; @@ -51,4 +53,17 @@ return new MercurialVcsSupport(vcsManager, server, dispatcher, new ResetCacheRegister(), config, hgPathProvider, repoFactory, mirrorManager, hgVcsRootFactory, testConnection); } + + + public static File copyRepository(@NotNull TempFiles tempFiles, @NotNull String repPath) throws IOException { + File tempDir = tempFiles.createTempDir(); + copyRepository(new File(repPath), tempDir); + return tempDir; + } + + public static void copyRepository(@NotNull File src, @NotNull File dst) throws IOException { + FileUtil.copyDir(src, dst); + if (new File(dst, "hg").isDirectory()) + FileUtil.rename(new File(dst, "hg"), new File(dst, ".hg")); + } }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommandTestCase.java Thu May 31 18:04:23 2012 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommandTestCase.java Tue Jun 19 15:17:11 2012 +0400 @@ -28,6 +28,8 @@ import java.util.HashMap; import java.util.Map; +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository; + public class BaseCommandTestCase extends BaseTestCase { private String myRepository; private String myUsername; @@ -55,8 +57,10 @@ vcsRootProps.put(Constants.REPOSITORY_PROP, myRepository); + TempFiles tempFiles = new TempFiles(); + if (myCloneRequired) { - File repository = LocalRepositoryUtil.prepareRepository(new File(myRepository).getAbsolutePath()); + File repository = copyRepository(tempFiles, new File(myRepository).getAbsolutePath()); vcsRootProps.put(Constants.REPOSITORY_PROP, repository.getAbsolutePath()); } @@ -68,9 +72,8 @@ vcsRootProps.put(Constants.PASSWORD, myPassword); } - TempFiles tf = new TempFiles(); VcsRoot vcsRoot = new VcsRootImpl(1, vcsRootProps); - ServerPluginConfig config = new ServerPluginConfigBuilder().cachesDir(tf.createTempDir()).build(); + ServerPluginConfig config = new ServerPluginConfigBuilder().cachesDir(tempFiles.createTempDir()).build(); MirrorManager mirrorManager = new MirrorManagerImpl(config); ServerHgPathProvider hgPathProvider = new ServerHgPathProvider(config); HgVcsRoot root = new HgVcsRoot(vcsRoot); @@ -83,7 +86,7 @@ return executor.execute(root, hgPathProvider, workingDir); } finally { - tf.cleanup(); + tempFiles.cleanup(); } }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CloneCommandTest.java Thu May 31 18:04:23 2012 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CloneCommandTest.java Tue Jun 19 15:17:11 2012 +0400 @@ -12,6 +12,8 @@ import java.io.File; import java.io.IOException; +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository; + /** * @author dmitry.neverov */ @@ -35,7 +37,7 @@ public void clone_should_be_made_to_its_destination_dir() throws IOException, VcsException { - File repository = LocalRepositoryUtil.prepareRepository(new File("mercurial-tests/testData/rep1").getAbsolutePath()); + File repository = copyRepository(myTempFiles, new File("mercurial-tests/testData/rep1").getAbsolutePath()); VcsRootImpl root = new VcsRootImpl(1, "rootForTest"); root.addProperty(Constants.REPOSITORY_PROP, repository.getAbsolutePath());