Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: cc16bef23f0ce135e2b28aae66a64fbb0694ac62 (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
/*******************************************************************************
 * Copyright (C) 2015, Max Hohenegger <eclipse@hohenegger.eu>
 *
 * 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.gitflow;

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

import org.eclipse.egit.gitflow.GitFlowConfig;
import org.eclipse.egit.gitflow.GitFlowRepository;
import org.eclipse.egit.gitflow.ui.Activator;
import org.eclipse.egit.gitflow.ui.internal.JobFamilies;

import static org.eclipse.egit.gitflow.ui.internal.UIText.*;

import org.eclipse.egit.ui.test.ContextMenuHelper;
import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.ui.PlatformUI;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * Tests for the Team->Gitflow init
 */
@RunWith(SWTBotJunit4ClassRunner.class)
public class InitHandlerTest extends AbstractGitflowHandlerTest {
	private static final String DEVELOP_BRANCH = "a";
	private static final String MASTER_BRANCH = "b";
	private static final String FEATURE_BRANCH_PREFIX = "c";
	private static final String RELEASE_BRANCH_PREFIX = "d";
	private static final String HOTFIX_BRANCH_PREFIX = "e";
	private static final String VERSION_TAG_PREFIX = "f";

	private static final String ILLEGAL_BRANCH_NAME = "!@#$%^&*()_";

	@Test
	public void testInit() throws Exception {
		init();

		GitFlowRepository gitFlowRepository = new GitFlowRepository(repository);
		GitFlowConfig config = gitFlowRepository.getConfig();

		assertEquals(DEVELOP_BRANCH, repository.getBranch());
		assertEquals(MASTER_BRANCH, config.getMaster());
		assertEquals(FEATURE_BRANCH_PREFIX, config.getFeaturePrefix());
		assertEquals(RELEASE_BRANCH_PREFIX, config.getReleasePrefix());
		assertEquals(HOTFIX_BRANCH_PREFIX, config.getHotfixPrefix());
		assertEquals(VERSION_TAG_PREFIX, config.getVersionTagPrefix());

	}

	private void init() {
		final SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
		getProjectItem(projectExplorerTree, PROJ1).select();
		final String[] menuPath = new String[] {
				util.getPluginLocalizedValue("TeamMenu.label"),
				util.getPluginLocalizedValue("TeamGitFlowInit.name", false, Activator.getDefault().getBundle()) };
		PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
			@Override
			public void run() {
				ContextMenuHelper.clickContextMenuSync(projectExplorerTree,
						menuPath);
			}
		});

		SWTBotText developText = bot.textWithLabel(InitDialog_developBranch);
		developText.selectAll();
		developText.typeText(ILLEGAL_BRANCH_NAME);


		SWTBotButton ok = bot.button("OK");
		assertFalse(ok.isEnabled());

		typeInto(InitDialog_developBranch, DEVELOP_BRANCH);
		typeInto(InitDialog_masterBranch, MASTER_BRANCH);
		typeInto(InitDialog_featureBranchPrefix, FEATURE_BRANCH_PREFIX);
		typeInto(InitDialog_releaseBranchPrefix, RELEASE_BRANCH_PREFIX);
		typeInto(InitDialog_hotfixBranchPrefix, HOTFIX_BRANCH_PREFIX);
		typeInto(InitDialog_versionTagPrefix, VERSION_TAG_PREFIX);

		ok.click();
		bot.waitUntil(Conditions.waitForJobs(JobFamilies.GITFLOW_FAMILY, "Git flow jobs"));
	}

	private void typeInto(String textLabel, String textInput) {
		SWTBotText developText = bot.textWithLabel(textLabel);
		developText.selectAll();
		developText.typeText(textInput);
	}
}

Back to the top