Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1666721c48235121402f900c81e512c6da62adb1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/******************************************************************************
 *  Copyright (c) 2012 GitHub Inc.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  Contributors:
 *    Kevin Sawicki (GitHub Inc.) - initial API and implementation
 *****************************************************************************/
package org.eclipse.egit.ui.submodule;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.io.File;

import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.JobFamilies;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.test.ContextMenuHelper;
import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.egit.ui.view.repositories.GitRepositoriesViewTestBase;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * Unit tests for adding submodules to a repository
 */
@RunWith(SWTBotJunit4ClassRunner.class)
public class SubmoduleAddTest extends GitRepositoriesViewTestBase {

	private static final String ADD_SUBMODULE_CONTEXT_MENU_LABEL = "SubmoduleAddCommand.label";

	private File repositoryFile;

	@Before
	public void before() throws Exception {
		repositoryFile = createProjectAndCommitToRepository();
	}

	@Test
	public void addAtRoot() throws Exception {
		deleteAllProjects();
		assertProjectExistence(PROJ1, false);
		clearView();
		Activator.getDefault().getRepositoryUtil()
				.addConfiguredRepository(repositoryFile);
		shareProjects(repositoryFile);
		assertProjectExistence(PROJ1, true);
		refreshAndWait();
		assertHasRepo(repositoryFile);
		FileRepository repo = lookupRepository(repositoryFile);

		SWTBotTree tree = getOrOpenView().bot().tree();
		tree.getAllItems()[0].select();
		ContextMenuHelper.clickContextMenu(tree, myUtil
				.getPluginLocalizedValue(ADD_SUBMODULE_CONTEXT_MENU_LABEL));
		SWTBotShell shell = bot.shell(UIText.AddSubmoduleWizard_WindowTitle);
		shell.activate();
		shell.bot().textWithLabel(UIText.SubmodulePathWizardPage_PathLabel)
				.setText("sub");
		shell.bot().button(IDialogConstants.NEXT_LABEL).click();

		shell.bot()
				.textWithLabel(UIText.RepositorySelectionPage_promptURI + ":")
				.setText(repo.getDirectory().toURI().toString());

		shell.bot().button(IDialogConstants.FINISH_LABEL).click();
		waitInUI();
		TestUtil.joinJobs(JobFamilies.SUBMODULE_ADD);
		refreshAndWait();

		tree = getOrOpenView().bot().tree();
		SWTBotTreeItem submodules = tree.getAllItems()[0]
				.select()
				.expand()
				.getNode(
						UIText.RepositoriesViewLabelProvider_SubmodulesNodeText);
		assertNotNull(submodules);
		submodules.expand();
		assertEquals(1, submodules.rowCount());
	}
}

Back to the top