1717import static org .assertj .core .api .Assertions .assertThat ;
1818import static org .junit .Assert .assertEquals ;
1919import static org .junit .Assert .assertNotNull ;
20+ import static org .junit .Assert .assertSame ;
2021import static org .junit .Assert .assertThrows ;
2122import 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