view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/StatusCommandTest.java @ 426:c91c4f1ebd53

Settings -> HgVcsRoot
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Fri, 11 May 2012 15:55:57 +0400
parents e33c3e4918f5
children 04eab204ba39
line wrap: on
line source
/*
 * 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.command;

import jetbrains.buildServer.vcs.VcsException;
import org.jetbrains.annotations.NotNull;
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.util.List;

@Test
public class StatusCommandTest extends BaseCommandTestCase {
  public void testAddedFile() throws IOException, VcsException {
    setRepository("mercurial-tests/testData/rep1", true);
    List<FileStatus> files = runStatus("9875b412a788", "1d446e82d356");
    assertEquals(1, files.size());
    FileStatus md = files.get(0);
    assertEquals(Status.ADDED, md.getStatus());
    assertEquals("dir1/file3.txt", md.getPath().replace(File.separatorChar, '/'));
  }

  public void testRemovedFile() throws IOException, VcsException {
    setRepository("mercurial-tests/testData/rep1", true);
    List<FileStatus> files = runStatus("7209b1f1d793", "9522278aa38d");
    assertEquals(1, files.size());
    FileStatus md = files.get(0);
    assertEquals(Status.REMOVED, md.getStatus());
    assertEquals("dir1/file4.txt", md.getPath().replace(File.separatorChar, '/'));
  }

  public void testModifiedFile() throws IOException, VcsException {
    setRepository("mercurial-tests/testData/rep1", true);
    List<FileStatus> files = runStatus("9522278aa38d", "b06a290a363b");
    assertEquals(1, files.size());
    FileStatus md = files.get(0);
    assertEquals(Status.MODIFIED, md.getStatus());
    assertEquals("dir1/file3.txt", md.getPath().replace(File.separatorChar, '/'));
  }

  private List<FileStatus> runStatus(final String fromId, final String toId) throws IOException, VcsException {
    return runCommand(new CommandExecutor<List<FileStatus>>() {
      public List<FileStatus> execute(@NotNull final HgVcsRoot root, @NotNull final File workingDir) throws VcsException {
        return new StatusCommand(root.getHgCommandPath(), workingDir, root.getAuthSettings())
                .fromRevision(fromId)
                .toRevision(toId)
                .call();
      }
    });
  }

}