Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7acba00e4d4e02ce038741e378b0d74454faa86c (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*******************************************************************************
 * Copyright (c) 2012 Lorenzo Bettini.
 * 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:
 *     Lorenzo Bettini - initial API and implementation
 *******************************************************************************/
package org.eclipse.swtbot.eclipse.finder.widgets;

import java.util.List;

import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.helpers.NewJavaClass;
import org.eclipse.swtbot.eclipse.finder.widgets.helpers.NewJavaProject;
import org.eclipse.swtbot.eclipse.finder.widgets.helpers.PackageExplorerView;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * @author Lorenzo Bettini <bettini [at] dsi [dot] unifi [dot] it>
 * @version $Id$
 */
@RunWith(SWTBotJunit4ClassRunner.class)
public class SWTBotEclipseProjectTest {

	private static final String		PROJECT_NAME		= "FooBarProject";
	private static final String		PACKAGE_NAME		= "org.eclipse.swtbot.eclipse.test";
	private static final String		CLASS_NAME			= "HelloWorld";
	private static final String		CLASS_FILE_NAME		= CLASS_NAME + ".java";

	private NewJavaClass			javaClass			= new NewJavaClass();
	private NewJavaProject			javaProject			= new NewJavaProject();
	private PackageExplorerView		packageExplorerView	= new PackageExplorerView();
	private static SWTWorkbenchBot	bot					= new SWTWorkbenchBot();

	@BeforeClass
	public static void beforeClass() {
		closeWelcomePage();
	}

	@Before
	public void setUp() throws Exception {
		javaProject.createProject(PROJECT_NAME);
		javaClass.createClass(PACKAGE_NAME, CLASS_NAME);
	}

	private static void closeWelcomePage() {
		try {
			System.setProperty("org.eclipse.swtbot.search.timeout", "0");
			bot.viewByTitle("Welcome").close();
		} catch (WidgetNotFoundException e) {
			// do nothing
		}finally{
			System.setProperty("org.eclipse.swtbot.search.timeout", "5000");
		}
	}

	@After
	public void tearDown() throws Exception {
		saveAndCloseAllEditors();
		packageExplorerView.deleteProject(PROJECT_NAME);
	}

	/**
	 * @throws WidgetNotFoundException
	 */
	private void saveAndCloseAllEditors() {
		List<? extends SWTBotEditor> editors = bot.editors();
		for (SWTBotEditor editor : editors) {
			editor.saveAndClose();
		}
	}

	@Test
	public void canRefreshProject() {
		packageExplorerTree().expandNode(PROJECT_NAME, "src")
				.contextMenu("Refresh").click();
	}

	@Test
	public void canAccessOpen() {
		javaClassFileTreeItem().contextMenu("Open").click();
	}

	@Test
	public void canAccessContextMenuWithSubmenus() {
		// this fails in e4 with current implementation of
		// SWTBotTreeItem.contextMenu
		// since "Open With" has submenus
		javaClassFileTreeItem().contextMenu("Open With");
	}
	
	@Test
	public void canAccessContextMenuCopyQualifiedName() {
		javaClassFileTreeItem().contextMenu("Copy Qualified Name");
	}
	
	@Test
	public void canAccessContextMenuSubmenu() {
		// this fails in e4 with current implementation of
		// SWTBotTreeItem.contextMenu
		// since "Open With" has submenus
		SWTBotMenu openWithMenu = javaClassFileTreeItem().contextMenu("Open With");
		openWithMenu.menu("Text Editor").click();
	}

	private SWTBotTreeItem javaClassFileTreeItem() {
		return packageExplorerTree().expandNode(PROJECT_NAME, "src",
				PACKAGE_NAME, CLASS_FILE_NAME);
	}

	private SWTBotTree packageExplorerTree() {
		return bot.viewByTitle("Package Explorer").bot().tree();
	}
}

Back to the top