[Mercurial Tests] Introduced HgSingleUserTestCase, HgCollaborativeTestCase, HgTestRep...
[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.vfs.VirtualFile;
16 import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory;
17 import com.intellij.testFramework.fixtures.TempDirTestFixture;
18 import com.intellij.vcsUtil.VcsUtil;
19 import org.testng.annotations.AfterMethod;
20 import org.testng.annotations.BeforeMethod;
21 import org.zmlx.hg4idea.HgVcs;
22
23 import java.io.File;
24
25 import static org.testng.Assert.assertTrue;
26
27 /**
28  * TODO: substitute by new interface from HgCollaborativeTestCase and HgTestRepository.
29  */
30 public class HgFromClonedTestCase extends HgCollaborativeTestCase {
31
32   protected File remoteRepo;
33   protected File projectRepo;
34   private TempDirTestFixture remoteRepoDir;
35   private TempDirTestFixture projectRepoDir;
36   protected VirtualFile projectRepoVirtualFile;
37
38   @BeforeMethod
39   @Override
40   public void setUp() throws Exception {
41     super.setUp();
42
43     remoteRepoDir = IdeaTestFixtureFactory.getFixtureFactory().createTempDirTestFixture();
44     projectRepoDir = IdeaTestFixtureFactory.getFixtureFactory().createTempDirTestFixture();
45
46     remoteRepo = createAndFillHgRepo(remoteRepoDir, "remote");
47     projectRepo = cloneRemoteRepository(projectRepoDir, remoteRepo, "project");
48
49     initProject(projectRepo);
50     activateVCS(HgVcs.VCS_NAME);
51
52     projectRepoVirtualFile = VcsUtil.getVirtualFile(projectRepo);
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"), HgTestOutputParser.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 }