Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d638f475743fdf5a505c2a9031d5f2617480674f (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*******************************************************************************
 * Copyright (c) 2013 RCP Vision (http://www.rcp-vision.com) and others.
 * 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.emf.parsley.dsl.ui.tests

import com.google.inject.Inject
import com.google.inject.Provider
import org.eclipse.core.resources.IProject
import org.eclipse.emf.parsley.dsl.generator.EmfParsleyDslOutputConfigurationProvider
import org.eclipse.emf.parsley.dsl.tests.util.ui.PluginProjectHelper
import org.eclipse.emf.parsley.dsl.tests.util.ui.TestableEmfParsleyDslNewProjectWizard
import org.eclipse.emf.parsley.tests.pde.utils.PDETargetPlatformUtils
import org.eclipse.jface.viewers.StructuredSelection
import org.eclipse.jface.wizard.Wizard
import org.eclipse.jface.wizard.WizardDialog
import org.eclipse.ui.PlatformUI
import org.eclipse.xtext.ui.testing.AbstractWorkbenchTest
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith

import static org.eclipse.emf.parsley.dsl.generator.EmfParsleyDslOutputConfigurationProvider.*
import static org.eclipse.emf.parsley.dsl.tests.util.ui.TestableEmfParsleyDslNewProjectWizard.*
import static org.eclipse.xtext.ui.testing.util.IResourcesSetupUtil.*

/**
 * @author Lorenzo Bettini
 */
@RunWith(typeof(XtextRunner))
@InjectWith(typeof(EmfParsleyDslUiInjectorProvider))
class EmfParsleyDslWorkbenchTest extends AbstractWorkbenchTest {

	@Inject Provider<TestableEmfParsleyDslNewProjectWizard> wizardProvider

	@Inject PluginProjectHelper projectHelper

	val TEST_MODULE = TestableEmfParsleyDslNewProjectWizard.TEST_PROJECT + "/" +
		TestableEmfParsleyDslNewProjectWizard.TEST_PROJECT.toFirstUpper + ".parsley"

	val TEST_PLUGIN_XML_GEN = 
		EmfParsleyDslOutputConfigurationProvider.EMFPARSLEY_GEN + "/" + TEST_PROJECT + "/" +
		EmfParsleyDslOutputConfigurationProvider.PLUGIN_XML_GEN_FILE

	/**
	 * Create the wizard dialog, open it and press Finish.
	 */
	def protected int createAndFinishWizardDialog(Wizard wizard) {
		val dialog = new WizardDialog(wizard.shell, wizard) {
			override open() {
				val thread = new Thread("Press Finish") {
					override run() {
						// wait for the shell to become active
						while (getShell() === null) {
							Thread.sleep(1000)
						}
						getShell().getDisplay().asyncExec[
							finishPressed();
						]					
					}			
				};
				thread.start();
				return super.open();
			}
		};
		return dialog.open();
	}

//	@Before
//	override setUp() throws Exception {
//		super.setUp()
//		projectHelper.clearJdtIndex
//	}

	@BeforeClass
	def static void beforeClass() {
		PDETargetPlatformUtils.setTargetPlatform();
	}

	@Test def void testEmfParsleyDslNewProjectWizard() {
		createProjectWithNewProjectWizard
		projectHelper.assertNoErrors
	}

	@Test def void testPluginXmlGeneration() {
		val project = createProjectWithNewProjectWizard
		project.modifyParsleyModuleFile(
'''
module «TEST_PROJECT» {
	
	// parts should trigger generation of «PLUGIN_XML_GEN_FILE»
	
	parts {
		viewpart id {
			viewname "View Name"
			viewclass org.eclipse.emf.parsley.views.AbstractSaveableTreeView
			// viewcategory my.category
		}
	}
}
'''
		)
		waitForBuild
		
		assertTrue(project.getFile(TEST_PLUGIN_XML_GEN).exists())
		assertTrue(project.getFile("/plugin.xml").exists())
		
		project.modifyParsleyModuleFile(
'''
module «TEST_PROJECT» {
	// removed parts
	
	// «PLUGIN_XML_GEN_FILE» should be removed
}
'''		
		)
		waitForBuild

		assertFalse(project.getFile(TEST_PLUGIN_XML_GEN).exists())
		// plugin.xml should still be there
		assertTrue(project.getFile("/plugin.xml").exists())
	}

	def private createProjectWithNewProjectWizard() {
		val wizard = wizardProvider.get
		wizard.init(PlatformUI.getWorkbench(), new StructuredSelection());
		createAndFinishWizardDialog(wizard)
		val project = root.getProject(TEST_PROJECT)
		assertTrue(project.exists())
		cleanBuild
		waitForBuild
		return project
	}

	def private modifyParsleyModuleFile(IProject project, CharSequence newcontents) {
		val srcFolder = project.getFolder("src")
		val file = srcFolder.getFile(TEST_MODULE)
		assertTrue(file.exists())
		createFile(file.fullPath, newcontents.toString)
		return project
	}

}

Back to the top