Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: dcab5bd5438a01a4ef584c43b7c90865949ee304 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*******************************************************************************
 * Copyright (c) 2016 Thomas Wolf <thomas.wolf@paranor.ch>
 * 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
 *******************************************************************************/
package org.eclipse.egit.ui.test.team.actions;

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

import java.io.File;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIPreferences;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
import org.eclipse.egit.ui.internal.staging.StagingView;
import org.eclipse.egit.ui.test.ContextMenuHelper;
import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * Tests for the Team->Commit action
 */
@RunWith(SWTBotJunit4ClassRunner.class)
public class CommitActionStagingViewTest extends LocalRepositoryTestCase {
	private File repositoryFile;

	private boolean initialUseStagingView;

	@Before
	public void setup() throws Exception {
		TestUtil.hideView(StagingView.VIEW_ID);
		initialUseStagingView = Activator.getDefault().getPreferenceStore()
				.getBoolean(UIPreferences.ALWAYS_USE_STAGING_VIEW);
		Activator.getDefault().getPreferenceStore()
				.setValue(UIPreferences.ALWAYS_USE_STAGING_VIEW, true);
		Activator.getDefault().getPreferenceStore()
				.setDefault(UIPreferences.STAGING_VIEW_SYNC_SELECTION, false);
		Activator.getDefault().getPreferenceStore()
				.setValue(UIPreferences.STAGING_VIEW_SYNC_SELECTION, false);
		repositoryFile = createProjectAndCommitToRepository();
		Repository repo = lookupRepository(repositoryFile);
		TestUtil.configureTestCommitterAsUser(repo);
		// TODO delete the second project for the time being (.gitignore is
		// currently not hiding the .project file from commit)
		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ2);
		File dotProject = new File(project.getLocation().toOSString(), ".project");
		project.delete(false, false, null);
		assertTrue(dotProject.delete());
	}

	@After
	public void tearDown() {
		Activator.getDefault().getPreferenceStore().setValue(
				UIPreferences.ALWAYS_USE_STAGING_VIEW, initialUseStagingView);
		Activator.getDefault().getPreferenceStore()
				.setDefault(UIPreferences.STAGING_VIEW_SYNC_SELECTION, true);
		Activator.getDefault().getPreferenceStore()
				.setValue(UIPreferences.STAGING_VIEW_SYNC_SELECTION, true);
	}

	@Test
	public void testOpenStagingViewNoLinkWithSelection() throws Exception {
		setTestFileContent("I have changed this");
		SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
		util.getProjectItems(projectExplorerTree, PROJ1)[0].select();
		String menuString = util.getPluginLocalizedValue("CommitAction_label");
		ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team",
				menuString);
		TestUtil.waitUntilViewWithGivenIdShows(StagingView.VIEW_ID);
		final Repository[] repo = { null };
		PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

			@Override
			public void run() {
				StagingView view;
				try {
					view = (StagingView) PlatformUI.getWorkbench()
							.getActiveWorkbenchWindow().getActivePage()
							.showView(StagingView.VIEW_ID);
					repo[0] = view.getCurrentRepository();
				} catch (PartInitException e) {
					// Ignore, repo[0] remains null
				}
			}
		});
		Repository repository = lookupRepository(repositoryFile);
		assertNotNull("No repository found", repository);
		assertEquals("Repository mismatch", repository, repo[0]);
	}

}

Back to the top