Skip to content

Commit c9f129d

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 34062b8 commit c9f129d

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

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

+20-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
import static org.assertj.core.api.Assertions.assertThat;
1818
import static org.junit.Assert.assertEquals;
19+
import static org.junit.Assert.assertFalse;
1920
import static org.junit.Assert.assertNotNull;
21+
import static org.junit.Assert.assertSame;
2022
import static org.junit.Assert.assertThrows;
2123
import static org.junit.Assert.assertTrue;
2224

@@ -47,6 +49,7 @@ public class ExampleQueriesTestCase {
4749
private ResourceSet resourceSet;
4850
private XPathContext xpathContext;
4951
private Resource resource;
52+
private XPathContextFactory<EObject> xpathContextFactory;
5053

5154
@Before
5255
public void setUp() {
@@ -58,13 +61,14 @@ public void setUp() {
5861
resourceSet.getPackageRegistry().put(XpathtestPackage.eNS_URI, XpathtestPackage.eINSTANCE);
5962
URI uri = URI.createPlatformPluginURI("/org.eclipse.e4.emf.xpath.test/model/Test.xmi", true);
6063
resource = resourceSet.getResource(uri, true);
61-
XPathContextFactory<EObject> f = EcoreXPathContextFactory.newInstance();
62-
xpathContext = f.newContext(resource.getContents().get(0));
64+
xpathContextFactory = EcoreXPathContextFactory.newInstance();
65+
xpathContext = xpathContextFactory.newContext(resource.getContents().get(0));
6366
}
6467

6568
@After
6669
public void tearDown() {
6770
xpathContext = null;
71+
xpathContextFactory = null;
6872
resource.unload();
6973
resourceSet.getResources().remove(resource);
7074
}
@@ -82,6 +86,7 @@ public void testSimpleQuery() {
8286
assertThat(application).isInstanceOf(Root.class);
8387

8488
assertThrows(JXPathNotFoundException.class, () -> xpathContext.getValue(".[@id='nixda']"));
89+
assertFalse(xpathContext.iterate(".[@id='nixda']").hasNext());
8590

8691
application = xpathContext.getValue(".[@id='root']");
8792
assertThat(application).isInstanceOf(Root.class);
@@ -95,6 +100,8 @@ public void testSimpleQuery() {
95100
assertThat(xpathContext.getValue("//.[ecore:eClassName(.)='ExtendedNode']")).isInstanceOf(ExtendedNode.class);
96101

97102
assertNotNull(xpathContext.getValue("//.[ecore:eClassName(.)='ExtendedNode']", ExtendedNode.class));
103+
104+
assertEquals(rootApplication, xpathContext.getValue("."));
98105
}
99106

100107
@Test
@@ -119,4 +126,15 @@ public void testMenuQuery() {
119126
assertEquals(26, list.size());
120127
}
121128

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

0 commit comments

Comments
 (0)