Mercurial > hg > mercurial
view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/UnrelatedResitoriesTest.java @ 406:aa016c34fede Faradi-7.0.x
Cleanup
author | Dmitry Neverov <dmitry.neverov@jetbrains.com> |
---|---|
date | Mon, 05 Mar 2012 13:07:44 +0400 |
parents | 45f25ca68312 |
children | b34ffc622efc |
line wrap: on
line source
package jetbrains.buildServer.buildTriggers.vcs.mercurial; import com.intellij.openapi.diagnostic.Logger; import jetbrains.buildServer.TempFiles; import jetbrains.buildServer.log.Log4jFactory; import jetbrains.buildServer.util.FileUtil; import jetbrains.buildServer.vcs.CheckoutRules; import jetbrains.buildServer.vcs.VcsException; import jetbrains.buildServer.vcs.impl.VcsRootImpl; import org.jetbrains.annotations.NotNull; import org.jmock.Mockery; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.io.File; import java.io.IOException; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertTrue; /** * @author dmitry.neverov */ @Test public class UnrelatedResitoriesTest { private final static String CURRENT_VERSION_OF_NEW_REPO = "18:df04faa7575a"; private MercurialVcsSupport myVcs; private TempFiles myTempFiles; private File myRepositoryLocation; private VcsRootImpl myRoot; private Mockery myContext; private ServerPluginConfig myPluginConfig; static { Logger.setFactory(new Log4jFactory()); } @BeforeMethod public void setUp() throws Exception { myContext = new Mockery(); myTempFiles = new TempFiles(); myPluginConfig = new ServerPluginConfigBuilder() .cachesDir(myTempFiles.createTempDir()) .pluginDataDir(myTempFiles.createTempDir()) .build(); myRepositoryLocation = myTempFiles.createTempDir(); copyRepository(new File("mercurial-tests/testData/rep1")); myRoot = new VcsRootBuilder().withUrl(myRepositoryLocation.getCanonicalPath()).build(); } @AfterMethod public void tearDown() { myTempFiles.cleanup(); } public void should_be_able_to_sync_when_repository_became_unrelated() throws Exception { myVcs = createVcs(); syncRepository(); repositoryBecamesUnrelated(); String currentVersion = syncRepository(); assertEquals(CURRENT_VERSION_OF_NEW_REPO, currentVersion); } public void should_return_no_changes_when_fromRevision_is_from_unrelated_repository() throws Exception { myVcs = createVcs(); String currentVersionOfOldRepo = syncRepository(); repositoryBecamesUnrelated(); String currentVersionOfNewRepo = syncRepository(); assertTrue(myVcs.collectChanges(myRoot, currentVersionOfOldRepo, currentVersionOfNewRepo, CheckoutRules.DEFAULT).isEmpty()); } private String syncRepository() throws VcsException { return myVcs.getCurrentVersion(myRoot); } private void repositoryBecamesUnrelated() throws IOException { FileUtil.delete(myRepositoryLocation); copyRepository(new File("mercurial-tests/testData/rep2")); } private void copyRepository(@NotNull final File src) throws IOException { LocalRepositoryUtil.copyRepository(src, myRepositoryLocation); } private MercurialVcsSupport createVcs() throws IOException { return Util.createMercurialServerSupport(myContext, myPluginConfig); } }