Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e21b6e450fc8d6617da4388c473dbfa47e5c405c (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
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
package org.eclipse.jpt.jpadiagrameditor.swtbot.tests.ui.editor;

import static org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable.asyncExec;
import static org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable.syncExec;
import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.awt.AWTException;
import java.awt.Robot;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.gef.LayerConstants;
import org.eclipse.gef.editparts.ScalableFreeformRootEditPart;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.ui.internal.contextbuttons.ContextButton;
import org.eclipse.graphiti.ui.internal.contextbuttons.ContextButtonPad;
import org.eclipse.graphiti.ui.internal.parts.DiagramEditPart;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IsARelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.eclipse.gef.finder.SWTGefBot;
import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefConnectionEditPart;
import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart;
import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
import org.eclipse.swtbot.swt.finder.utils.Position;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotStyledText;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;

public class EditorProxy {
	
	private final SWTWorkbenchBot workbenchBot;
	protected SWTGefBot bot;


	/**
	 * Create proxy object.
	 *
	 * @param bot
	 */
	public EditorProxy(SWTWorkbenchBot workbenchBot, SWTGefBot bot) {
		this.workbenchBot = workbenchBot;
		this.bot = bot;
	}
	
	public SWTBotGefEditor openDiagramOnJPAContentNode(String name) {
		SWTBotTree projectTree = workbenchBot.viewByTitle("Project Explorer").bot().tree();
		projectTree.expandNode(name).expandNode("JPA Content").select();
		ContextMenuHelper.clickContextMenu(projectTree, "Open Diagram");
		
		workbenchBot.waitUntil(shellIsActive(JPAEditorMessages.OpenJpaDiagramActionDelegate_jpaSupportWarningTitle), 5000);
		SWTBotShell jpaSupportWarningDialog = workbenchBot.shell(JPAEditorMessages.OpenJpaDiagramActionDelegate_jpaSupportWarningTitle);
		getOkButton(jpaSupportWarningDialog).click();
		
		SWTBotGefEditor jpaDiagramEditor = bot.gefEditor(name);
		assertFalse("Editor must not be dirty!", jpaDiagramEditor.isDirty());
		
		List<SWTBotGefEditPart> entities = jpaDiagramEditor.mainEditPart().children();
		assertTrue("Editor must not contains any entities!", entities.isEmpty());
		
		return jpaDiagramEditor;
	}
	
	public SWTBotGefEditor openDiagramOnJPAProjectNode(String name) {
		SWTBotTree projectTree = workbenchBot.viewByTitle("Project Explorer").bot().tree();
		projectTree.expandNode(name).select();
		ContextMenuHelper.clickContextMenu(projectTree, "JPA Tools", "Open Diagram");
		
		workbenchBot.waitUntil(shellIsActive(JPAEditorMessages.OpenJpaDiagramActionDelegate_jpaSupportWarningTitle), 5000);
		SWTBotShell jpaSupportWarningDialog = workbenchBot.shell(JPAEditorMessages.OpenJpaDiagramActionDelegate_jpaSupportWarningTitle);
		getOkButton(jpaSupportWarningDialog).click();
		
		SWTBotGefEditor jpaDiagramEditor = bot.gefEditor(name);
		assertFalse("Editor must not be dirty!", jpaDiagramEditor.isDirty());
		return jpaDiagramEditor;
	}
	
	/**
	 * Gets the "Select Type" dialog that appears when the attribute's context menu
	 * "Refactor Attribute Type..." is selected
	 * @param jpaDiagramEditor
	 * @param attribute
	 * @return the "Select Type" dialog
	 */
	public SWTBotShell getSelectNewAttributeTypeDialog(final SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart attribute) {
		attribute.click();
		jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_refactorAttributeType);
		
		workbenchBot.waitUntil(shellIsActive(JPAEditorMessages.SelectTypeDialog_chooseAttributeTypeDialogWindowTitle), 5000);
		SWTBotShell changeTypeDialog = workbenchBot.shell(JPAEditorMessages.SelectTypeDialog_chooseAttributeTypeDialogWindowTitle);
		getNewTypeInputField(changeTypeDialog);
		return changeTypeDialog;
	}

	/**
	 * Gets the text input field of the "Select Type" dialog, which appears when
	 * the attribute's context menu "Refcator Attribute Type..." is selected
	 * @param changeTypeDialog - the "Select Type" dialog
	 * @return the text input field
	 */
	public SWTBotText getNewTypeInputField(SWTBotShell changeTypeDialog) {
		SWTBotText attributeType = changeTypeDialog.bot().textWithLabel(JPAEditorMessages.SelectTypeDialog_typeLabel);
		assertEquals("java.lang.String", attributeType.getText());
		assertTrue(getOkButton(changeTypeDialog).isEnabled());
		assertTrue(getCancelButton(changeTypeDialog).isEnabled());
		return attributeType;
	}

	/**
	 * Gets the current attribute type value
	 * @param jpaDiagramEditor
	 * @param attributeName
	 * @param fp
	 * @return the value of the attribute's type
	 */
	public String getAttributeType(SWTBotGefEditor jpaDiagramEditor, String attributeName, final IFeatureProvider fp) {
		SWTBotGefEditPart attribute = jpaDiagramEditor.getEditPart(attributeName);
		PictogramElement el = (PictogramElement) attribute.part().getModel();
		Object bo = fp.getBusinessObjectForPictogramElement(el);
		assertTrue("The selected element is not an attribute!", (bo instanceof JavaPersistentAttribute));
		String currentAttributeType = JPAEditorUtil.getAttributeTypeName((JavaPersistentAttribute)bo);
		return currentAttributeType;
	}
	
	/**
	 * Adds a new attribute to the entity and checks that:
	 * 1. The newly created attribute is selected
	 * 2. The "Other Attributes" section is visible
	 * @param jpaDiagramEditor
	 * @param attributeName - the name of the attribute
	 * @return the newly added attribute
	 */
	public SWTBotGefEditPart addAttributeToEntity(final SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart entity, String attributeName) {
		pressEntityContextButton(jpaDiagramEditor, entity, JPAEditorMessages.JPAEditorToolBehaviorProvider_createAttributeButtonlabel);
		
		bot.waitUntil(new ElementIsShown(jpaDiagramEditor, attributeName), 30000);		
		SWTBotGefEditPart attribute = jpaDiagramEditor.getEditPart(attributeName);
		assertNotNull("Atrribute is not added.", attribute);
		
		assertTrue("The newly added attribute must be selected.", jpaDiagramEditor.selectedEditParts().size() == 1);
		assertTrue("The newly added attribute must be selected.", jpaDiagramEditor.selectedEditParts().contains(attribute));
		
		assertTrue("\"Other Attributes\" section must be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
		
		return attribute;
	}
	
	/**
	 * Checks whether a section with the specified name is visible
	 * @param diagramEditor
	 * @param sectionTitle - the name of the section
	 * @return true, if the section with the specified name is visible,
	 * false otherwise
	 */
	public boolean isSectionVisible(SWTBotGefEditor diagramEditor, String sectionTitle){
		SWTBotGefEditPart section = diagramEditor.getEditPart(sectionTitle);
		((PictogramElement)section.part().getModel()).isVisible();
		IFigure figure = ((GraphicalEditPart) section.part()).getFigure();
		return figure.isVisible();
	}
	
	/**
	 * Adds an entity to the diagram
	 * @param jpaDiagramEditor
	 * @param entityName - the name of the entity to be added
	 * @return the added entity
	 */
	public SWTBotGefEditPart addEntityToDiagram(final SWTBotGefEditor jpaDiagramEditor, int x, int y, String entityName) {
		jpaDiagramEditor.activateTool(JPAEditorMessages.CreateJPAEntityFeature_jpaEntityFeatureName);
		jpaDiagramEditor.doubleClick(x, y);
		bot.waitUntil(new ElementIsShown(jpaDiagramEditor, entityName), 30000);
		
		List<SWTBotGefEditPart> entities = jpaDiagramEditor.mainEditPart().children();
		assertFalse("Editor must contains at least one entity!", entities.isEmpty());
		
		SWTBotGefEditPart entity = jpaDiagramEditor.getEditPart(entityName);
		assertNotNull("Entity is not added!", entity);
		
		SWTBotGefEditPart idAttribute = jpaDiagramEditor.getEditPart("id");
		assertNotNull("Entity must have a primary key attribute!", idAttribute);

		assertTrue("\"Primary Key\" section must be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape));
		assertFalse("\"Relation Attributes\" section must not be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
		assertFalse("\"Other Attributes\" section must not be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
		
		return entity;
	}
	
	/**
	 * Adds mapped superclass  to the diagram
	 * @param jpaDiagramEditor
	 * @param entityName - the name of the mapped superclass to be added
	 * @return the added mapped superclass
	 */
	public SWTBotGefEditPart addMappedSuperclassToDiagram(final SWTBotGefEditor jpaDiagramEditor, int x, int y, String entityName) {
		jpaDiagramEditor.activateTool(JPAEditorMessages.CreateMappedSuperclassFeature_createMappedSuperclassFeatureName);
		jpaDiagramEditor.doubleClick(x, y);		
		bot.waitUntil(new ElementIsShown(jpaDiagramEditor, entityName), 30000);
		
		List<SWTBotGefEditPart> entities = jpaDiagramEditor.mainEditPart().children();
		assertFalse("Editor must contains at least one mapped superclass!", entities.isEmpty());
		
		SWTBotGefEditPart mappedSuperclass = jpaDiagramEditor.getEditPart(entityName);
		assertNotNull("Mapped superclass is not added!", mappedSuperclass);
		
		SWTBotGefEditPart idAttribute = jpaDiagramEditor.getEditPart("id");
		assertNull("Mapped superclass must not have a primary key attribute!", idAttribute);

		assertFalse("\"Primary Key\" section must not be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape));
		assertFalse("\"Relation Attributes\" section must not be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
		assertFalse("\"Other Attributes\" section must not be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
		
		return mappedSuperclass;
	}
	

	
	/**
	 * Pressing the "Yes" button of the "Confirm Delete" question dialog.
	 */
	public void confirmDelete() {
		SWTBotShell shell = getDeleteEntityDialog();
		shell.bot().button("Yes").click();
	}
	
	/**
	 * Pressing the "No" button of the "Confirm Delete" question dialog.
	 */
	public void denyDelete() {
		SWTBotShell shell = getDeleteEntityDialog();
		shell.bot().button("No").click();
	}

	/**
	 * Gets the dialog that appears after the "Delete" context button/menu
	 * is pressed.
	 * @return the question dialog, asking whether to the delete the selected entity
	 */
	public SWTBotShell getDeleteEntityDialog() {
		workbenchBot.waitUntil(shellIsActive(JPAEditorMessages.DeleteFeature_deleteConfirm), 5000);
		SWTBotShell shell = workbenchBot.shell(JPAEditorMessages.DeleteFeature_deleteConfirm);
		return shell;
	}
	
	/**
	 * Gets the dialog that appears after the "Refactor Entity Class -> Rename..." context menu
	 * is pressed.
	 * @return the "Rename Compilation Unit" dialog
	 */
	public SWTBotShell getRenameEntityDialog() {
		workbenchBot.waitUntil(shellIsActive("Rename Compilation Unit"), 5000);
		SWTBotShell shell = workbenchBot.shell("Rename Compilation Unit");
		assertFalse(getFinishButton(shell).isEnabled());
		assertTrue(getCancelButton(shell).isEnabled());
		return shell;
	}
	
	/**
	 * Gets the dialog that appears after the "Refactor Entity Class -> Move..." context menu
	 * is pressed.
	 * @return the "Move" dialog
	 */
	public SWTBotShell getMoveEntityDialog() {
		workbenchBot.waitUntil(shellIsActive("Move"), 5000);
		SWTBotShell shell = workbenchBot.shell("Move");
		assertFalse(getOkButton(shell).isEnabled());
		assertTrue(getCancelButton(shell).isEnabled());
		return shell;
	}
	
	/**
	 * Gets the dialog that appears after the "Remove All Entities from Diagram -> ...and Save/Discard Changes" context menu
	 * is pressed. Press the OK button.
	 */
	public void confirmRemoveEntitiesFromDiagramDialog() {
		workbenchBot.waitUntil(shellIsActive(JPAEditorMessages.JPAEditorToolBehaviorProvider_removeAllEntitiesMenu), 5000);
		SWTBotShell shell = workbenchBot.shell(JPAEditorMessages.JPAEditorToolBehaviorProvider_removeAllEntitiesMenu);
		assertTrue("Ok button is disabled", getOkButton(shell).isEnabled());
		assertTrue(getCancelButton(shell).isEnabled());
		getOkButton(shell).click();
	}
	
	
	/**
	 * Deletes an entity with the specified name using the context button.
	 * @param jpaDiagramEditor
	 * @param entityName - the name of the entity to be deleted
	 */
	public void deleteDiagramElements(SWTBotGefEditor jpaDiagramEditor){
		
		jpaDiagramEditor.save();

		List<SWTBotGefEditPart> entitiesInDiagram = jpaDiagramEditor.mainEditPart().children();
		assertFalse("Diagram must contain at least one entity!", entitiesInDiagram.isEmpty());
		
		Iterator<SWTBotGefEditPart> iterator = entitiesInDiagram.iterator();
		while (iterator.hasNext()) {
			SWTBotGefEditPart editPart = iterator.next();
			assertNotNull(editPart);
			editPart.select();
			jpaDiagramEditor.clickContextMenu("Delete");
			confirmDelete();
		}

		entitiesInDiagram = jpaDiagramEditor.mainEditPart().children();
		assertTrue("Diagram must be empty!", entitiesInDiagram.isEmpty());
		assertTrue("Editor must be dirty!", jpaDiagramEditor.isDirty());
	}
	
	/**
	 * Press some of the entity's context buttons
	 * @param jpaDiagramEditor
	 * @param contextButtonName - the name of the button to be pressed
	 */
	public void pressEntityContextButton(SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart part, String contextButtonName){
		pressContextButton(jpaDiagramEditor, part, contextButtonName);
	}
	
	/**
	 * Press the "Delete Attribute" attribute's context button
	 * @param jpaDiagramEditor
	 */
	public void pressAttributeDeleteContextButton(SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart part){
		pressContextButton(jpaDiagramEditor, part, JPAEditorMessages.JPAEditorToolBehaviorProvider_deleteAttributeButtonlabel);
	}

	/**
	 * Assert that the context button pad is shown, when the mouse is placed over the
	 * entity and press the the desired button
	 * @param jpaDiagramEditor
	 * @param contextButtonName - the name of the button to be pressed.
	 */
	@SuppressWarnings("restriction")
	private void pressContextButton(final SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart part, String contextButtonName) {
		jpaDiagramEditor.click(0, 0);
		jpaDiagramEditor.click(part);
		
		ContextButtonPad pad = findContextButtonPad(jpaDiagramEditor);
		assertNotNull(pad);
		for(final Object button : pad.getChildren()){
			if(((ContextButton)button).getEntry().getText().equals(contextButtonName)){
				asyncExec(new VoidResult() {
					public void run() {
						((ContextButton)button).doClick();
						
					}
				});
			}
		}
	}

	/**
	 * Place the mouse over the entity to show the context button pad.
	 * @param jpaDiagramEditor
	 */
	public void moveMouse(final SWTBotGefEditor jpaDiagramEditor, final int x, final int y) {
		syncExec(new VoidResult() {
			public void run() {
				Robot r;
				try {
					r = new Robot();
					Point p = getOrigin(jpaDiagramEditor);
					r.mouseMove(p.x + x, p.y + y);
				} catch (AWTException e) {
					fail(e.getMessage());
				}
			}
		});
	}

	/**
	 * Gets the context button pad, after placing the mouse over the entity
	 * @param editor
	 * @return the entity's context button pad
	 */
	@SuppressWarnings("restriction")
	private ContextButtonPad findContextButtonPad(SWTBotGefEditor editor) {
		SWTBotGefEditPart rootEditPart = editor.rootEditPart();
		IFigure feedbackLayer = ((ScalableFreeformRootEditPart) rootEditPart.part())
				.getLayer(LayerConstants.HANDLE_LAYER);
		ContextButtonPad cbp = null;
		for (Object obj : feedbackLayer.getChildren()) {
			if (obj instanceof ContextButtonPad) {
				cbp = (ContextButtonPad) obj;
				break;
			}
		}
		return cbp;
	}

	
	private FigureCanvas getCanvas(SWTBotGefEditor editorGef) {
		IEditorReference reference = editorGef.getReference();
		final IEditorPart editor = reference.getEditor(true);
		GraphicalViewer graphicalViewer = (GraphicalViewer) editor.getAdapter(GraphicalViewer.class);
		final Control control = graphicalViewer.getControl();
		if (control instanceof FigureCanvas) {
			FigureCanvas c = (FigureCanvas) control;
			return c;
		}
		return null;
	}
	
	private Point getOrigin(SWTBotGefEditor editorGef) {
		Canvas c = getCanvas(editorGef);
		Point p = c.toDisplay(0, 0);
		return p;
	}
	
	/**
	 * Get the error message that appears in the "Select Type" dialog
	 * @param dialog
	 * @return the error message
	 */
	public SWTBotText getDialogErroMessage(SWTBotShell dialog){
		return dialog.bot().text(1);
	}
	
	/**
	 * Gets the "OK" button of a dialog
	 * @param dialog
	 * @return the "OK" button
	 */
	public SWTBotButton getOkButton(SWTBotShell dialog){
		return dialog.bot().button(IDialogConstants.OK_LABEL);
	}
	
	/**
	 * Gets the "Cancel" button of a dialog
	 * @param dialog
	 * @return the "Cancel" button
	 */
	public SWTBotButton getCancelButton(SWTBotShell dialog){
		return dialog.bot().button(IDialogConstants.CANCEL_LABEL);
	}
	
	/**
	 * Gets the "Finish" button of a dialog
	 * @param dialog
	 * @return the "Finish" button
	 */
	public SWTBotButton getFinishButton(SWTBotShell dialog) {
		return dialog.bot().button("Finish");
	}
	
	/**
	 * Find the IRelation object for the given GEF Connection
	 * @param jpaDiagramEditor
	 * @param gefConn
	 * @return the IRelation object for the given GEF Connection
	 */
	@SuppressWarnings("restriction")
	public IRelation getConnection(SWTBotGefEditor jpaDiagramEditor, SWTBotGefConnectionEditPart gefConn){
		 IFeatureProvider fp = ((DiagramEditPart)jpaDiagramEditor.mainEditPart().part()).getFeatureProvider();
		 FreeFormConnection conn = (FreeFormConnection) gefConn.part().getModel();
		 Object ob = fp.getBusinessObjectForPictogramElement(conn);
		 if(ob instanceof IRelation){
			 return (IRelation)ob;
		 }
		 
		 return null;
	}
	
	/**
	 * Gets the business object (JavaPersistentType) for the given GEF element
	 * @param jpaDiagramEditor
	 * @param element
	 * @return the java persistent type for the given element, null if the selected element is not an entity
	 */
	@SuppressWarnings("restriction")
	public JavaPersistentType getEntityForElement(SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart element){
		final IFeatureProvider fp = ((DiagramEditPart)jpaDiagramEditor.mainEditPart().part()).getFeatureProvider();
		PictogramElement el = (PictogramElement) element.part().getModel();
		Object bo = fp.getBusinessObjectForPictogramElement(el);
		if (bo instanceof JavaPersistentType){
			return (JavaPersistentType)bo;
		}
		return null;
	}
	
	/**
	 * Gets the existing isARelation
	 * @param jpaDiagramEditor
	 * @return the existing isArelation if exists, null otherwise
	 */
	@SuppressWarnings("restriction")
	public IsARelation getIsARelationship(SWTBotGefEditor jpaDiagramEditor){
		IJPAEditorFeatureProvider fp = (IJPAEditorFeatureProvider) ((DiagramEditPart)jpaDiagramEditor.mainEditPart().part()).getFeatureProvider();
		Set<IsARelation> isARelationships = fp.getAllExistingIsARelations();
		assertFalse(isARelationships.isEmpty());
		assertEquals(1, isARelationships.size());
		IsARelation relation = isARelationships.iterator().next();
		return relation;
	}
	
	/**
	 * CHecks whether the Entity contains unsaved changes.
	 * @param jpaDiagramEditor
	 * @param element
	 * @return true if the entity contains unsaved changes, false otherwise
	 */
	@SuppressWarnings("restriction")
	public boolean isEntityDirty(SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart element){
		final IFeatureProvider fp = ((DiagramEditPart)jpaDiagramEditor.mainEditPart().part()).getFeatureProvider();
		PictogramElement el = (PictogramElement) element.part().getModel();
		Object bo = fp.getBusinessObjectForPictogramElement(el);
		IResource res = null;
		if(bo instanceof JavaPersistentAttribute){
			res = ((JavaPersistentAttribute)bo).getResource();
		} else if (bo instanceof JavaPersistentType){
			res = ((JavaPersistentType)bo).getResource();
		}
		
		if(res != null){
			ICompilationUnit unit = JPAEditorUtil.getCompilationUnit((IFile)res);
			try {
				return unit.hasUnsavedChanges();
			} catch (JavaModelException e) {
				e.printStackTrace();
			}
		}
		
		return false;
	}
	
	/**
	 * Select the bidirectional self relation and call its "Delete" context menu.
	 * On the confirmation dialog press "No" and assert that
	 * the connection and the relative relation attributes still exist
	 * and the "Relation Attributes" sections of the entities' are visible.
	 * @param jpaDiagramEditor
	 * @param entity1
	 * @param connection
	 * @param ownerAttributeName
	 * @param inverseAttributeName
	 */
	public void assertSelfBiDirRelationIsNotDeleted(
			SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart entity1,
			SWTBotGefConnectionEditPart connection,
			String ownerAttributeName, String inverseAttributeName) {
		connection.select();
		jpaDiagramEditor.clickContextMenu("Delete");
		denyDelete();
		assertFalse(entity1.sourceConnections().isEmpty());
		assertFalse(entity1.targetConnections().isEmpty());
		connection = entity1.sourceConnections().get(0);
		assertNotNull("Attribute must not be deleted!", connection);
		assertNotNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
		assertNotNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
		assertTrue("\"Relation Attributes\" section of the owner entity must be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
	}
	
	/**
	 * Select the bidirectional relation and call its "Delete" context menu.
	 * On the confirmation dialog press "No" and assert that
	 * the connection and the relative relation attributes still exist
	 * and the "Relation Attributes" sections of the entities' are visible.
	 * @param jpaDiagramEditor
	 * @param entity1
	 * @param entity2
	 * @param connection
	 * @param ownerAttributeName
	 * @param inverseAttributeName
	 */
	public void assertBiDirRelationIsNotDeleted(
			SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart entity1,
			SWTBotGefEditPart entity2,
			SWTBotGefConnectionEditPart connection,
			String ownerAttributeName, String inverseAttributeName) {
		connection.select();
		jpaDiagramEditor.clickContextMenu("Delete");
		denyDelete();
		assertFalse(entity1.sourceConnections().isEmpty());
		assertFalse(entity2.targetConnections().isEmpty());
		connection = entity1.sourceConnections().get(0);
		assertNotNull("Attribute must not be deleted!", connection);
		assertNotNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
		assertNotNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
		assertTrue("\"Relation Attributes\" section of the owner entity must be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
		assertTrue("\"Relation Attributes\" section of the inverse entity must be visible!", isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
	}

	/**
	 * Select the unidirectional relation and call its "Delete" context menu.
	 * On the confirmation dialog press "No" and assert that
	 * the connection and the relative relation attributes still exist
	 * and the "Relation Attributes" sections of the entities' are visible.
	 * @param jpaDiagramEditor
	 * @param entity1
	 * @param entity2
	 * @param connection
	 * @param ownerAttributeName
	 * @param inverseAttributeName
	 */
	public void assertUniDirRelationIsNotDeleted(
			SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart entity1,
			SWTBotGefEditPart entity2,
			SWTBotGefConnectionEditPart connection, String attributeName) {
		connection.select();
		jpaDiagramEditor.clickContextMenu("Delete");
		denyDelete();
		assertFalse(entity1.sourceConnections().isEmpty());
		assertFalse(entity2.targetConnections().isEmpty());
		connection = entity1.sourceConnections().get(0);
		assertNotNull("Attribute must not be deleted!", connection);
		assertNotNull(jpaDiagramEditor.getEditPart(attributeName));
		assertTrue("\"Relation Attributes\" section of the owner entity must be visible!",isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
		assertFalse("\"Relation Attributes\" section of the inverse entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
	}
	
	/**
	 * Select the unidirectional self relation and call its "Delete" context menu.
	 * On the confirmation dialog press "No" and assert that
	 * the connection and the relative relation attributes still exist
	 * and the "Relation Attributes" sections of the entities' are visible.
	 * @param jpaDiagramEditor
	 * @param entity1
	 * @param connection
	 * @param ownerAttributeName
	 * @param inverseAttributeName
	 */
	public void assertSelfUniDirRelationIsNotDeleted(
			SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart entity1,
			SWTBotGefConnectionEditPart connection, String attributeName) {
		connection.select();
		jpaDiagramEditor.clickContextMenu("Delete");
		denyDelete();
		assertFalse(entity1.sourceConnections().isEmpty());
		assertFalse(entity1.targetConnections().isEmpty());
		connection = entity1.sourceConnections().get(0);
		assertNotNull("Attribute must not be deleted!", connection);
		assertNotNull(jpaDiagramEditor.getEditPart(attributeName));
		assertTrue("\"Relation Attributes\" section of the owner entity must be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
	}

	/**
	 * Select the bidirectional relation and call its "Delete" context menu.
	 * On the confirmation dialog press "Yes" and assert that
	 * the connection and the relative relation attributes do not exist anymore
	 * and the "Relation Attributes" sections of the entities' are not visible.
	 * @param jpaDiagramEditor
	 * @param entity1
	 * @param entity2
	 * @param connection
	 * @param ownerAttributeName
	 * @param inverseAttributeName
	 */
	public void assertBiDirRelationIsDeleted(SWTBotGefEditor jpaDiagramEditor,
			SWTBotGefEditPart entity1, SWTBotGefEditPart entity2,
			SWTBotGefConnectionEditPart connection,
			String ownerAttributeName, String inverseAttributeName) {
		connection.select();
		jpaDiagramEditor.clickContextMenu("Delete");
		confirmDelete();
		bot.waitUntil(new ElementDisappears(jpaDiagramEditor, ownerAttributeName));
		assertTrue(entity1.sourceConnections().isEmpty());
		assertTrue(entity2.targetConnections().isEmpty());
		assertNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
		assertNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
		assertFalse("\"Relation Attributes\" section of the owner entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
		assertFalse("\"Relation Attributes\" section of the inverse entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
	}
	
	/**
	 * Select the bidirectional self relation and call its "Delete" context menu.
	 * On the confirmation dialog press "Yes" and assert that
	 * the connection and the relative relation attributes do not exist anymore
	 * and the "Relation Attributes" sections of the entities' are not visible.
	 * @param jpaDiagramEditor
	 * @param entity1
	 * @param connection
	 * @param ownerAttributeName
	 * @param inverseAttributeName
	 */
	public void assertSelfBiDirRelationIsDeleted(SWTBotGefEditor jpaDiagramEditor,
			SWTBotGefEditPart entity1,
			SWTBotGefConnectionEditPart connection,
			String ownerAttributeName, String inverseAttributeName) {
		connection.select();
		jpaDiagramEditor.clickContextMenu("Delete");
		confirmDelete();
		bot.waitUntil(new ElementDisappears(jpaDiagramEditor, ownerAttributeName));
		assertTrue(entity1.sourceConnections().isEmpty());
		assertTrue(entity1.targetConnections().isEmpty());
		assertNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
		assertNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
		assertFalse("\"Relation Attributes\" section of the owner entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
	}
	
	/**
	 * Select the unidirectional relation and call its "Delete" context menu.
	 * On the confirmation dialog press "Yes" and assert that
	 * the connection and the relative relation attributes do not exist anymore
	 * and the "Relation Attributes" sections of the entities' are not visible.
	 * @param jpaDiagramEditor
	 * @param entity1
	 * @param entity2
	 * @param connection
	 * @param ownerAttributeName
	 * @param inverseAttributeName
	 */
	public void assertUniDirRelationIsDeleted(SWTBotGefEditor jpaDiagramEditor,
			SWTBotGefEditPart entity1, SWTBotGefEditPart entity2,
			SWTBotGefConnectionEditPart connection, String attributeName) {
		connection.select();
		jpaDiagramEditor.clickContextMenu("Delete");
		confirmDelete();
		bot.waitUntil(new ElementDisappears(jpaDiagramEditor, attributeName));
		assertTrue(entity1.sourceConnections().isEmpty());
		assertTrue(entity2.targetConnections().isEmpty());
		assertNull(jpaDiagramEditor.getEditPart(attributeName));
		assertFalse("\"Relation Attributes\" section of the owner entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
		assertFalse("\"Relation Attributes\" section of the inverse entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
	}
	
	/**
	 * Select the unidirectional self relation and call its "Delete" context menu.
	 * On the confirmation dialog press "Yes" and assert that
	 * the connection and the relative relation attributes do not exist anymore
	 * and the "Relation Attributes" sections of the entities' are not visible.
	 * @param jpaDiagramEditor
	 * @param entity1
	 * @param connection
	 * @param ownerAttributeName
	 * @param inverseAttributeName
	 */
	public void assertSelfUniDirRelationIsDeleted(SWTBotGefEditor jpaDiagramEditor,
			SWTBotGefEditPart entity1,
			SWTBotGefConnectionEditPart connection, String attributeName) {
		connection.select();
		jpaDiagramEditor.clickContextMenu("Delete");
		confirmDelete();
		bot.waitUntil(new ElementDisappears(jpaDiagramEditor, attributeName));
		assertTrue(entity1.sourceConnections().isEmpty());
		assertTrue(entity1.targetConnections().isEmpty());
		assertNull(jpaDiagramEditor.getEditPart(attributeName));
		assertFalse("\"Relation Attributes\" section of the owner entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
	}
	
	/**
	 * Assert that there is exactly one GEF element representing the relationship 
	 * @param jpaDiagramEditor
	 * @param entity1
	 * @param entity2
	 */
	public void assertConnectionIsCreated(SWTBotGefEditor jpaDiagramEditor,
			SWTBotGefEditPart entity1, SWTBotGefEditPart entity2, boolean isBiDIr) {
		//assert that there is exactly one relationship, which start from entity1
		//and that there is no relationship which starts from entity2
		assertFalse(entity1.sourceConnections().isEmpty());
		assertEquals(1, entity1.sourceConnections().size());
		assertTrue(entity2.sourceConnections().isEmpty());
		
		//assert that there is exactly one relationship which ends in entity2
		//and that there is no relationship which end in entity1.
		assertFalse(entity2.targetConnections().isEmpty());
		assertEquals(1, entity2.targetConnections().size());
		assertTrue(entity1.targetConnections().isEmpty());
		
		assertTrue("\"Relation Attributes\" section of the owner entity must be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
		if(isBiDIr){
			assertTrue("\"Relation Attributes\" section of the inverse entity must be visible!", isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
		} else {
			assertFalse("\"Relation Attributes\" section of the inverse entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
		}
	}
	
	public void assertIsARelationExists(SWTBotGefEditor jpaDiagramEditor,
			SWTBotGefEditPart entity1, SWTBotGefEditPart entity2) {
		// assert that there is exactly one relationship, which start from
		// entity2 and that there is no relationship which starts from entity2
		assertFalse(entity2.sourceConnections().isEmpty());
		assertEquals(1, entity2.sourceConnections().size());
		assertTrue(entity1.sourceConnections().isEmpty());

		// assert that there is exactly one relationship which ends in entity1
		// and that there is no relationship which end in entity2.
		assertFalse(entity1.targetConnections().isEmpty());
		assertEquals(1, entity1.targetConnections().size());
		assertTrue(entity2.targetConnections().isEmpty());
	}

	/**
	 * Assert that there is exactly one GEF element representing the self relationship 
	 * @param jpaDiagramEditor
	 * @param entity1
	 */
	public void assertSelfConnectionIsCreated(SWTBotGefEditor jpaDiagramEditor,
			SWTBotGefEditPart entity1) {
		//assert that there is exactly one relationship, which start from entity1
		//and ends in entity2
		assertFalse(entity1.sourceConnections().isEmpty());
		assertEquals(1, entity1.sourceConnections().size());

		assertFalse(entity1.targetConnections().isEmpty());
		assertEquals(1, entity1.targetConnections().size());
		
		assertTrue(isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
	}
	
	/**
	 * Assert that the owner relationship attribute exists
	 * @param jpaDiagramEditor
	 * @param rel
	 * @return the name of the owner relationship attribute
	 */
	public String testOwnerRelationAttributeProperties(
			SWTBotGefEditor jpaDiagramEditor, IRelation rel) {
		JavaPersistentAttribute ownerAttr = rel.getOwnerAnnotatedAttribute();
		String attributeName = rel.getOwnerAttributeName();
		assertNotNull(ownerAttr);
		assertNotNull(jpaDiagramEditor.getEditPart(attributeName));
		
		return attributeName;
	}
	
	/**
	 * Assert that the inverse relationship attribute exists.
	 * @param jpaDiagramEditor
	 * @param rel
	 * @return the name of the inverse relationship attribute
	 */
	public String testInverseRelationAttributeProperties(
			SWTBotGefEditor jpaDiagramEditor, IRelation rel) {
		JavaPersistentAttribute inverseAttr = rel.getInverseAnnotatedAttribute();
		String inverseAttributeName = rel.getInverseAttributeName();
		assertNotNull(inverseAttr);
		assertNotNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
		return inverseAttributeName;
	}
	
	
	/**
	 * Checks whether a section of a particular entity is visible
	 * @param diagramEditor
	 * @param editPart - the particular entity
	 * @param sectionTitle - the title of the section to be checked
	 * @return true,  if the sections is visible, false otherwise
	 */
	@SuppressWarnings("deprecation")
	public boolean isSectionVisible(SWTBotGefEditor diagramEditor, SWTBotGefEditPart editPart,  String sectionTitle){
		List<SWTBotGefEditPart> children = editPart.children();
		SWTBotGefEditPart section = diagramEditor.getEditpart(sectionTitle, children);
		((PictogramElement)section.part().getModel()).isVisible();
		IFigure figure = ((GraphicalEditPart) section.part()).getFigure();
		return figure.isVisible();
	}

	/**
	 * Change the mapping of the type or attribute.
	 * @param newMappingType
	 */
	public void changeMappingtype(String newMappingType) {
		workbenchBot.waitUntil(shellIsActive("Mapping Type Selection"), 5000);
		SWTBotShell mappingTypeShell = workbenchBot.shell("Mapping Type Selection");
		mappingTypeShell.bot().table().getTableItem(newMappingType).select();		
		getOkButton(mappingTypeShell).click();
	}

	/**
	 * Click on the mapping type link in the JPA Details view
	 * @param styledText
	 * @param position
	 */
	public void clickOnStyledText(final SWTBotStyledText styledText, int position) {
		styledText.navigateTo(new Position(0, position));		
		asyncExec(new VoidResult() {
			public void run() {
				styledText.widget.notifyListeners(SWT.MouseDown, new Event());
				styledText.widget.notifyListeners(SWT.MouseUp, new Event());
			}
		});
	}

	public void waitASecond() {
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Assert that the relation attribute is correctly mapped in the JPA Details view
	 * @param jpaDiagramEditor
	 * @param attributeName
	 * @param relationAttributeMapping - the expected attribute mapping
	 */
	public void assertAttributeIsCorretlyMapped(IFeatureProvider fp,
			SWTBotGefEditor jpaDiagramEditor, String attributeName,  String relationAttributeMapping) {		
		
		SWTBotGefEditPart attribute = jpaDiagramEditor.getEditPart(attributeName);
		PictogramElement el = (PictogramElement) attribute.part().getModel();
		Object bo = fp.getBusinessObjectForPictogramElement(el);
		assertTrue("The selected element is not an attribute!", (bo instanceof JavaPersistentAttribute));
		
		assertEquals(((JavaPersistentAttribute)bo).getMappingKey(), relationAttributeMapping);
	}
	
	/**
	 * Assert that the relation attribute is correctly mapped in the JPA Details view
	 * @param jpaDiagramEditor
	 * @param attributeName
	 * @param relationAttributeMapping - the expected attribute mapping
	 */
	public void assertAttributeIsCorretlyMappedInJPADetailsView(
			SWTBotGefEditor jpaDiagramEditor, String attributeName,  String relationAttributeMapping) {

		//assert that the JPA Details view is opened
		SWTBotView jpaDetailsView = workbenchBot.viewByTitle("JPA Details");
		jpaDetailsView.setFocus();
		assertTrue("JPA Details view must be opened!", jpaDetailsView.isActive());
		
		SWTBotGefEditPart oneToManyAttr = jpaDiagramEditor.getEditPart(attributeName);
		oneToManyAttr.click();
		oneToManyAttr.select();

		//assert that the default entity's attribute is mapped as primary key
		SWTBot jpaDetailsBot = jpaDetailsView.bot();
		SWTBotStyledText styledText = jpaDetailsBot.styledText();
		assertEquals("Attribute '" +attributeName+ "' is mapped as " +relationAttributeMapping+ ".", styledText.getText());
	}
	
	/**
	 * Assert that the type is correctly mapped in the JPA Details view
	 * @param jpaDiagramEditor
	 * @param typeName
	 * @param typeMapping - the expected type mapping
	 */
	public void assertTypeIsCorretlyMapped(IFeatureProvider fp,
			SWTBotGefEditor jpaDiagramEditor, String typeName,  String typeMapping) {

		SWTBotGefEditPart attribute = jpaDiagramEditor.getEditPart(typeName);
		PictogramElement el = (PictogramElement) attribute.part().getModel();
		Object bo = fp.getBusinessObjectForPictogramElement(el);
		assertTrue("The selected element is not an persistent type!", (bo instanceof JavaPersistentType));
		assertEquals(((JavaPersistentType)bo).getMappingKey(), typeMapping);
	}
	
	/**
	 * Assert that the type is correctly mapped in the JPA Details view
	 * @param jpaDiagramEditor
	 * @param typeName
	 * @param typeMapping - the expected type mapping
	 */
	public void assertTypeIsCorretlyMappedInJPADetailsView(
			SWTBotGefEditor jpaDiagramEditor, String typeName,  String typeMapping) {
		workbenchBot.viewByTitle("JPA Details").close();
		jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_openJPADetailsView);
		//assert that the JPA Details view is opened
		SWTBotView jpaDetailsView = workbenchBot.viewByTitle("JPA Details");
		assertTrue("JPA Details view must be opened!", jpaDetailsView.isActive());
		
		SWTBotGefEditPart type = jpaDiagramEditor.getEditPart(typeName);
		type.click();

		//assert that the default entity's attribute is mapped as the given mapping key
		SWTBot jpaDetailsBot = jpaDetailsView.bot();
		SWTBotStyledText styledText = jpaDetailsBot.styledText();
		assertEquals("Type '" +typeName+ "' is mapped as " +typeMapping+ ".", styledText.getText());
	}
}

Back to the top