Skip to content

Commit fd728c3

Browse files
ptzieglerHannesWell
authored andcommitted
Extend o.e.e4.emf.xpath.test to cover test child context
1 parent 3fbb469 commit fd728c3

File tree

2 files changed

+58
-6
lines changed

2 files changed

+58
-6
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: 52 additions & 6 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,11 +47,14 @@ 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
4856
public void setUp() {
57+
4958
resourceSet = new ResourceSetImpl();
5059
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
5160
.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new E4XMIResourceFactory());
@@ -63,13 +72,19 @@ public void setUp() {
6372
resource = resourceSet.getResource(uri, true);
6473
XPathContextFactory<EObject> f = EcoreXPathContextFactory.newInstance();
6574
xpathContext = f.newContext(resource.getContents().get(0));
75+
URI childUri = URI.createPlatformPluginURI("/org.eclipse.e4.emf.xpath.test/model/fragment.e4xmi", true);
76+
childResource = resourceSet.getResource(childUri, true);
77+
xpathChildContext = f.newContext(xpathContext, childResource.getContents().get(0));
6678
}
6779

6880
@After
6981
public void tearDown() {
7082
xpathContext = null;
7183
resource.unload();
7284
resourceSet.getResources().remove(resource);
85+
xpathChildContext = null;
86+
childResource.unload();
87+
resourceSet.getResources().remove(childResource);
7388
}
7489

7590
@Test
@@ -80,17 +95,48 @@ public void testAccessingTheApplication() {
8095

8196
@Test
8297
public void testAccessingTheMainMenu() {
83-
Object menu = xpathContext.getValue("//mainMenu");
84-
assertThat(menu).isInstanceOf(MMenu.class);
98+
assertThat(xpathContext.getValue("//mainMenu")).isInstanceOf(MMenu.class);
99+
assertNotNull(xpathContext.getValue("//mainMenu", MMenu.class));
85100

86-
MMenu mMenu = xpathContext.getValue("//mainMenu", MMenu.class);
87-
assertNotNull(mMenu);
101+
assertNotNull(xpathContext.getValue("/children/mainMenu", MMenu.class));
102+
assertThat(xpathContext.getValue("/children/mainMenu")).isInstanceOf(MMenu.class);
88103
}
89104

90105
@Test
91106
public void testAccessingAllMenus() {
92107
Object menuEntries = xpathContext.getValue("//mainMenu/children");
93-
assertNotNull(menuEntries);
108+
assertThat(menuEntries).isInstanceOf(List.class);
109+
List<?> list = (List<?>) menuEntries;
110+
assertEquals(2, list.size());
111+
assertThat(list).allMatch(MMenu.class::isInstance, "Is instanceof of MMenu") //
112+
.anyMatch(e -> "File".equals(((MMenu) e).getLabel()))
113+
.anyMatch(e -> "Help".equals(((MMenu) e).getLabel()));
94114
}
95115

96-
}
116+
@Test
117+
public void testAccessingTheModelFragments() {
118+
Object modelFragments = xpathChildContext.getValue("/");
119+
assertThat(modelFragments).isInstanceOf(MModelFragments.class);
120+
}
121+
122+
@Test
123+
public void testAccessingTheStringModelFragment() {
124+
Object modelFragment = xpathChildContext.getValue("//fragments[1]");
125+
assertThat(modelFragment).isInstanceOf(MStringModelFragment.class);
126+
127+
MStringModelFragment mModelFragment = xpathChildContext.getValue("//fragments[1]", MStringModelFragment.class);
128+
assertNotNull(mModelFragment);
129+
130+
Object modelFragment2 = xpathChildContext.getValue("/fragments[1]");
131+
assertThat(modelFragment2).isInstanceOf(MStringModelFragment.class);
132+
}
133+
134+
@Test
135+
public void testAccessingTheAddons() {
136+
Object addon = xpathChildContext.getValue("//elements[1]");
137+
assertThat(addon).isInstanceOf(MAddon.class);
138+
139+
MAddon mAddon = xpathChildContext.getValue("//elements[1]", MAddon.class);
140+
assertNotNull(mAddon);
141+
}
142+
}

0 commit comments

Comments
 (0)