1 /*******************************************************************************
2 * Copyright (C) 2009, Robin Rosenberg <robin.rosenberg@dewire.com>
3 * Copyright (C) 2010, Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
9 *******************************************************************************/
10 package org
.eclipse
.egit
.ui
.wizards
.clone
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertFalse
;
14 import static org
.junit
.Assert
.assertNotNull
;
15 import static org
.junit
.Assert
.assertNull
;
16 import static org
.junit
.Assert
.assertTrue
;
20 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
21 import org
.eclipse
.core
.runtime
.Platform
;
22 import org
.eclipse
.egit
.ui
.test
.Eclipse
;
23 import org
.eclipse
.jgit
.lib
.Repository
;
24 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
25 import org
.eclipse
.swtbot
.swt
.finder
.exceptions
.WidgetNotFoundException
;
26 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
27 import org
.junit
.After
;
28 import org
.junit
.Before
;
29 import org
.junit
.BeforeClass
;
30 import org
.junit
.Ignore
;
31 import org
.junit
.Test
;
32 import org
.junit
.runner
.RunWith
;
34 @RunWith(SWTBotJunit4ClassRunner
.class)
35 public class GitCloneWizardTest
{
37 System
.setProperty("org.eclipse.swtbot.playback.delay", "50");
40 private static final SWTWorkbenchBot bot
= new SWTWorkbenchBot();
42 private GitImportRepoWizard importWizard
;
45 public void updatesParameterFieldsInImportDialogWhenURIIsUpdated()
48 RepoPropertiesPage propertiesPage
= importWizard
.openWizard();
50 propertiesPage
.setURI("git://www.jgit.org/EGIT");
51 propertiesPage
.assertSourceParams(null, "www.jgit.org", "/EGIT", "git",
52 "", true, "", "", false, false);
54 propertiesPage
.appendToURI("X");
56 propertiesPage
.assertSourceParams(null, "www.jgit.org", "/EGITX",
57 "git", "", true, "", "", false, false);
59 propertiesPage
.setURI("git://www.jgit.org/EGIT");
60 propertiesPage
.assertSourceParams(null, "www.jgit.org", "/EGIT", "git",
61 "", true, "", "", false, false);
63 propertiesPage
.setURI("git://user:hi@www.jgit.org/EGIT");
64 propertiesPage
.assertSourceParams(
65 " User not supported on git protocol.", "www.jgit.org",
66 "/EGIT", "git", "", true, "user", "hi", false, false);
68 // UI doesn't change URI even when password is entered in clear text as
69 // part of URI. Opinions on this may vary.
70 propertiesPage
.assertURI("git://user:hi@www.jgit.org/EGIT");
72 propertiesPage
.setURI("ssh://user@www.jgit.org/EGIT");
73 propertiesPage
.assertSourceParams(null, "www.jgit.org", "/EGIT",
74 "git+ssh", "", true, "user", "", true, true);
76 propertiesPage
.setURI("ssh://user@www.jgit.org/EGIT");
77 propertiesPage
.assertSourceParams(null, "www.jgit.org", "/EGIT",
78 "git+ssh", "", true, "user", "", true, true);
80 propertiesPage
.setURI("ssh://user:hi@www.jgit.org:33/EGIT");
81 propertiesPage
.assertSourceParams(null, "www.jgit.org", "/EGIT",
82 "git+ssh", "33", true, "user", "hi", true, true);
84 propertiesPage
.setURI("ssh:///EGIT");
85 propertiesPage
.assertSourceParams(" Host required for ssh protocol.",
86 "", "/EGIT", "git+ssh", "", true, "", "", true, true);
88 propertiesPage
.setURI("file:///some/place");
89 if (Platform
.getOS().equals(Platform
.OS_WIN32
))
90 propertiesPage
.assertSourceParams(" "
91 + System
.getProperty("user.dir")
92 + "\\.\\some\\place does not exist.", "", "/some/place",
93 "file", "", false, "", "", false, false);
95 propertiesPage
.assertSourceParams(" /some/place does not exist.",
96 "", "/some/place", "file", "", false, "", "", false, false);
98 // Now try changing some fields other than URI and see how the URI field
100 propertiesPage
.setURI("ssh://user@www.jgit.org/EGIT");
103 bot
.textWithLabel("Host:").setText("example.com");
104 propertiesPage
.assertURI("ssh://user@example.com/EGIT");
106 propertiesPage
.assertSourceParams(null, "example.com", "/EGIT",
107 "git+ssh", "", true, "user", "", true, true);
110 bot
.textWithLabel("User:").setText("gitney");
111 propertiesPage
.assertURI("ssh://gitney@example.com/EGIT");
112 propertiesPage
.assertSourceParams(null, "example.com", "/EGIT",
113 "git+ssh", "", true, "gitney", "", true, true);
116 bot
.textWithLabel("Password:").setText("fsck");
117 // Password is not written into the URL here!
118 propertiesPage
.assertURI("ssh://gitney@example.com/EGIT");
119 propertiesPage
.assertSourceParams(null, "example.com", "/EGIT",
120 "git+ssh", "", true, "gitney", "fsck", true, true);
122 // change port number
123 bot
.textWithLabel("Port:").setText("99");
124 propertiesPage
.assertURI("ssh://gitney@example.com:99/EGIT");
125 propertiesPage
.assertSourceParams(null, "example.com", "/EGIT",
126 "git+ssh", "99", true, "gitney", "fsck", true, true);
128 // change protocol to another with user/password capability
129 bot
.comboBoxWithLabel("Protocol:").setSelection("ftp");
130 propertiesPage
.assertURI("ftp://gitney@example.com:99/EGIT");
131 propertiesPage
.assertSourceParams(null, "example.com", "/EGIT", "ftp",
132 "99", true, "gitney", "fsck", true, true);
134 // change protocol to one without user/password capability
135 bot
.comboBoxWithLabel("Protocol:").setSelection("git");
136 propertiesPage
.assertURI("git://gitney@example.com:99/EGIT");
137 propertiesPage
.assertSourceParams(
138 " User not supported on git protocol.", "example.com", "/EGIT",
139 "git", "99", true, "gitney", "fsck", false, false);
141 // change protocol to one without host capability
142 bot
.comboBoxWithLabel("Protocol:").setSelection("file");
143 propertiesPage
.assertURI("file://gitney@example.com:99/EGIT");
144 propertiesPage
.assertSourceParams(
145 " Host not supported on file protocol.", "example.com",
146 "/EGIT", "file", "99", false, "gitney", "fsck", false, false);
148 // Local protocol with file: prefix. We need to make sure the
149 // local path exists as a directory so we choose user.home as
150 // that one should exist.
151 if (Platform
.getOS().equals(Platform
.OS_WIN32
))
152 propertiesPage
.setURI("file:///" + System
.getProperty("user.home"));
154 propertiesPage
.setURI("file://" + System
.getProperty("user.home"));
155 propertiesPage
.assertSourceParams(null, "", System
.getProperty(
156 "user.home").replace('\\', '/'), "file", "", false, "", "",
159 // Local protocol without file: prefix
160 propertiesPage
.setURI(System
.getProperty("user.home"));
161 propertiesPage
.assertSourceParams(null, "", System
.getProperty(
162 "user.home").replace('\\', '/'), "file", "", false, "", "",
165 // On windows the use can choose forward or backward slashes, so add
166 // a case for forward slashes using the non prefixed local protocol.
167 if (Platform
.getOS().equals(Platform
.OS_WIN32
)) {
168 propertiesPage
.setURI(System
.getProperty("user.home").replace('\\',
170 propertiesPage
.assertSourceParams(null, "", System
.getProperty(
171 "user.home").replace('\\', '/'), "file", "", false, "", "",
174 bot
.button("Cancel").click();
177 @SuppressWarnings("boxing")
179 public void canCloneARemoteRepo() throws Exception
{
180 File destRepo
= new File(ResourcesPlugin
.getWorkspace()
181 .getRoot().getLocation().toFile(), "egit");
183 RepoPropertiesPage propertiesPage
= importWizard
.openWizard();
185 RepoRemoteBranchesPage remoteBranches
= propertiesPage
186 .nextToRemoteBranches("git://repo.or.cz/egit.git");
188 remoteBranches
.assertRemoteBranches("historical/pre-eclipse", "master");
189 remoteBranches
.selectBranches("historical/pre-eclipse");
191 WorkingCopyPage workingCopy
= remoteBranches
.nextToWorkingCopy();
193 workingCopy
.assertDirectory(destRepo
.toString());
194 workingCopy
.assertBranch("master");
195 workingCopy
.assertRemoteName("origin");
196 workingCopy
.waitForCreate();
198 // Some random sampling to see we got something. We do not test
199 // the integrity of the repository here. Only a few basic properties
200 // we'd expect from a clone made this way, that would possibly
201 // not hold true given other parameters in the GUI.
202 Repository repository
= new Repository(new File(destRepo
, ".git"));
203 // we always have an origin/master
204 assertNotNull(repository
.resolve("origin/master"));
205 // and a local master initialized from origin/master (default!)
206 assertEquals(repository
.resolve("origin/master"), repository
207 .resolve("origin/master"));
209 assertEquals("90b818e596660b813b6fcf68f1e9e9b62c615130", repository
210 .resolve("refs/tags/v0.4.0").name());
212 assertTrue(repository
.getAllRefs().size() >= 10);
213 // and a README in the working dir
214 assertTrue(new File(destRepo
, "README").exists());
215 assertFalse(repository
.getIndex().isChanged());
216 assertFalse(repository
.getIndex().getEntry("README").isModified(
218 // No project have been imported
220 ResourcesPlugin
.getWorkspace().getRoot().getProjects().length
);
225 public void clonedRepositoryShouldExistOnFileSystem() throws Exception
{
226 RepoPropertiesPage repoProperties
= importWizard
.openWizard();
227 RepoRemoteBranchesPage remoteBranches
= repoProperties
228 .nextToRemoteBranches("git://repo.or.cz/egit.git");
229 WorkingCopyPage workingCopy
= remoteBranches
.nextToWorkingCopy();
230 workingCopy
.assertWorkingCopyExists();
234 public void alteringSomeParametersDuringClone() throws Exception
{
236 File destRepo
= new File(new File(ResourcesPlugin
.getWorkspace()
237 .getRoot().getLocation().toFile().getParent(),
238 "junit-workspace"), "EGIT2");
240 RepoPropertiesPage repoProperties
= importWizard
.openWizard();
241 RepoRemoteBranchesPage remoteBranches
= repoProperties
242 .nextToRemoteBranches("git://repo.or.cz/egit.git");
243 remoteBranches
.deselectAllBranches();
245 .assertErrorMessage("At least one branch must be selected.");
246 remoteBranches
.assertNextIsDisabled();
248 remoteBranches
.selectBranches("historical/pre-eclipse");
249 remoteBranches
.assertNextIsEnabled();
251 WorkingCopyPage workingCopy
= remoteBranches
.nextToWorkingCopy();
252 workingCopy
.setDirectory(destRepo
.toString());
253 workingCopy
.assertBranch("historical/pre-eclipse");
254 workingCopy
.setRemoteName("src");
255 workingCopy
.waitForCreate();
257 // Some random sampling to see we got something. We do not test
258 // the integrity of the repo here. Only a few basic properties
259 // we'd expect from a clone made this way, that would possibly
260 // not hold true given othe parameters in the GUI.
261 Repository repository
= new Repository(new File(destRepo
, ".git"));
262 assertNotNull(repository
.resolve("src/historical/pre-eclipse"));
263 // we didn't clone that one
264 assertNull(repository
.resolve("src/master"));
265 // and a local master initialized from origin/master (default!)
266 assertEquals(repository
.resolve("stable"), repository
267 .resolve("src/stable"));
269 assertEquals("90b818e596660b813b6fcf68f1e9e9b62c615130", repository
270 .resolve("refs/tags/v0.4.0").name());
272 assertTrue(repository
.getAllRefs().size() >= 10);
276 public void invalidHostnameFreezesDialog() throws Exception
{
277 RepoPropertiesPage repoProperties
= importWizard
.openWizard();
278 RepoRemoteBranchesPage remoteBranches
= repoProperties
279 .nextToRemoteBranches("git://no.example.com/EGIT");
281 .assertErrorMessage("git://no.example.com/EGIT: unknown host");
282 remoteBranches
.assertCannotProceed();
283 remoteBranches
.cancel();
286 // TODO: Broken, seems that this takes forever and does not come back with
287 // an error. Perhaps set a higher timeout for this test ?
289 public void invalidPortFreezesDialog() throws Exception
{
290 RepoPropertiesPage repoProperties
= importWizard
.openWizard();
291 RepoRemoteBranchesPage remoteBranches
= repoProperties
292 .nextToRemoteBranches("git://localhost:80/EGIT");
294 .assertErrorMessage("git://localhost:80/EGIT: not found.");
295 remoteBranches
.assertCannotProceed();
296 remoteBranches
.cancel();
299 // TODO: Broken, seems that this takes forever and does not come back with
300 // an error. Perhaps set a higher timeout for this test ?
302 public void timeoutToASocketFreezesDialog() throws Exception
{
303 RepoPropertiesPage repoProperties
= importWizard
.openWizard();
304 RepoRemoteBranchesPage remoteBranches
= repoProperties
305 .nextToRemoteBranches("git://www.example.com/EGIT");
307 .assertErrorMessage("git://www.example.com/EGIT: Connection timed out");
308 remoteBranches
.assertCannotProceed();
309 remoteBranches
.cancel();
313 public void setupViews() {
314 bot
.perspectiveById("org.eclipse.jdt.ui.JavaPerspective").activate();
315 bot
.viewByTitle("Package Explorer").show();
316 importWizard
= new GitImportRepoWizard();
319 // TODO: push this in the junit class runner. This can then be shared across
322 public static void closeWelcomePage() {
324 bot
.viewByTitle("Welcome").close();
325 } catch (WidgetNotFoundException e
) {
326 // somebody else probably closed it, lets not feel bad about it.
330 // TODO: push this in the junit class runner. This can then be shared across
333 public void resetWorkbench() {
334 new Eclipse().reset();