view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseAgentSideCheckoutTestCase.java @ 856:a11bcfb63f4f

Support sparse checkout
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Tue, 08 Jul 2014 16:15:55 +0200
parents 80ae3dc66685
children c28e68e22272
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.agent.AgentRunningBuild;
import jetbrains.buildServer.agent.BuildAgentConfiguration;
import jetbrains.buildServer.agent.BuildProgressLogger;
import jetbrains.buildServer.agent.vcs.UpdateByIncludeRules2;
import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.CommandSettingsForRootImpl;
import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.CommandlineViaFileWrapperWeaver;
import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.ExtensionsWeaver;
import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.TestCommandSettingsFactory;
import jetbrains.buildServer.buildTriggers.vcs.mercurial.ext.MercurialExtensionManager;
import jetbrains.buildServer.vcs.CheckoutRules;
import jetbrains.buildServer.vcs.IncludeRule;
import jetbrains.buildServer.vcs.VcsException;
import jetbrains.buildServer.vcs.VcsRoot;
import org.jetbrains.annotations.NotNull;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.testng.annotations.BeforeMethod;

import java.io.File;
import java.util.HashMap;

public abstract class BaseAgentSideCheckoutTestCase extends BaseMercurialTestCase {

  protected Mockery myContext;
  protected BuildProgressLogger myLogger;
  protected UpdateByIncludeRules2 myVcsSupport;
  private int myBuildCounter = 0;
  protected File myWorkDir;

  @Override
  @BeforeMethod
  public void setUp() throws Exception {
    super.setUp();

    myContext = new Mockery();

    final BuildAgentConfiguration agentConfig = myContext.mock(BuildAgentConfiguration.class);
    myContext.checking(new Expectations() {{
      allowing(agentConfig).getCacheDirectory("mercurial"); will(returnValue(myTempFiles.createTempDir()));
      allowing(agentConfig).getParametersResolver(); will(returnValue(new HgPathResolver()));
    }});

    final AgentPluginConfigImpl pluginConfig = new AgentPluginConfigImpl(agentConfig);
    MirrorManager mirrorManager = new MirrorManagerImpl(pluginConfig);
    CommandSettingsForRootImpl commandSettingsFactory = new CommandSettingsForRootImpl(new TestCommandSettingsFactory(), new ExtensionsWeaver(), new CommandlineViaFileWrapperWeaver());
    myVcsSupport = new MercurialAgentSideVcsSupport(pluginConfig, mirrorManager, new AgentRepoFactory(pluginConfig, commandSettingsFactory, new AgentHgPathProvider(agentConfig)),
            new MercurialExtensionManager());

    myLogger = myContext.mock(BuildProgressLogger.class);
    myContext.checking(new Expectations() {{
      allowing(myLogger).message(with(any(String.class)));
      allowing(myLogger).warning(with(any(String.class)));
    }});

    myWorkDir = myTempFiles.createTempDir();
  }


  protected void checkout(@NotNull VcsRoot vcsRoot, @NotNull String toVersion) throws VcsException {
    checkout(vcsRoot, toVersion, false);
  }

  protected void checkout(@NotNull VcsRoot vcsRoot, @NotNull String toVersion, final boolean useLocalMirrors) throws VcsException {
    final AgentRunningBuild build = myContext.mock(AgentRunningBuild.class, "build" + myBuildCounter++);
    myContext.checking(new Expectations() {{
      allowing(build).getBuildLogger(); will(returnValue(myLogger));
      allowing(build).getSharedConfigParameters(); will(returnValue(new HashMap<String, String>() {{
        put("teamcity.hg.use.local.mirrors", useLocalMirrors ? "true" : "false");
      }}));
    }});
    myVcsSupport.getUpdater(vcsRoot, CheckoutRules.DEFAULT, toVersion, myWorkDir, build, false).process(IncludeRule.createDefaultInstance(), myWorkDir);
  }
}