/
EmfParsleySWTBotAbstractTests.java
1656 lines (1351 loc) · 54 KB
/
EmfParsleySWTBotAbstractTests.java
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* 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 contribution and API
*******************************************************************************/
package org.eclipse.emf.parsley.tests.swtbot;
import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellCloses;
import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive;
import static org.eclipse.xtext.ui.testing.util.IResourcesSetupUtil.cleanWorkspace;
import static org.eclipse.xtext.ui.testing.util.IResourcesSetupUtil.createFile;
import static org.eclipse.xtext.ui.testing.util.IResourcesSetupUtil.root;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.log4j.Logger;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.parsley.examples.library.Library;
import org.eclipse.emf.parsley.examples.views.EmfParsleyExamplesViewsActivator;
import org.eclipse.emf.parsley.junit4.ui.util.ImageTester;
import org.eclipse.emf.parsley.tests.swtbot.activator.EmfParsleySwtBotTestsActivator;
import org.eclipse.emf.parsley.tests.swtbot.views.TestOnSelectionLibraryTreeViewWithResourceURI;
import org.eclipse.emf.parsley.util.ActionBarsUtils;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.StatusLineManager;
import org.eclipse.jface.action.SubStatusLineManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.forms.finder.SWTFormsBot;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.finders.ContextMenuHelper;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.results.ListResult;
import org.eclipse.swtbot.swt.finder.results.WidgetResult;
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.ISaveablePart;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.WorkbenchException;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.xtext.ui.testing.util.IResourcesSetupUtil;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.junit.runner.RunWith;
/**
* @author Lorenzo Bettini
*
*/
@RunWith(SWTBotJunit4ClassRunner.class)
public abstract class EmfParsleySWTBotAbstractTests {
public static final String OPEN_DIALOG_SUBMIT = "Open";
public static final String PACKAGE_EXPLORER = "Package Explorer";
protected static final String EMF_PARSLEY_CATEGORY = "EMF Parsley";
protected static final String WRITER_LABEL = "Writer Lorenzo Bettini";
protected static final String WRITER_FIRSTNAME = "Lorenzo";
protected static final String WRITER_NAME = "Lorenzo Bettini";
protected static final String BORROWER_LABEL = "Borrower Bar";
protected static final String CUSTOM_BORROWER_LABEL = "Borrower: Foo";
protected static final String BOOK_LABEL = "Book Lorenzo's Book";
protected static final String BOOK_LABEL_CUSTOM = "Book: Lorenzo's Book";
protected static final String BOOK_TITLE = "Lorenzo's Book";
protected static final String LIBRARY_LABEL = "Library My Library";
protected static final String LIBRARY_NAME = "My Library";
protected static final String DAMAGED_VIDEO_LABEL = "Video Cassette My Damaged Video";
protected static final String OUTLINE_VIEW = "Outline";
protected static final String PARSLEY_MODEL_LABEL = "Model";
protected static final String PARSLEY_MODULE_LABEL = "Module MyTestModule";
protected static final String TEST_CONTAINER_LABEL = "Test Container";
protected static final String TEST_CONTAINER_SOURCE_LABEL = "Test Container Source Container";
protected static final String TEST_CONTAINER_TARGET_LABEL = "Test Container Target Container";
protected static final String TEST_CONTAINER_ELEMENT_TO_MOVE_LABEL = "Class With Name To Move";
protected static final String CLASS_FOR_CONTROLS_LABEL = "Class For Controls";
protected static final String STRING_FEATURE_LABEL = "String Feature";
protected static final String EMF_TREE_EDITOR = "EMF Tree Editor";
protected static final String EMF_TREE_EDITOR_XTEXT = "EMF Tree Editor Xtext";
protected static final String EMF_TREE_EDITOR_NO_MOUSE = "EMF Tree Editor No Mouse Events";
protected static final String EMF_TREE_EDITOR_OPEN_FORM_DIALOG = "EMF Tree Editor Opening Form Dialog";
protected static final String EMF_TREE_EDITOR_OPEN_DIALOG = "EMF Tree Editor Opening Dialog";
protected static final String EMF_TREE_EDITOR_OPEN_DIALOG_UNDOABLE = "EMF Tree Editor Dialog Undoable";
protected static final String EMF_TREE_EDITOR_CUSTOM_LABEL = "EMF Tree Editor Custom Label";
protected static final String EMF_CUSTOM_LIBRARY_EDITOR = "EMF Custom Library Editor";
protected static final String EMF_CUSTOM_MENU_LIBRARY_EDITOR = "EMF Custom Menu Library Editor";
protected static final String MY_EXTLIBRARY = "My.extlibrary";
protected static final String MY2_EXTLIBRARY = "My2.extlibrary";
protected static final String MY_PARSLEY = "My.parsley";
protected static final String MY_TEST_PROJECT = "MyTestProject";
protected static final String TEST_CONTAINER = "TestContainer.xmi";
protected static final String TEST_CONTAINER_FOR_DND = "TestContainerForDnD.xmi";
public static final String MY_EXTLIBRARY_RELATIVE_PATH = MY_TEST_PROJECT
+ "/" + MY_EXTLIBRARY;
public static final String MY2_EXTLIBRARY_RELATIVE_PATH = MY_TEST_PROJECT
+ "/" + MY2_EXTLIBRARY;
protected static final String MY_PARSLEY_RELATIVE_PATH = MY_TEST_PROJECT
+ "/" + MY_PARSLEY;
protected static final String MY_EXT_LIBRARY_PLATFORM_URI = "platform:/resource/"
+ MY_EXTLIBRARY_RELATIVE_PATH;
protected static final String MY_PARSLEY_PLATFORM_URI = "platform:/resource/"
+ MY_PARSLEY_RELATIVE_PATH;
public static final String TEST_CONTAINER_RELATIVE_PATH = MY_TEST_PROJECT
+ "/" + TEST_CONTAINER;
protected static final String TEST_CONTAINER_PLATFORM_URI = "platform:/resource/"
+ TEST_CONTAINER_RELATIVE_PATH;
public static final String TEST_CONTAINER_FOR_DND_RELATIVE_PATH = MY_TEST_PROJECT
+ "/" + TEST_CONTAINER_FOR_DND;
protected static final String TEST_CONTAINER_FOR_DND_PLATFORM_URI = "platform:/resource/"
+ TEST_CONTAINER_FOR_DND_RELATIVE_PATH;
protected static final String HARDCODED_LIBRARY_PLATFORM_URI = TestOnSelectionLibraryTreeViewWithResourceURI.resourceUri;
protected static final String LIBRARY_ON_SELECTION_TREE_VIEW_WITH_RESOURCE_URI = "TestOnSelectionLibraryTreeViewWithResourceURI";
protected static final String LIBRARY_ON_SELECTION_TREE_FORM_VIEW = "TestOnSelectionLibraryTreeFormView";
protected static final String LIBRARY_EMF_VIEW_CUSTOM_LABEL = "TestOnSelectionLibraryTreeViewWithResourceURI Custom Label";
protected static final String EMF_DETAIL_VIEW = "Emf Form View";
protected static final String EMF_DETAIL_READONLY_VIEW = "Emf Read Only Form View";
protected static final String EMF_TREE_FORM_DETAIL_VIEW = "Emf Tree Form View";
protected static final String LIBRARY_CUSTOM_DETAIL_VIEW = "Library Emf Detail View";
protected static final String LIBRARY_BOOKS_TABLE_VIEW = "Library Books Table View";
protected static final String LIBRARY_BOOKS_TABLE_FORM_VIEW = "Library Books Table Form View";
protected static final String LIBRARY_BOOKS_TABLE_VIEW_CUSTOM_PROVIDER = "Library Books Table View With Custom Content Provider";
protected static final String LIBRARY_BOOKS_TABLE_FORM_VIEW_CUSTOM_PROVIDER = "Library Books Table Form View With Custom Content Provider";
protected static final String TEST_SAVEABLE_TREE_FORM_VIEW = "Library Test Saveable Resource Tree Form View";
protected static final String TEST_SAVEABLE_TABLE_FORM_VIEW = "Library Test Saveable Resource Table Form View";
protected static final String TEST_SAVEABLE_TABLE_VIEW = "Library Test Saveable Table View";
protected static final String TEST_SAVEABLE_TREE_VIEW = "Library Test Saveable Tree View";
protected static final String TEST_SAVEABLE_TREE_WITH_COLUMNS_VIEW = "Library Test Saveable Tree View With Colunms";
protected static final String TEST_SAVEABLE_TREE_WITH_SPECIFIC_COLUMNS_VIEW = "Library Test Saveable Tree View With Specific Colunms";
protected static final String TEST_SAVEABLE_VIEW_WITH_CUSTOM_CONTENT_PROVIDER = "Library Tree View With Custom Content Provider";
protected static final String TEST_SAVEABLE_VIEW_WITH_CUSTOM_ELEMENTS_CONTENT_PROVIDER = "Library Tree View With Custom Elements Content Provider";
protected static final String CUSTOM_PROPOSALS_FORM_VIEW = "Custom Proposals Form View";
protected static final String WRITER_S_ADDRESS_TEXT = "writer's address";
protected static final String ADDRESS_LABEL = "Address";
protected static final String ADDRESS_COLUMN_HEADER = "address";
protected static final String BORROWERS_LABEL = "Borrowers";
protected static final String BORROWERS_COLUMN_HEADER = "borrowers";
protected static final String AUTHOR_LABEL = "Author";
protected static final String AUTHOR_COLUMN_HEADER = "author";
protected static final String FIRSTNAME_LABEL = "First Name";
protected static final String FIRSTNAME_COLUMN_HEADER = "firstName";
protected static final String DAMAGED_LABEL = "Damaged";
protected static final String CUSTOM_FIRSTNAME_LABEL = "First name";
protected static final String CUSTOM_SURNAME_LABEL = "Last name";
protected static final String LIBRARY_S_ADDRESS_TEXT = "Library's address";
protected static final String PEOPLE_LABEL = "people";
protected static final String PEOPLE_TEXT = WRITER_LABEL + ", "
+ BORROWER_LABEL;
protected static final String CUSTOM_PEOPLE_TEXT = WRITER_LABEL + ", "
+ CUSTOM_BORROWER_LABEL;
protected static final String ACTION_DELETE = "Delete";
protected static final String ACTION_VALIDATE = "Validate";
protected static final String ACTION_COPY = "Copy";
protected static final String ACTION_CUT = "Cut";
protected static final String ACTION_PASTE = "Paste";
// they have mnemonic so use a space after the string
protected static final String ACTION_REDO = "Redo ";
protected static final String ACTION_UNDO = "Undo ";
protected static final String BOOK_ON_TAPE = "Book On Tape";
protected static final String NEW_CHILD = "New Child";
protected static final String CUSTOM_NEW_BOOK = "New book";
protected static final String CUSTOM_NEW_BOOK_TITLE = "Book A new book";
protected static final String NEW_SIBLING = "New Sibling";
protected static final String EMF_PARSLEY_PROJECT = "EmfParsleyProject";
protected static final String NEW_EMF_PARSLEY_PROJECT = "EMF Parsley Project";
protected static final String NEW_EMF_PARSLEY_DSL_PROJECT = "EMF Parsley Dsl Based Project";
protected static final String EMF_PARSLEY_MAIL_RCP_EXAMPLE = "EMF Parsley Mail RCP Example";
protected static final String EMF_PARSLEY_FIRST_EXAMPLE = "EMF Parsley First Example";
protected static final String EMF_PARSLEY_VIEWS_EXAMPLES = "EMF Parsley Views Examples";
protected static final String EMF_PARSLEY_EDITORS_EXAMPLES = "EMF Parsley Editors Examples";
protected static final String EMF_PARSLEY_E4_EXAMPLE = "EMF Parsley Eclipse 4 Part Example";
protected static final String EMF_PARSLEY_CDO_SERVER_EXAMPLE = "EMF Parsley CDO Server Example";
protected static final String EMF_PARSLEY_CDO_EXAMPLE = "EMF Parsley CDO Example";
protected static final String EMF_PARSLEY_RAP_TP_EXAMPLE = "EMF Parsley RAP Target Platform Example";
protected static final String EMF_PARSLEY_RAP_CDO_EXAMPLE = "EMF Parsley RAP CDO Example";
protected static final String EMF_PARSLEY_RAP_EXAMPLE = "EMF Parsley RAP Example";
protected static final String TEST_ON_SELECTION_TREE_VIEW = "Test On Selection Tree View";
protected static final String TEST_MODEL_TREE_FORM_VIEW = "Test Model Tree Form View";
protected static final String TEST_MODEL_TREE_VIEW = "Test Model Tree View";
protected static final String TEST_MODEL_EDITABLE_TABLE_VIEW = "Test Model Editable Table View";
protected static final String NEW_OBJECT_FOR_VALIDATION = "Objects For Validation Class For Validation";
protected static final String OBJECT_FOR_VALIDATION = "Class For Validation";
protected static final String NOT_EMPTY_LABEL = "Not Empty";
protected static SWTWorkbenchBot bot;
protected static Map<String, String> editorNamesToId;
protected final Logger log;
@Rule
public TestRule showTestMethodNameRule = new TestWatcher() {
@Override
protected void starting(Description description) {
System.out.println("*** Starting test: " + description.getMethodName());
}
};
public EmfParsleySWTBotAbstractTests() {
log = Logger.getLogger(getClass());
// log.setLevel(Level.DEBUG);
}
@BeforeClass
public static void beforeClass() throws Exception {
// force loading of examples.views
EmfParsleyExamplesViewsActivator.getDefault();
bot = new SWTWorkbenchBot();
// increase timeout to 10 seconds
// SWTBotPreferences.TIMEOUT = 10000;
// in the launch configuration there will be no welcome view
// try {
// bot.viewByTitle("Welcome").close();
// } catch (WidgetNotFoundException e) {
// // OK!
// }
SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
closeWelcomePage();
editorNamesToId = new HashMap<String, String>();
editorNamesToId.put(EMF_TREE_EDITOR,
EmfParsleySwtBotTestsActivator.EMF_TREE_EDITOR);
editorNamesToId.put(EMF_TREE_EDITOR_XTEXT,
EmfParsleySwtBotTestsActivator.EMF_TREE_EDITOR_FOR_XTEXT);
editorNamesToId.put(EMF_TREE_EDITOR_NO_MOUSE,
EmfParsleySwtBotTestsActivator.EMF_TREE_EDITOR_NO_MOUSE_ID);
editorNamesToId.put(EMF_TREE_EDITOR_OPEN_FORM_DIALOG,
EmfParsleySwtBotTestsActivator.EMF_TREE_EDITOR_OPEN_FORM_DIALOG_ID);
editorNamesToId.put(EMF_TREE_EDITOR_OPEN_DIALOG,
EmfParsleySwtBotTestsActivator.EMF_TREE_EDITOR_OPEN_DIALOG_ID);
editorNamesToId.put(EMF_TREE_EDITOR_OPEN_DIALOG_UNDOABLE,
EmfParsleySwtBotTestsActivator.EMF_TREE_EDITOR_OPEN_DIALOG_UNDOABLE_ID);
editorNamesToId.put(EMF_TREE_EDITOR_CUSTOM_LABEL,
EmfParsleySwtBotTestsActivator.EMF_TREE_EDITOR_CUSTOM_LABEL);
editorNamesToId.put(EMF_CUSTOM_LIBRARY_EDITOR,
EmfParsleySwtBotTestsActivator.EMF_EDITOR_FOR_LIBRARY);
editorNamesToId.put(EMF_CUSTOM_MENU_LIBRARY_EDITOR,
EmfParsleySwtBotTestsActivator.EMF_EDITOR_FOR_MENU_LIBRARY);
openJavaPerspective();
/*
// Change the perspective via the Open Perspective dialog
bot.menu("Open Perspective").menu("Other...").click();
SWTBotShell openPerspectiveShell = bot.shell("Open Perspective");
openPerspectiveShell.activate();
if (isOxygen()) {
// they changed "OK" to "Open" in Oxygen
OPEN_DIALOG_SUBMIT = "Open";
}
// select the dialog
bot.table().select("Plug-in Development");
bot.button(OPEN_DIALOG_SUBMIT).click();
*/
// in SwtBot 2.2.0 we must use part name since the title
// of the problems view also contains the items count
// see also http://www.eclipse.org/forums/index.php/t/640194/
// Error Log view is disturbing since it often shows up
// and gets the focus, breaking many of our tests, so it's crucial
// to close it right away.
// Unfortunately, before Luna, the Error Log view was enabled by
// default in Plug-in Development perspective, but in Luna it is
// there anymore.
// if (!isLuna()) {
// bot.viewByPartName("Error Log").close();
// }
// bot.viewByPartName("Problems").show();
//
// bot.viewByTitle(OUTLINE_VIEW).show();
//
// openPackageExplorer();
// In Neon the Package Explorer is not part of the Plug-in Development perspective
// but in Kepler it is not available from the Window | Show View menu
// if (!isKepler()) {
// bot.menu("Window").menu("Show View").menu(PACKAGE_EXPLORER).click();
// }
}
@AfterClass
public static void clean() throws CoreException {
bot.resetWorkbench();
}
@After
public void runAfterEveryTest() throws Exception {
// bot.sleep(2000);
bot.saveAllEditors();
waitForJobs();
cleanWorkspace();
waitForJobs();
}
private void waitForJobs() {
bot.waitUntil(new DefaultCondition() {
@Override
public boolean test() throws Exception {
boolean idle = Job.getJobManager().isIdle();
if (!idle) {
log.info("Jobs still running...");
}
return idle;
}
@Override
public String getFailureMessage() {
printJobs();
return "Timed out waiting for jobs to finish.";
}
void printJobs() {
Job[] jobs = Job.getJobManager().find(null);
for (Job job : jobs) {
System.err.println("### JOBS: " + job.toString() + " state: " + job.getState());
}
}
}, SWTBotPreferences.TIMEOUT + SWTBotPreferences.TIMEOUT);
// waiting for Jobs might require lots of time, so better
// to double the timeout
}
private static void openJavaPerspective() throws InterruptedException {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
IWorkbench workbench = PlatformUI.getWorkbench();
try {
workbench.showPerspective("org.eclipse.jdt.ui.JavaPerspective",
workbench.getActiveWorkbenchWindow());
} catch (WorkbenchException e) {
e.printStackTrace();
}
}
});
}
// private static void openPDEPerspective() throws InterruptedException {
// Display.getDefault().syncExec(new Runnable() {
// @Override
// public void run() {
// try {
// IWorkbench workbench = PlatformUI.getWorkbench();
// workbench.showPerspective("org.eclipse.pde.ui.PDEPerspective",
// workbench.getActiveWorkbenchWindow());
// } catch (WorkbenchException e) {
// e.printStackTrace();
// }
// }
// });
// }
protected static void closeWelcomePage() throws InterruptedException {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
if (PlatformUI.getWorkbench().getIntroManager().getIntro() != null) {
PlatformUI
.getWorkbench()
.getIntroManager()
.closeIntro(
PlatformUI.getWorkbench().getIntroManager()
.getIntro());
}
}
});
}
protected static void openPackageExplorer() throws InterruptedException {
openViewById("org.eclipse.jdt.ui.PackageExplorer");
}
protected static void openViewById(final String viewId) throws InterruptedException {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
IWorkbench workbench = PlatformUI.getWorkbench();
try {
workbench.getActiveWorkbenchWindow().getActivePage().showView(viewId);
} catch (WorkbenchException e) {
e.printStackTrace();
}
}
});
}
protected static boolean isOxygen() {
// org.eclipse.ui has minor number 109 for Oxygen
return getOrgEclipseUiMinorVersion() >= 109;
}
protected static boolean isLuna() {
// org.eclipse.ui has minor number 106 for Luna
return getOrgEclipseUiMinorVersion() >= 106;
}
protected static boolean isIndigo() {
// org.eclipse.ui has minor number 7 for Indigo, and surely less than 100
return getOrgEclipseUiMinorVersion() < 100;
}
protected static boolean isKepler() {
int orgEclipseUiMinorVersion = getOrgEclipseUiMinorVersion();
return orgEclipseUiMinorVersion > 100 && orgEclipseUiMinorVersion < 106;
}
protected static int getOrgEclipseUiMinorVersion() {
return getPluginVersion(PlatformUI.PLUGIN_ID);
}
protected static int getOrgEclipseEmfEditUiMinorVersion() {
return getPluginVersion("org.eclipse.emf.edit.ui");
}
private static int getPluginVersion(String pluginId) {
String version = Platform.getBundle(pluginId).getHeaders()
.get("Bundle-Version");
Pattern versionPattern = Pattern.compile("\\d+\\.(\\d+)\\..*");
Matcher m = versionPattern.matcher(version);
if (m.matches()) {
return Integer.parseInt(m.group(1));
} else {
throw new RuntimeException("Can't parse version " + version);
}
}
protected void assertPropertyViewIsOpenedAndCloseIt() {
SWTBotView propertyView = bot.viewByTitle("Properties");
// bot.sleep(2000);
propertyView.close();
}
protected SWTBotTreeItem getLibraryWriterNode(SWTBotTreeItem editorTreeRoot) {
return getWriterNode(getLibraryNode(editorTreeRoot));
}
protected SWTBotTreeItem getLibraryBookNode(SWTBotTreeItem editorTreeRoot) {
return getBookNode(getLibraryNode(editorTreeRoot));
}
protected SWTBotTreeItem getBookNode(SWTBotTreeItem treeItem) {
return treeItem.expand().getNode(BOOK_LABEL);
}
protected SWTBotTreeItem getLibraryDamagedVideoCassetteNode(SWTBotTreeItem editorTreeRoot) {
return getDamagedVideoCassetteNode(getLibraryNode(editorTreeRoot));
}
protected SWTBotTreeItem accessTreeWithCustomLabels(SWTBotTreeItem rootOfTree) {
return rootOfTree.expand().getNode("TEST " + LIBRARY_LABEL + " ENDTEST")
.expand().getNode("TEST " + WRITER_LABEL + " ENDTEST");
}
protected SWTBotTreeItem accessTreeWithCustomLibraryLabels(
SWTBotTreeItem rootOfTree) {
return rootOfTree.expand().getNode(LIBRARY_LABEL).expand()
.getNode("Book: Lorenzo's Book");
}
protected SWTBotTreeItem getLibraryNode(final SWTBotTreeItem treeItem) {
return treeItem.expand().getNode(LIBRARY_LABEL);
}
protected SWTBotTreeItem getLibraryModifiedNode(final SWTBotTreeItem treeItem) {
return treeItem.expand().getNode(LIBRARY_LABEL + " MODIFIED");
}
protected SWTBotTreeItem getWriterNode(final SWTBotTreeItem treeItem) {
return treeItem.expand().getNode(WRITER_LABEL);
}
protected SWTBotTreeItem getDamagedVideoCassetteNode(final SWTBotTreeItem treeItem) {
return treeItem.expand().getNode(DAMAGED_VIDEO_LABEL);
}
protected SWTBotTreeItem getParsleyModelNode(final SWTBotTreeItem treeItem) {
return treeItem.expand().getNode(PARSLEY_MODEL_LABEL);
}
protected SWTBotTreeItem getParsleyModuleNode(final SWTBotTreeItem treeItem) {
return treeItem.expand().getNode(PARSLEY_MODULE_LABEL);
}
protected SWTBotTreeItem getClassForControlsNode(SWTBotTreeItem editorTreeRoot) {
return getTestContainerNode(editorTreeRoot).expand().
getNode(CLASS_FOR_CONTROLS_LABEL);
}
protected SWTBotTreeItem getTestContainerNode(final SWTBotTreeItem treeItem) {
return treeItem.expand().getNode(TEST_CONTAINER_LABEL);
}
protected void assertPropertyViewIsNotShown() {
try {
SWTBotView propertyView = bot.viewByTitle("Properties");
propertyView.close();
fail("Properties view should not show");
} catch (WidgetNotFoundException e) {
// OK!
}
}
protected SWTBotTreeItem getRootOfOutlineViewTree() {
SWTBotTree outlineTree = getRootOfTreeFromView(OUTLINE_VIEW);
return outlineTree.getTreeItem(MY_EXT_LIBRARY_PLATFORM_URI);
}
protected SWTBotTree getRootOfTreeFromView(String view) {
SWTBotView outlineView = bot.viewByTitle(view);
SWTBotTree outlineTree = outlineView.bot().tree();
return outlineTree;
}
protected SWTBotTreeItem openEditorAndGetTreeRoot(
String emfEditorContextMenuString, String fileName,
String treeRootLabel) throws CoreException,
InvocationTargetException, InterruptedException, IOException {
SWTBotTree tree = openEditorAndGetTree(emfEditorContextMenuString, fileName);
SWTBotTreeItem treeItemRoot = tree.getTreeItem(treeRootLabel);
return treeItemRoot;
}
protected SWTBotTree openEditorAndGetTree(String emfEditorContextMenuString,
String fileName) throws CoreException, InvocationTargetException,
InterruptedException, IOException {
SWTBotEditor editor = openEmfEditorOnTestFile(
emfEditorContextMenuString, fileName);
SWTBotTree tree = editor.bot().tree();
return tree;
}
protected SWTBotTreeItem getRootOfTreeEditor(String emfEditorContextMenuString,
String treeRootLabel)
throws CoreException, InvocationTargetException,
InterruptedException, IOException {
SWTBotTree tree = getEditorTree(emfEditorContextMenuString);
return tree.getTreeItem(treeRootLabel);
}
protected SWTBotTree getEditorTree(String emfEditorContextMenuString) {
SWTBotEditor editor = getEditor(emfEditorContextMenuString);
SWTBotTree tree = editor.bot().tree();
return tree;
}
/**
* Retrieves the "File" menu by using the shell of the active workbench window;
* this ensures that the active shell is not null (it happens often after the first test).
*
* @return
*/
protected SWTBotMenu fileMenu() {
return bot.shell().menu().menu("File");
}
/**
* Retrieves the "Window" menu by using the shell of the active workbench window;
* this ensures that the active shell is not null (it happens often after the first test).
*
* @return
*/
protected SWTBotMenu windowMenu() {
return bot.shell().menu().menu("Window");
}
/**
* Retrieves the "Edit" menu by using the shell of the active workbench window;
* this ensures that the active shell is not null (it happens often after the first test).
*
* @return
*/
protected SWTBotMenu editMenu() {
return bot.shell().menu().menu("Edit");
}
protected SWTBotEditor openEmfEditorOnTestFile(
String emfEditorContextMenuString, String fileName)
throws CoreException, InvocationTargetException,
InterruptedException, IOException {
createProjectAndTestFiles();
clickOnContextMenu(getFileItemFromTestProject(fileName), "Open With",
emfEditorContextMenuString);
// ContextMenuHelper.clickContextMenu(projectTree, "Open With",
// emfEditorContextMenuString);
// SWTBotMenu contextMenu = getFileItemFromTestProject(fileName)
// .contextMenu("Open With");
// getSubMenuItem(contextMenu, emfEditorContextMenuString).click();
SWTBotEditor editor = getEditor(emfEditorContextMenuString);
return editor;
}
protected void clickOnContextMenu(SWTBotTreeItem treeItem,
final String... texts) {
new SWTBotMenu(contextMenu(treeItem, texts)).click();
}
protected void clickOnContextMenu(SWTBotTable table,
final String... texts) {
new SWTBotMenu(contextMenu(table, texts)).click();
}
protected MenuItem contextMenu(final SWTBotTreeItem treeItem,
final String... texts) {
treeItem.select();
return contextMenu(getSWTBotTree(treeItem), texts);
}
protected SWTBotMenu contextMenu(final SWTBotEditor editor,
final String text) {
return new SWTBotMenu(
ContextMenuHelper.contextMenu(editor.toTextEditor().getStyledText(), text));
}
protected SWTBotTree getSWTBotTree(final SWTBotTreeItem treeItem) {
return new SWTBotTree(
UIThreadRunnable.syncExec(new WidgetResult<Tree>() {
@Override
public Tree run() {
return treeItem.widget.getParent();
}
}));
}
protected MenuItem contextMenu(SWTBotTree tree, final String... texts) {
return ContextMenuHelper.contextMenu(tree, texts);
}
protected MenuItem contextMenu(SWTBotTable table, final String... texts) {
return ContextMenuHelper.contextMenu(table, texts);
}
protected SWTBotEditor getEditor(String emfEditorContextMenuString) {
return bot.editorById(editorNamesToId.get(emfEditorContextMenuString));
}
protected SWTBotTreeItem getFileItemFromTestProject(String fileName) {
return getProjectTreeItem(MY_TEST_PROJECT).expand().getNode(fileName);
}
protected void createProjectAndTestFile() throws CoreException,
InvocationTargetException, InterruptedException, IOException {
createMyTestProject();
IFile file = createFile(MY_EXTLIBRARY_RELATIVE_PATH,
localFileContents(MY_EXTLIBRARY));
assertTrue(file.exists());
}
protected void createProjectAndTestFiles() throws CoreException,
InvocationTargetException, InterruptedException, IOException {
createProjectAndTestFile();
assertTrue(createFile(MY_PARSLEY_RELATIVE_PATH,
localFileContents(MY_PARSLEY)).exists());
assertTrue(createFile(TEST_CONTAINER_RELATIVE_PATH,
localFileContents(TEST_CONTAINER)).exists());
assertTrue(createFile(TEST_CONTAINER_FOR_DND_RELATIVE_PATH,
localFileContents(TEST_CONTAINER_FOR_DND)).exists());
}
protected String localFileContents(String string) throws IOException {
return EmfParsleySwtBotTestsActivator.localFileContents(string);
}
protected Library localLibrary(String extlibraryFileName) throws IOException {
Resource resource = localResource(extlibraryFileName);
return (Library) resource.getContents().get(0);
}
protected Resource localResource(String extlibraryFileName)
throws IOException {
File file = EmfParsleySwtBotTestsActivator.localFile(extlibraryFileName);
URI uri = URI.createFileURI(file.getAbsolutePath());
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.getResource(uri, true);
return resource;
}
protected void createMyTestProject() {
createProjectWithoutTemplateInWorkspace("General", "Project", MY_TEST_PROJECT);
}
protected void createProjectInWorkspace(String category,
String projectType, String projectName) {
SWTBotShell shell = createNewProjectWizard(category, projectType,
projectName);
bot.button("Finish").click();
waitForShellToClose(shell);
assertProjectIsCreated(projectName, shell);
}
protected void createProjectWithoutTemplateInWorkspace(String category,
String projectType, String projectName) {
SWTBotShell shell = createNewProjectWizard(category, projectType,
projectName);
//deselect template check
bot.checkBox(1).deselect();
bot.button("Finish").click();
waitForShellToClose(shell);
assertProjectIsCreated(projectName, shell);
}
protected void createProjectWithTemplateInWorkspace(String category,
String projectType, String projectName, String template) {
SWTBotShell shell = createNewProjectWizard(category, projectType,
projectName);
bot.button("Next >").click();
bot.table().select(template);
bot.button("Finish").click();
waitForShellToClose(shell);
assertProjectIsCreated(projectName, shell);
}
protected void createExampleProjectsInWorkspace(String exampleDescription,
String... expectedProjects) {
fileMenu().menu("New").menu("Project...").click();
SWTBotShell shell = bot.shell("New Project");
shell.activate();
bot.waitUntil(shellIsActive("New Project"));
expandNodeSync(bot.tree(), EMF_PARSLEY_CATEGORY, "Examples")
.select(exampleDescription);
bot.button("Next >").click();
bot.button("Finish").click();
waitForShellToClose(shell);
for (String projectName : expectedProjects) {
assertProjectIsCreated(projectName, shell);
}
}
protected void createProjectInWorkspaceWithView(String category,
String projectType, String projectName, String viewToSelect) {
SWTBotShell shell = createNewProjectWizard(category, projectType,
projectName);
// advance to the second page
bot.button("Next >").click();
if (viewToSelect != null) {
bot.radio(viewToSelect).click();
}
bot.button("Finish").click();
waitForShellToClose(shell);
assertProjectIsCreated(projectName, shell);
}
protected SWTBotShell createNewProjectWizard(String category,
String projectType, String projectName) {
fileMenu().menu("New").menu("Project...").click();
SWTBotShell shell = bot.shell("New Project");
shell.activate();
bot.waitUntil(shellIsActive("New Project"));
expandNodeSync(bot.tree(), category).select(projectType);
bot.button("Next >").click();
bot.textWithLabel("Project name:").setText(projectName);
return shell;
}
protected SWTBotShell createNewProjectWizard(String category,
String subCategory, String projectType, String projectName) {
fileMenu().menu("New").menu("Project...").click();
SWTBotShell shell = bot.shell("New Project");
shell.activate();
bot.waitUntil(shellIsActive("New Project"));
expandNodeSync(bot.tree(), category, subCategory).select(projectType);
bot.button("Next >").click();
bot.textWithLabel("Project name:").setText(projectName);
return shell;
}
protected void assertProjectIsCreated(String projectName, SWTBotShell shell) {
waitForShellToClose(shell);
assertProjectIsCreated(projectName);
}
protected void assertProjectIsCreated(String projectName) {
assertTrue("Project doesn't exist: " + projectName, isProjectCreated(projectName));
}
protected void waitForBuild() throws CoreException {
waitForJobs();
bot.waitUntil(new DefaultCondition() {
private AssertionError error;
@Override
public boolean test() throws Exception {
IResourcesSetupUtil.fullBuild();
try {
assertNoIssuesInProject();
} catch (AssertionError error) {
this.error = error;
System.err.println("errors: " + error.getMessage());
System.err.println("retrying...");
// ensure that all queued workspace operations and locks are released
try {
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
// nothing to do!
}
}, new NullProgressMonitor());
} catch (CoreException e) {
e.printStackTrace();
}
// IResourcesSetupUtil.cleanBuild();