05a632198a3b5c34b4b82bb4d7063bc944d89e81
[idea/community.git] / plugins / hg4idea / testSrc / org / zmlx / hg4idea / test / HgFromClonedTestCase.java
1 // Copyright 2010 Victor Iacoban
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software distributed under
10 // the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11 // either express or implied. See the License for the specific language governing permissions and
12 // limitations under the License.
13 package org.zmlx.hg4idea.test;
14
15 import com.intellij.openapi.vcs.VcsConfiguration;
16 import com.intellij.openapi.vfs.VirtualFile;
17 import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory;
18 import com.intellij.testFramework.fixtures.TempDirTestFixture;
19 import com.intellij.vcsUtil.VcsUtil;
20 import org.testng.annotations.AfterMethod;
21 import org.testng.annotations.BeforeMethod;
22 import org.zmlx.hg4idea.HgVcs;
23
24 import java.io.File;
25
26 import static org.testng.Assert.assertTrue;
27
28 public class HgFromClonedTestCase extends HgAbstractTestCase {
29
30   protected File remoteRepo;
31   protected File projectRepo;
32   private TempDirTestFixture remoteRepoDir;
33   private TempDirTestFixture projectRepoDir;
34   protected VirtualFile projectRepoVirtualFile;
35
36   @BeforeMethod
37   public void setUp() throws Exception {
38     setHGExecutablePath();
39
40     remoteRepoDir = IdeaTestFixtureFactory.getFixtureFactory().createTempDirTestFixture();
41     projectRepoDir = IdeaTestFixtureFactory.getFixtureFactory().createTempDirTestFixture();
42
43     remoteRepo = createAndFillHgRepo(remoteRepoDir, "remote");
44     projectRepo = cloneRemoteRepository(projectRepoDir, remoteRepo, "project");
45
46     initProject(projectRepo);
47     activateVCS(HgVcs.VCS_NAME);
48
49     projectRepoVirtualFile = VcsUtil.getVirtualFile(projectRepo);
50
51     enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
52     enableSilentOperation(VcsConfiguration.StandardConfirmation.REMOVE);
53   }
54
55   private File cloneRemoteRepository(TempDirTestFixture projectRepoDir, File remoteRepo, String destination) throws Exception {
56     projectRepoDir.setUp();
57     String projectTempParent = projectRepoDir.getTempDirPath();
58
59     File projectRepo = new File(projectTempParent, destination);
60     runHg(null, "clone", remoteRepo.getAbsolutePath(), projectRepo.getAbsolutePath());
61     assertTrue(projectRepo.exists());
62     return projectRepo;
63   }
64
65   private File createAndFillHgRepo(TempDirTestFixture remoteRepoDir, String dirName) throws Exception {
66     remoteRepoDir.setUp();
67     File remoteRepo = new File(remoteRepoDir.getTempDirPath(), dirName);
68     assertTrue(remoteRepo.mkdir());
69
70
71     verify(runHg(remoteRepo, "init"));
72
73     File aFile = fillFile(remoteRepo, new String[]{"com", "a.txt"}, "file contents");
74
75     verify(runHg(remoteRepo, "add", aFile.getPath()));
76     verify(runHg(remoteRepo, "status"), added("com", "a.txt"));
77     verify(runHg(remoteRepo, "commit", "-m", "initial contents"));
78
79     return remoteRepo;
80   }
81
82   @AfterMethod
83   public void tearDown() throws Exception {
84 //    remoteRepoDir.tearDown();
85 //    projectRepoDir.tearDown();
86   }
87 }