Skip to content

Commit 824308d

Browse files
merksHannesWell
authored andcommitted
Extend o.e.e4.emf.xpath.test
- Add ExampleQueriesTestCase.testRelative() to test relative paths via a nested context. Contributes to - #423
1 parent fdff781 commit 824308d

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static org.assertj.core.api.Assertions.assertThat;
1818
import static org.junit.Assert.assertEquals;
1919
import static org.junit.Assert.assertNotNull;
20+
import static org.junit.Assert.assertSame;
2021
import static org.junit.Assert.assertThrows;
2122
import static org.junit.Assert.assertTrue;
2223

@@ -47,6 +48,7 @@ public class ExampleQueriesTestCase {
4748
private ResourceSet resourceSet;
4849
private XPathContext xpathContext;
4950
private Resource resource;
51+
private XPathContextFactory<EObject> xpathContextFactory;
5052

5153
@Before
5254
public void setUp() {
@@ -58,13 +60,14 @@ public void setUp() {
5860
resourceSet.getPackageRegistry().put(XpathtestPackage.eNS_URI, XpathtestPackage.eINSTANCE);
5961
URI uri = URI.createPlatformPluginURI("/org.eclipse.e4.emf.xpath.test/model/Test.xmi", true);
6062
resource = resourceSet.getResource(uri, true);
61-
XPathContextFactory<EObject> f = EcoreXPathContextFactory.newInstance();
62-
xpathContext = f.newContext(resource.getContents().get(0));
63+
xpathContextFactory = EcoreXPathContextFactory.newInstance();
64+
xpathContext = xpathContextFactory.newContext(resource.getContents().get(0));
6365
}
6466

6567
@After
6668
public void tearDown() {
6769
xpathContext = null;
70+
xpathContextFactory = null;
6871
resource.unload();
6972
resourceSet.getResources().remove(resource);
7073
}
@@ -95,6 +98,8 @@ public void testSimpleQuery() {
9598
assertThat(xpathContext.getValue("//.[ecore:eClassName(.)='ExtendedNode']")).isInstanceOf(ExtendedNode.class);
9699

97100
assertNotNull(xpathContext.getValue("//.[ecore:eClassName(.)='ExtendedNode']", ExtendedNode.class));
101+
102+
assertEquals(rootApplication, xpathContext.getValue("."));
98103
}
99104

100105
@Test
@@ -119,4 +124,15 @@ public void testMenuQuery() {
119124
assertEquals(26, list.size());
120125
}
121126

127+
@Test
128+
public void testRelative() {
129+
EObject context = resource.getContents().get(0);
130+
List<EObject> eContents = context.eContents();
131+
EObject firstElement = eContents.get(0);
132+
XPathContext nestedXpathContext = xpathContextFactory.newContext(xpathContext, firstElement);
133+
134+
List<Node> dotList = nestedXpathContext.stream(".", Node.class).toList();
135+
assertEquals(1, dotList.size());
136+
assertSame(firstElement, dotList.get(0));
137+
}
122138
}

0 commit comments

Comments
 (0)