Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8289508: Improve test coverage for XPath Axes: ancestor, ancestor-or-self, preceding, and preceding-sibling #10211

Closed
wants to merge 11 commits into from
Closed
38 changes: 19 additions & 19 deletions test/jaxp/javax/xml/jaxp/unittest/xpath/XPathAncestorsTest.java
Original file line number Diff line number Diff line change
@@ -41,7 +41,6 @@
* @test
* @bug 8289508
* @library /javax/xml/jaxp/unittest
*
* @run testng/othervm xpath.XPathAncestorsTest
* @summary Tests for XPath ancestor and ancestor-or-self axis specifiers.
*/
@@ -85,34 +84,34 @@ public Object[][] getXPathAncestors() {
//test ancestor

// abbreviated text
{"//author/ancestor::book/ancestor::store", "/store"},
{"//author/ancestor::book/ancestor::store", "/store"},
{"//isbn/ancestor::store", "/store"},
{"//ancestor::book[1]", "//book[1]"},
{"//ancestor::book[1]", "//book[1]"},

// any node
{"//book/ancestor::*", "/store"},
{"//author/ancestor::*[ancestor::store]/ancestor::store", "/store"},
{"//author/ancestor::node()[ancestor::store]", "//book"},
{"//book/ancestor::*", "/store"},
{"//author/ancestor::*[ancestor::store]/ancestor::store", "/store"},
{"//author/ancestor::node()[ancestor::store]", "//book"},

// dot reference
{"//author/ancestor::book/..", "/store"},
{"//author/ancestor::*[ancestor::store]/..", "/store"},
{"//ancestor::book/..", "/store"},
{"//author/ancestor::book/..", "/store"},
{"//author/ancestor::*[ancestor::store]/..", "/store"},
{"//ancestor::book/..", "/store"},

// attributes
{"//author/ancestor::*[@id]/parent::*", "/store"},
{"//author/parent::*[@id]/ancestor::*", "/store"},
{"//author[@id='1']/ancestor::book[1]", "//book[1]"},
{"//author[@*]/ancestor::book[1]", "//book[1]"},
{"//author/ancestor::*[@id]/parent::*", "/store"},
{"//author/parent::*[@id]/ancestor::*", "/store"},
{"//author[@id='1']/ancestor::book[1]", "//book[1]"},
{"//author[@*]/ancestor::book[1]", "//book[1]"},

//test ancestor-or-self

// any node, indexing, id
{"/store/ancestor-or-self::*", "/store"},
{"//book[*]/ancestor-or-self::book[1]", "//book[1]"},
{"/store/book[@*]/ancestor-or-self::book[1]", "//book[1]"},
{"//book[@id='1']/ancestor-or-self::book[1]", "//book[1]"},
{"//author[@id='2']/ancestor-or-self::book", "//book[2]"},
{"/store/ancestor-or-self::*", "/store"},
{"//book[*]/ancestor-or-self::book[1]", "//book[1]"},
{"/store/book[@*]/ancestor-or-self::book[1]", "//book[1]"},
{"//book[@id='1']/ancestor-or-self::book[1]", "//book[1]"},
{"//author[@id='2']/ancestor-or-self::book", "//book[2]"},
{"//book[1]/ancestor-or-self::store", "/store"},

};
@@ -158,7 +157,8 @@ public Object[][] getNoResults() {
}

/**
* Verifies XPath ancestor and ancestor-or-self axis specifiers by comparing expression and expected result.
* Verifies XPath ancestor and ancestor-or-self axis specifiers
* by comparing expression and expected result.
* @param exp XPath expression
* @param expected expected result
* @throws Exception if test failed
27 changes: 13 additions & 14 deletions test/jaxp/javax/xml/jaxp/unittest/xpath/XPathPrecedingTest.java
Original file line number Diff line number Diff line change
@@ -40,8 +40,7 @@
/*
* @test
* @bug 8289508
* @library /javax/xml/jaxp/unittest
*
* @library /javax/xml/jaxp/unittest
* @run testng/othervm xpath.XPathPrecedingTest
* @summary Tests for XPath preceding and preceding-sibling axis specifiers.
*/
@@ -76,14 +75,14 @@ public class XPathPrecedingTest {
}

/*
* DataProvider: provides XPath expression using preceding/preceding-sibling
* DataProvider: provides XPath expression using preceding/preceding-sibling
* and the expected node(s) from the expression
*/
@DataProvider(name = "preceding_axes")
public Object[][] getXPathPreceding() {
return new Object[][]{
// test preceding

// any nodes
{"/store/book[1]/author/preceding::*", "/store/book[1]/title"},

@@ -99,7 +98,7 @@ public Object[][] getXPathPreceding() {
{"//author[@id='2']/../preceding::book", "//book[1]"},
{"//author[@id='2']/preceding::node()/preceding::book", "//book[1]"},
{"//author[@id='1']/preceding::title", "//book[1]/title"},

//test preceding-sibling

// any node
@@ -112,7 +111,7 @@ public Object[][] getXPathPreceding() {

// id
{"/store/book[1]/isbn[preceding-sibling::author[@id='1']]", "/store/book[1]/isbn"},

};
}

@@ -144,20 +143,20 @@ public Object[][] getNoResults() {
{"//author[@id='2']/preceding-sibling::book"},
{"//author[@id='2']/preceding-sibling::node()/preceding-sibling::author"},

// attribute / namespace
{"/store/book[2]/@id/preceding-sibling::*"},
{"/store/book/@lang/preceding-sibling::*"},
{"/store/book[2]/namespace::*/preceding-sibling::*"},
// attribute / namespace
{"/store/book[2]/@id/preceding-sibling::*"},
{"/store/book/@lang/preceding-sibling::*"},
{"/store/book[2]/namespace::*/preceding-sibling::*"},

// text node
{"/store/book[2]/isbn/text()/preceding-sibling::*"},
// text node
{"/store/book[2]/isbn/text()/preceding-sibling::*"},

};
}

/**
* Verifies XPath preceding and preceding-sibling axis specifiers by
* comparing expression and expected result.
* Verifies XPath preceding and preceding-sibling axis specifiers by
* comparing expression and expected result.
* @param exp XPath expression
* @param expected expected result
* @throws Exception if test failed