Skip to content

Commit 34062b8

Browse files
ptzieglerHannesWell
authored andcommitted
Extend o.e.e4.emf.xpath.test to cover test child context
Contributes to - #423
1 parent 3fbb469 commit 34062b8

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="ASCII"?>
2+
<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:application="http://www.eclipse.org/ui/2010/UIModel/application" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmi:id="_LyWmYOb0Ee--mt4bM5b6zQ">
3+
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_KlpGMOb1Ee--mt4bM5b6zQ" featurename="addons" parentElementId="xpath:/">
4+
<elements xsi:type="application:Addon" xmi:id="_YfwQoOb1Ee--mt4bM5b6zQ" elementId="org.eclipse.e4.emf.xpath.test.addon.0"/>
5+
</fragments>
6+
</fragment:ModelFragments>

tests/org.eclipse.e4.emf.xpath.test/src/org/eclipse/e4/emf/xpath/test/ExampleQueriesApplicationTest.java

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
package org.eclipse.e4.emf.xpath.test;
1515

1616
import static org.assertj.core.api.Assertions.assertThat;
17+
import static org.junit.Assert.assertEquals;
1718
import static org.junit.Assert.assertNotNull;
1819

20+
import java.util.List;
21+
1922
import org.eclipse.e4.emf.xpath.EcoreXPathContextFactory;
2023
import org.eclipse.e4.emf.xpath.XPathContext;
2124
import org.eclipse.e4.emf.xpath.XPathContextFactory;
2225
import org.eclipse.e4.ui.internal.workbench.E4XMIResourceFactory;
26+
import org.eclipse.e4.ui.model.application.MAddon;
2327
import org.eclipse.e4.ui.model.application.MApplication;
2428
import org.eclipse.e4.ui.model.application.commands.impl.CommandsPackageImpl;
2529
import org.eclipse.e4.ui.model.application.impl.ApplicationPackageImpl;
@@ -28,6 +32,8 @@
2832
import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl;
2933
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
3034
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;
3137
import org.eclipse.emf.common.util.URI;
3238
import org.eclipse.emf.ecore.EObject;
3339
import 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

Comments
 (0)