14
14
package org .eclipse .e4 .emf .xpath .test ;
15
15
16
16
import static org .assertj .core .api .Assertions .assertThat ;
17
+ import static org .junit .Assert .assertEquals ;
17
18
import static org .junit .Assert .assertNotNull ;
18
19
20
+ import java .util .List ;
21
+
19
22
import org .eclipse .e4 .emf .xpath .EcoreXPathContextFactory ;
20
23
import org .eclipse .e4 .emf .xpath .XPathContext ;
21
24
import org .eclipse .e4 .emf .xpath .XPathContextFactory ;
22
25
import org .eclipse .e4 .ui .internal .workbench .E4XMIResourceFactory ;
26
+ import org .eclipse .e4 .ui .model .application .MAddon ;
23
27
import org .eclipse .e4 .ui .model .application .MApplication ;
24
28
import org .eclipse .e4 .ui .model .application .commands .impl .CommandsPackageImpl ;
25
29
import org .eclipse .e4 .ui .model .application .impl .ApplicationPackageImpl ;
28
32
import org .eclipse .e4 .ui .model .application .ui .impl .UiPackageImpl ;
29
33
import org .eclipse .e4 .ui .model .application .ui .menu .MMenu ;
30
34
import org .eclipse .e4 .ui .model .application .ui .menu .impl .MenuPackageImpl ;
35
+ import org .eclipse .e4 .ui .model .fragment .MModelFragments ;
36
+ import org .eclipse .e4 .ui .model .fragment .MStringModelFragment ;
31
37
import org .eclipse .emf .common .util .URI ;
32
38
import org .eclipse .emf .ecore .EObject ;
33
39
import org .eclipse .emf .ecore .resource .Resource ;
@@ -41,7 +47,9 @@ public class ExampleQueriesApplicationTest {
41
47
42
48
private ResourceSet resourceSet ;
43
49
private XPathContext xpathContext ;
50
+ private XPathContext xpathChildContext ;
44
51
private Resource resource ;
52
+ private Resource childResource ;
45
53
46
54
@ SuppressWarnings ("restriction" )
47
55
@ Before
@@ -63,13 +71,19 @@ public void setUp() {
63
71
resource = resourceSet .getResource (uri , true );
64
72
XPathContextFactory <EObject > f = EcoreXPathContextFactory .newInstance ();
65
73
xpathContext = f .newContext (resource .getContents ().get (0 ));
74
+ URI childUri = URI .createPlatformPluginURI ("/org.eclipse.e4.emf.xpath.test/model/fragment.e4xmi" , true );
75
+ childResource = resourceSet .getResource (childUri , true );
76
+ xpathChildContext = f .newContext (xpathContext , childResource .getContents ().get (0 ));
66
77
}
67
78
68
79
@ After
69
80
public void tearDown () {
70
81
xpathContext = null ;
71
82
resource .unload ();
72
83
resourceSet .getResources ().remove (resource );
84
+ xpathChildContext = null ;
85
+ childResource .unload ();
86
+ resourceSet .getResources ().remove (childResource );
73
87
}
74
88
75
89
@ Test
@@ -80,17 +94,48 @@ public void testAccessingTheApplication() {
80
94
81
95
@ Test
82
96
public void testAccessingTheMainMenu () {
83
- Object menu = xpathContext .getValue ("//mainMenu" );
84
- assertThat ( menu ). isInstanceOf ( MMenu .class );
97
+ assertThat ( xpathContext .getValue ("//mainMenu" )). isInstanceOf ( MMenu . class );
98
+ assertNotNull ( xpathContext . getValue ( "//mainMenu" , MMenu .class ) );
85
99
86
- MMenu mMenu = xpathContext .getValue ("//mainMenu" , MMenu .class );
87
- assertNotNull ( mMenu );
100
+ assertNotNull ( xpathContext .getValue ("/children /mainMenu" , MMenu .class ) );
101
+ assertThat ( xpathContext . getValue ( "/children/mainMenu" )). isInstanceOf ( MMenu . class );
88
102
}
89
103
90
104
@ Test
91
105
public void testAccessingAllMenus () {
92
106
Object menuEntries = xpathContext .getValue ("//mainMenu/children" );
93
- assertNotNull (menuEntries );
107
+ assertThat (menuEntries ).isInstanceOf (List .class );
108
+ List <?> list = (List <?>) menuEntries ;
109
+ assertEquals (2 , list .size ());
110
+ assertThat (list ).allMatch (MMenu .class ::isInstance , "Is instanceof of MMenu" ) //
111
+ .anyMatch (e -> "File" .equals (((MMenu ) e ).getLabel ()))
112
+ .anyMatch (e -> "Help" .equals (((MMenu ) e ).getLabel ()));
113
+ }
114
+
115
+ @ Test
116
+ public void testAccessingTheModelFragments () {
117
+ Object modelFragments = xpathChildContext .getValue ("/" );
118
+ assertThat (modelFragments ).isInstanceOf (MModelFragments .class );
119
+ }
120
+
121
+ @ Test
122
+ public void testAccessingTheStringModelFragment () {
123
+ Object modelFragment = xpathChildContext .getValue ("//fragments[1]" );
124
+ assertThat (modelFragment ).isInstanceOf (MStringModelFragment .class );
125
+
126
+ MStringModelFragment mModelFragment = xpathChildContext .getValue ("//fragments[1]" , MStringModelFragment .class );
127
+ assertNotNull (mModelFragment );
128
+
129
+ Object modelFragment2 = xpathChildContext .getValue ("/fragments[1]" );
130
+ assertThat (modelFragment2 ).isInstanceOf (MStringModelFragment .class );
94
131
}
95
132
133
+ @ Test
134
+ public void testAccessingTheAddons () {
135
+ Object addon = xpathChildContext .getValue ("//elements[1]" );
136
+ assertThat (addon ).isInstanceOf (MAddon .class );
137
+
138
+ MAddon mAddon = xpathChildContext .getValue ("//elements[1]" , MAddon .class );
139
+ assertNotNull (mAddon );
140
+ }
96
141
}
0 commit comments