Mercurial > hg > mercurial
view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommandTest.java @ 1049:0022415d251d cloud
from trunk: fixed tests for recent hg versions
(grafted from 5bec80ce92ae32b6e271be3131dcfbd4cebbf918)
(grafted from a377f996514e4b9dfc66a4f47196cd4a6d3aa82d)
author | victory.bedrosova |
---|---|
date | Thu, 21 Jan 2021 12:01:07 +0100 |
parents | 7bf4d943d5bb |
children | 10dc26b32c35 |
line wrap: on
line source
/* * Copyright 2000-2018 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.TempFiles; import jetbrains.buildServer.buildTriggers.vcs.mercurial.HgPathProvider; import jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialClasspathTemplate; import jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialTemplate; import jetbrains.buildServer.vcs.VcsException; import org.jetbrains.annotations.NotNull; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @Test public class LogCommandTest extends BaseCommandTestCase { private TempFiles myTempFiles = new TempFiles(); private MercurialTemplate myTemplateFile; @BeforeMethod @Override protected void setUp() throws Exception { super.setUp(); setRepository("mercurial-tests/testData/rep1", true); myTemplateFile = new MercurialClasspathTemplate("/buildServerResources/log.template", "log.template") {}; } @AfterMethod public void tearDown() { myTempFiles.cleanup(); } public void testOneChangeSet() throws Exception { final String toId = "9875b412a788"; List<ChangeSet> changes = runLog(null, toId); assertEquals(1, changes.size()); final ChangeSet changeSet = changes.get(0); assertEquals(0, changeSet.getRevNumber()); assertEquals(toId, changeSet.getId()); assertEquals("pavel@localhost", changeSet.getUser()); assertEquals("dir1 created", changeSet.getDescription()); } public void testMoreThanOneChangeSet() throws Exception { final String fromId = "9875b412a788"; final String toId = "7209b1f1d793"; List<ChangeSet> changes = runLog(fromId, toId); assertEquals(3, changes.size()); ChangeSet changeSet1 = changes.get(0); final ChangeSet changeSet2 = changes.get(1); final ChangeSet changeSet3 = changes.get(2); assertEquals("dir1 created", changeSet1.getDescription()); assertEquals("new file added", changeSet2.getDescription()); assertEquals("file4.txt added", changeSet3.getDescription()); changes = runLog(null, toId); assertEquals(3, changes.size()); changeSet1 = changes.get(2); assertEquals("file4.txt added", changeSet1.getDescription()); } public void changeset_parents() throws VcsException, IOException { setRepository("mercurial-tests/testData/rep2", true); List<ChangeSet> changes = runLog("6eeb8974fe67", "6eeb8974fe67"); assertEquals(1, changes.size()); ChangeSet cs = changes.get(0); assertNotNull(cs.getParents()); assertEquals(2, cs.getParents().size()); assertTrue(cs.getParents().contains(new ChangeSetRevision("1:a3d15477d297"))); assertTrue(cs.getParents().contains(new ChangeSetRevision("3:2538c02bafeb"))); } public void parse_multiline_description() throws VcsException, IOException { List<ChangeSet> changes = runLog("9babcf2d5705", "9c6a6b4aede0"); assertEquals(1, changes.size()); assertEquals("Multiline description\n" + "description with new\n" + "lines\n" + "aaaa\n" + "bbb", changes.get(0).getDescription()); } public void log_result_should_contain_changed_files() throws Exception { final String fromId = "7209b1f1d793"; final String toId = "b06a290a363b"; List<ChangeSet> csets = runLog(fromId, toId); assertEquals(3, csets.size()); List<FileStatus> files = csets.get(0).getModifiedFiles(); assertEquals(1, files.size()); FileStatus file = files.get(0); assertEquals(Status.ADDED, file.getStatus()); assertEquals("dir1/file4.txt", file.getPath()); files = csets.get(1).getModifiedFiles(); assertEquals(1, files.size()); file = files.get(0); assertEquals(Status.REMOVED, file.getStatus()); assertEquals("dir1/file4.txt", file.getPath()); files = csets.get(2).getModifiedFiles(); assertEquals(1, files.size()); file = files.get(0); assertEquals(Status.MODIFIED, file.getStatus()); assertEquals("dir1/file3.txt", file.getPath()); } public void log_results_should_have_parents() throws Exception { setRepository("mercurial-tests/testData/rep2", true); List<ChangeSet> csets = runLog("e0ad3ddde5aa", "df04faa7575a"); for (ChangeSet cset : csets) { assertFalse(cset.getParents().isEmpty()); } Map<String, ChangeSet> csetMap = createChangeSetMap(csets); //see testData/README checkParents(csetMap.get("e0ad3ddde5aa"), "0000000000000000000000000000000000000000"); checkParents(csetMap.get("a3d15477d297"), "e0ad3ddde5aa"); checkParents(csetMap.get("db8a04d262f3"), "e0ad3ddde5aa"); checkParents(csetMap.get("2538c02bafeb"), "db8a04d262f3"); checkParents(csetMap.get("6eeb8974fe67"), "a3d15477d297", "2538c02bafeb"); checkParents(csetMap.get("b4937926e2e3"), "6eeb8974fe67"); checkParents(csetMap.get("6066b677d026"), "b4937926e2e3"); checkParents(csetMap.get("d6eaab231902"), "6eeb8974fe67"); checkParents(csetMap.get("b6e2d176fe8e"), "6066b677d026", "d6eaab231902"); } private Map<String, ChangeSet> createChangeSetMap(@NotNull List<ChangeSet> csets) { Map<String, ChangeSet> result = new HashMap<String, ChangeSet>(); for (ChangeSet cset : csets) { result.put(cset.getId(), cset); } return result; } private void checkParents(@NotNull final ChangeSet cset, String... parents) { assertEquals(parents.length, cset.getParents().size()); int i = 0; for (ChangeSetRevision parent : cset.getParents()) { assertEquals(parents[i], parent.getId()); i++; } } private List<ChangeSet> runLog(final String fromId, final String toId) throws IOException, VcsException { return runCommand(new CommandExecutor<List<ChangeSet>>() { public List<ChangeSet> execute(@NotNull HgVcsRoot root, @NotNull HgPathProvider hgPathProvider, @NotNull File workingDir) throws VcsException { return new LogCommand(myCommandSettingsFactory.create(), hgPathProvider.getHgPath(root), workingDir, root.getAuthSettings()) .inBranch(root.getBranchName()) .withTemplate(myTemplateFile) .fromRevision(fromId) .toRevision(toId) .call(); } }); } }