-
Notifications
You must be signed in to change notification settings - Fork 20
/
CreateSequentialLanguageFromOfficialK3FSM_Test.xtend
320 lines (279 loc) · 13.5 KB
/
CreateSequentialLanguageFromOfficialK3FSM_Test.xtend
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*******************************************************************************
* Copyright (c) 2016, 2017 Inria 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:
* Inria - initial API and implementation
*******************************************************************************/
package org.eclipse.gemoc.studio.tests.system.lwb.userstory
import org.eclipse.core.resources.ResourcesPlugin
import org.eclipse.core.runtime.NullProgressMonitor
import org.eclipse.gemoc.commons.eclipse.core.resources.IFileUtils
import org.eclipse.gemoc.execution.sequential.javaxdsml.ide.ui.templates.WizardTemplateMessages
import org.eclipse.gemoc.xdsmlframework.ide.ui.XDSMLFrameworkUI
import org.eclipse.gemoc.xdsmlframework.test.lib.TailWorkspaceLogToStderrRule
import org.eclipse.gemoc.xdsmlframework.test.lib.WorkspaceTestHelper
import org.eclipse.swt.widgets.Display
import org.eclipse.swt.widgets.Table
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner
import org.eclipse.swtbot.swt.finder.keyboard.Keyboard
import org.eclipse.swtbot.swt.finder.keyboard.KeyboardFactory
import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem
import org.eclipse.xtext.junit4.AbstractXtextTests
import org.eclipse.xtext.ui.testing.util.IResourcesSetupUtil
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
import org.junit.FixMethodOrder
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import static org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences.*
import org.eclipse.gemoc.xdsmlframework.test.lib.GEMOCTestVideoHelper
import org.eclipse.gemoc.commons.eclipse.messagingsystem.api.MessagingSystemManager
import org.eclipse.gemoc.commons.eclipse.messagingsystem.api.MessagingSystem
import org.junit.rules.TestName
/**
* This class check a scenario where we reuse some of the base projects of the official sample : MelangeK3FSM
* in order to create a new language.
* The tests are ordered and a failure in the initial tests will most likely make fail the following ones.
* As much as possible, this test tries to follow the DIY section in the K3FSM documentation
*/
@RunWith(SWTBotJunit4ClassRunner)
@FixMethodOrder(MethodSorters::NAME_ASCENDING)
class CreateSequentialLanguageFromOfficialK3FSM_Test extends AbstractXtextTests {
static WorkspaceTestHelper helper = new WorkspaceTestHelper
static final String BASE_FOLDER_NAME = "tests-inputs-gen/K3FSM"
static final String BASE_NAME = "org.eclipse.gemoc.example.k3fsm"
static final String MODEL_PROJECT_NAME = BASE_NAME
static final String XDSML_PROJECT_NAME = BASE_NAME + ".xdsml"
static final String XTEXT_PROJECT_NAME = BASE_NAME + ".xtext"
static SWTWorkbenchBot bot
static MessagingSystem messaggingSystem
@Rule public TestName testName = new TestName();
@BeforeClass
def static void beforeClass() throws Exception {
GEMOCTestVideoHelper.addTestSuiteVideoLog("starting "+CreateSequentialLanguageFromOfficialK3FSM_Test.canonicalName);
helper.waitWorkbench // useful especially for the first test suite that starts the workbench
val MessagingSystemManager msm = new MessagingSystemManager()
messaggingSystem = msm.createBestPlatformMessagingSystem("","");
messaggingSystem.important(CreateSequentialLanguageFromOfficialK3FSM_Test.canonicalName,"")
messaggingSystem.important(System.getProperty("user.dir"),"")
helper.init
bot = new SWTWorkbenchBot()
// Set the SWTBot timeout
SWTBotPreferences.TIMEOUT = WorkspaceTestHelper.SWTBotPreferencesTIMEOUT_4_GEMOC;
helper.setTargetPlatform
bot.resetWorkbench
WorkspaceTestHelper::forceCleanPreviousWorkspaceContent
messaggingSystem.important("user.dir="+System.getProperty("user.dir"),"")
messaggingSystem.focus();
WorkspaceTestHelper::reallyWaitForJobs(2)
IResourcesSetupUtil::reallyWaitForAutoBuild
helper.deployProject(CreateSequentialLanguageFromOfficialK3FSM_Test.MODEL_PROJECT_NAME,
BASE_FOLDER_NAME + "/" + CreateSequentialLanguageFromOfficialK3FSM_Test.MODEL_PROJECT_NAME + ".zip")
helper.deployProject(CreateSequentialLanguageFromOfficialK3FSM_Test.MODEL_PROJECT_NAME + ".k3dsa",
BASE_FOLDER_NAME + "/" + CreateSequentialLanguageFromOfficialK3FSM_Test.MODEL_PROJECT_NAME + ".k3dsa.zip")
WorkspaceTestHelper::reallyWaitForJobs(2)
IResourcesSetupUtil::reallyWaitForAutoBuild
IResourcesSetupUtil::fullBuild
IResourcesSetupUtil::reallyWaitForAutoBuild
WorkspaceTestHelper::reallyWaitForJobs(2)
}
@Rule
public TailWorkspaceLogToStderrRule workspaceLogRule = new TailWorkspaceLogToStderrRule();
@Before
override setUp() {
GEMOCTestVideoHelper.addTestSuiteVideoLog(" - "+testName.methodName);
helper.setTargetPlatform
bot.resetWorkbench
messaggingSystem.important(testName.methodName,"")
messaggingSystem.focus()
// helps to reset the workspace state by closing menu as bot.resetWorkbench is not enough
val Keyboard key = KeyboardFactory.getSWTKeyboard();
key.pressShortcut(Keystrokes.ESC);
// make sure we are on the correct perspective
bot.perspectiveById(XDSMLFrameworkUI.ID_PERSPECTIVE).activate()
bot.viewByTitle("Project Explorer").bot
IResourcesSetupUtil::reallyWaitForAutoBuild
WorkspaceTestHelper::reallyWaitForJobs(4)
}
@After
override tearDown() {
// Nothing to do
}
@Test
def void test01_OpenXDSMLPerspective() throws Exception {
bot.perspectiveById(XDSMLFrameworkUI.ID_PERSPECTIVE).activate()
helper.assertContains("Menu does not contain", "GEMOC Java xDSML Project",
bot.menu("File").menu("New").menuItems())
}
@Test
def void test02_CreateSequentialLanguageProject() {
IResourcesSetupUtil::reallyWaitForAutoBuild
bot.menu("File").menu("New").menu("GEMOC Java xDSML Project").click();
bot.text().setText(CreateSequentialLanguageFromOfficialK3FSM_Test.XDSML_PROJECT_NAME);
bot.button("Next >").click();
// bot.table(0).select("Simple GEMOC sequential project");
// bot.tree().getTreeItem("Simple GEMOC sequential project").click();
// bot.list().items
// Cant find a way to correctly select the table item, so let's workaround by using keystrokes
// this is ugly but seems to work ...
selectTabWidgetByKeyStroke()
// normally, we are now on the table
val Keyboard key = KeyboardFactory.getSWTKeyboard();
Display.getDefault().syncExec(new Runnable() {
override void run() {
val Table table = bot.focusedWidget as Table
table.items.forEach[i|println(i + " " + i.text)]
val index = table.items.indexOf(table.items.findFirst [ item |
item.text.contains(WizardTemplateMessages.SequentialSingleLanguageTemplate_title)
])
// warning! the string actually comes from wizard name declared in the plugin.xml so make sure to have the same in the title !
println("index of " + WizardTemplateMessages.SequentialSingleLanguageTemplate_title + " =" + index)
// TODO assert if not found
// table.select(index) // does not seem to work
// bot.table.select(index) // does not seem to work too :-(
for (var i = 0; i < table.itemCount; i++) {
key.pressShortcut(Keystrokes.UP)
}
for (var i = 0; i < index; i++) {
key.pressShortcut(Keystrokes.DOWN)
}
}
})
printFocusedWidget
bot.sleep(2000)
// val TemplateListSelectionPage templatePage = bot.widget(widgetOfType(TemplateListSelectionPage.class))
bot.button("Next >").click();
bot.textWithLabel("&Package name(*)").setText(BASE_NAME);
val activeShell = bot.activeShell // the focus is lost after click on "Browse..."
bot.button("Browse...", 0).click();
// bot.shell("File Selection").activate();
bot.tree().getTreeItem(CreateSequentialLanguageFromOfficialK3FSM_Test.MODEL_PROJECT_NAME).expand();
bot.tree().getTreeItem(CreateSequentialLanguageFromOfficialK3FSM_Test.MODEL_PROJECT_NAME).getNode("model").
expand();
bot.tree().getTreeItem(CreateSequentialLanguageFromOfficialK3FSM_Test.MODEL_PROJECT_NAME).getNode("model").
getNode("k3fsm.ecore").click();
bot.button("OK").click();
activeShell.bot.button("Browse...", 1).click();
bot.button("OK").click();
/* or
* bot.textWithLabel("&Ecore file location").setText(SOURCE_PROJECT_NAME + ".model/model/fsm.ecore");
* bot.textWithLabel("K3 DSA Project name").setText(SOURCE_PROJECT_NAME + ".k3dsa");
*/
activeShell.bot.button("Finish").click()
// bot.button("Finish").click();
IResourcesSetupUtil::reallyWaitForAutoBuild
WorkspaceTestHelper::reallyWaitForJobs(2)
helper.assertProjectExists(CreateSequentialLanguageFromOfficialK3FSM_Test.XDSML_PROJECT_NAME);
IResourcesSetupUtil.reallyWaitForAutoBuild();
helper.assertNoMarkers();
}
@Test
def void test03_CreateTreeEditor() throws Exception {
bot.tree().getTreeItem("org.eclipse.gemoc.example.k3fsm").expand();
bot.tree().getTreeItem("org.eclipse.gemoc.example.k3fsm").getNode("model").expand();
val projectItem = bot.tree().getTreeItem("org.eclipse.gemoc.example.k3fsm").getNode("model").getNode(
"k3fsm.genmodel").select();
projectItem.contextMenu("Open").click();
val genModelEditor = bot.editorByTitle("k3fsm.genmodel")
genModelEditor.show
genModelEditor.setFocus
val genModelPackageItem = genModelEditor.bot.tree().getTreeItem("K3fsm").select();
genModelPackageItem.contextMenu("Generate All").click();
IResourcesSetupUtil::reallyWaitForAutoBuild
WorkspaceTestHelper::reallyWaitForJobs(2)
helper.assertProjectExists(MODEL_PROJECT_NAME + ".edit");
helper.assertProjectExists(MODEL_PROJECT_NAME + ".editor");
helper.assertNoMarkers();
}
@Test
def void test04_CreateTextualEditor() throws Exception {
val SWTBotTreeItem projectItem = bot.tree().getTreeItem("org.eclipse.gemoc.example.k3fsm.xdsml").select();
projectItem.contextMenu("GEMOC Language").menu("Create XText Editor Project for language").click();
bot.button("Add...").click();
selectTabWidgetByKeyStroke()
// normally, we are now on the table
val Keyboard key = KeyboardFactory.getSWTKeyboard();
// press space to select the first entry
key.pressShortcut((Keystrokes.SPACE))
bot.button("OK").click();
bot.button("Next >").click();
bot.textWithLabel("&Project name:").setText(XTEXT_PROJECT_NAME);
bot.textWithLabel("Name:").setText(BASE_NAME + ".K3FSM");
bot.textWithLabel("Extensions:").setText("k3fsm");
bot.button("Next >").click();
bot.button("Finish").click();
IResourcesSetupUtil::reallyWaitForAutoBuild
WorkspaceTestHelper::reallyWaitForJobs(4)
// workaround for https://github.com/eclipse/gemoc-studio/issues/14 we currently need to manually replace the nsUri by a platform uri
val xtexFile = ResourcesPlugin::workspace.root.getProject(XTEXT_PROJECT_NAME).getFile("src/org/eclipse/gemoc/example/k3fsm/K3FSM.xtext")
assertTrue(xtexFile.exists)
IFileUtils.writeInFileIfDifferent(xtexFile,
IFileUtils.getStringContent(xtexFile).replaceFirst(
'import "http://www.eclipse.org/gemoc/example/k3fsm"',
'import "platform:/resource/org.eclipse.gemoc.example.k3fsm/model/k3fsm.ecore"'),
new NullProgressMonitor)
helper.assertProjectExists(XTEXT_PROJECT_NAME);
helper.assertProjectExists(XTEXT_PROJECT_NAME + ".ide");
helper.assertProjectExists(XTEXT_PROJECT_NAME + ".ui");
bot.tree().getTreeItem(XTEXT_PROJECT_NAME).select();
bot.tree().getTreeItem(XTEXT_PROJECT_NAME).expand();
bot.tree().getTreeItem(XTEXT_PROJECT_NAME).getNode("src").expand();
bot.tree().getTreeItem(XTEXT_PROJECT_NAME).getNode("src").getNode(BASE_NAME).expand();
val SWTBotTreeItem mwe2Item = bot.tree().getTreeItem(XTEXT_PROJECT_NAME).getNode("src").getNode(BASE_NAME).
getNode("GenerateK3FSM.mwe2").select();
mwe2Item.contextMenu("Run As").menu("1 MWE2 Workflow").click();
IResourcesSetupUtil::reallyWaitForAutoBuild
WorkspaceTestHelper::reallyWaitForJobs(2)
helper.assertNoMarkers();
}
/**
* This test use the GEMOC menu to create a Sirius editor for a language
* @throws Exception
*/
@Test
def void test05_CreateSiriusEditorForLanguage() throws Exception {
val SWTBotTreeItem projectItem = bot.tree().getTreeItem(XDSML_PROJECT_NAME).select();
projectItem.contextMenu("GEMOC Language").menu("Create Sirius Editor Project for language").click();
bot.button("Finish").click();
IResourcesSetupUtil::reallyWaitForAutoBuild
WorkspaceTestHelper::reallyWaitForJobs(2)
helper.assertProjectExists(CreateSequentialLanguageFromOfficialK3FSM_Test.BASE_NAME + ".design");
bot.editorByTitle("k3fsm.odesign").show();
/*bot.tree().getTreeItem(
"platform:/resource/" + CreateSequentialLanguageFromOfficialK3FSM_Test.BASE_NAME +
".design/description/xfsm.odesign").expand();
*/
// TODO recreate a basic representation in the default layer
helper.assertNoMarkers();
}
def printFocusedWidget() {
Display.getDefault().syncExec(new Runnable() {
override void run() {
System.out.println(
"Focused Widget = " + bot.focusedWidget.toString + " " + bot.focusedWidget.class)
}
});
}
def selectTabWidgetByKeyStroke() {
// Cant find a way to correctly select the table item, so let's workaround by using keystrokes
// this is ugly but seems to work ...
printFocusedWidget
bot.sleep(500)
val Keyboard key = KeyboardFactory.getSWTKeyboard();
(1 .. 10).takeWhile[!( bot.focusedWidget instanceof Table)].forEach [ i |
key.pressShortcut(Keystrokes.TAB)
printFocusedWidget
bot.sleep(500)
]
}
}