-
Notifications
You must be signed in to change notification settings - Fork 20
/
CreateSingleSequentialLanguageFromOfficialFSM_Test.xtend
249 lines (204 loc) · 9.58 KB
/
CreateSingleSequentialLanguageFromOfficialFSM_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
/*******************************************************************************
* 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.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.
*/
@RunWith(SWTBotJunit4ClassRunner)
@FixMethodOrder(MethodSorters::NAME_ASCENDING)
class CreateSingleSequentialLanguageFromOfficialFSM_Test extends AbstractXtextTests
{
static WorkspaceTestHelper helper = new WorkspaceTestHelper
static final String BASE_FOLDER_NAME = "tests-inputs-gen/SequentialFSM"
static final String BASE_NAME = "org.eclipse.gemoc.example.melangek3fsm"
static final String SOURCE_PROJECT_NAME = BASE_NAME + ".fsm"
static final String PROJECT_NAME = BASE_NAME + ".xfsm"
static SWTWorkbenchBot bot;
static MessagingSystem messaggingSystem
@Rule public TestName testName = new TestName();
@BeforeClass
def static void beforeClass() throws Exception {
GEMOCTestVideoHelper.addTestSuiteVideoLog("starting "+CreateSingleSequentialLanguageFromOfficialFSM_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(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
WorkspaceTestHelper::reallyWaitForJobs(2)
IResourcesSetupUtil::reallyWaitForAutoBuild
helper.deployProject(SOURCE_PROJECT_NAME+".model",BASE_FOLDER_NAME+"/"+SOURCE_PROJECT_NAME+".model.zip")
helper.deployProject(SOURCE_PROJECT_NAME+".k3dsa",BASE_FOLDER_NAME+"/"+SOURCE_PROJECT_NAME+".k3dsa.zip")
WorkspaceTestHelper::reallyWaitForJobs(2)
IResourcesSetupUtil::reallyWaitForAutoBuild
IResourcesSetupUtil::fullBuild
IResourcesSetupUtil::reallyWaitForAutoBuild
WorkspaceTestHelper::reallyWaitForJobs(4)
}
@Rule
public TailWorkspaceLogToStderrRule workspaceLogRule = new TailWorkspaceLogToStderrRule();
@Before
override setUp() {
GEMOCTestVideoHelper.addTestSuiteVideoLog(" - "+testName.methodName);
helper.setTargetPlatform
bot.resetWorkbench
// 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")
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(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 ...
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)
]
// normally, we are now on the table
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(SOURCE_PROJECT_NAME + ".model").expand();
bot.tree().getTreeItem(SOURCE_PROJECT_NAME + ".model").getNode("model").expand();
bot.tree().getTreeItem(SOURCE_PROJECT_NAME + ".model").getNode("model").getNode("fsm.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(4)
helper.assertProjectExists(PROJECT_NAME);
IResourcesSetupUtil.reallyWaitForAutoBuild();
helper.assertNoMarkers();
}
@Test
def void test04_CreateTraceAddon() throws Exception {
val projExplorerBot = bot.viewByTitle("Project Explorer").bot
val SWTBotTreeItem projectItem = projExplorerBot.tree().getTreeItem(PROJECT_NAME).select();
projectItem.contextMenu("GEMOC Language").menu("Generate Multidimensional Trace Addon project for language")
.click();
bot.button("OK").click();
IResourcesSetupUtil::reallyWaitForAutoBuild
WorkspaceTestHelper::waitForJobs
helper.assertProjectExists(PROJECT_NAME + ".trace");
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(PROJECT_NAME).select();
projectItem.contextMenu("GEMOC Language").menu("Create Sirius Editor Project for language").click();
bot.button("Finish").click();
IResourcesSetupUtil::reallyWaitForAutoBuild
WorkspaceTestHelper::waitForJobs
helper.assertProjectExists(PROJECT_NAME + ".design");
bot.editorByTitle("xfsm.odesign").show();
//bot.tree().getTreeItem("platform:/resource/"+PROJECT_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)
}
});
}
}