1414package org .eclipse .e4 .emf .xpath .test ;
1515
1616import static org .assertj .core .api .Assertions .assertThat ;
17+ import static org .junit .Assert .assertEquals ;
1718import static org .junit .Assert .assertNotNull ;
1819
20+ import java .util .List ;
21+
1922import org .eclipse .e4 .emf .xpath .EcoreXPathContextFactory ;
2023import org .eclipse .e4 .emf .xpath .XPathContext ;
2124import org .eclipse .e4 .emf .xpath .XPathContextFactory ;
2225import org .eclipse .e4 .ui .internal .workbench .E4XMIResourceFactory ;
26+ import org .eclipse .e4 .ui .model .application .MAddon ;
2327import org .eclipse .e4 .ui .model .application .MApplication ;
2428import org .eclipse .e4 .ui .model .application .commands .impl .CommandsPackageImpl ;
2529import org .eclipse .e4 .ui .model .application .impl .ApplicationPackageImpl ;
2832import org .eclipse .e4 .ui .model .application .ui .impl .UiPackageImpl ;
2933import org .eclipse .e4 .ui .model .application .ui .menu .MMenu ;
3034import 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 ;
3137import org .eclipse .emf .common .util .URI ;
3238import org .eclipse .emf .ecore .EObject ;
3339import org .eclipse .emf .ecore .resource .Resource ;
@@ -41,7 +47,9 @@ public class ExampleQueriesApplicationTest {
4147
4248 private ResourceSet resourceSet ;
4349 private XPathContext xpathContext ;
50+ private XPathContext xpathChildContext ;
4451 private Resource resource ;
52+ private Resource childResource ;
4553
4654 @ SuppressWarnings ("restriction" )
4755 @ Before
@@ -63,13 +71,19 @@ public void setUp() {
6371 resource = resourceSet .getResource (uri , true );
6472 XPathContextFactory <EObject > f = EcoreXPathContextFactory .newInstance ();
6573 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 ));
6677 }
6778
6879 @ After
6980 public void tearDown () {
7081 xpathContext = null ;
7182 resource .unload ();
7283 resourceSet .getResources ().remove (resource );
84+ xpathChildContext = null ;
85+ childResource .unload ();
86+ resourceSet .getResources ().remove (childResource );
7387 }
7488
7589 @ Test
@@ -80,17 +94,48 @@ public void testAccessingTheApplication() {
8094
8195 @ Test
8296 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 ) );
8599
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 );
88102 }
89103
90104 @ Test
91105 public void testAccessingAllMenus () {
92106 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 );
94131 }
95132
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+ }
96141}
0 commit comments