use of org.eclipse.wst.xml.xpath2.processor.Evaluator in project webtools.sourceediting by eclipse.
the class NodeBeforeTest method test_nodeexpression32.
// Evaluation of a Node expression With the operands/operator set with the following format: Sequence of single Element Node "<<" Single Node Element.
// public void test_nodeexpression31() throws Exception {
// String inputFile = "/TestSources/works.xml";
// String xqFile = "/Queries/XQuery/Expressions/Operators/NodeOp/NodeBefore/nodeexpression31.xq";
// String resultFile = "/ExpectedTestResults/Expressions/Operators/NodeOp/NodeBefore/nodeexpression31.txt";
// String expectedResult = getExpectedResult(resultFile);
// URL fileURL = bundle.getEntry(inputFile);
// loadDOMDocument(fileURL);
//
// // Get XML Schema Information for the Document
// XSModel schema = getGrammar();
//
// setupDynamicContext(schema);
//
// String xpath = extractXPathExpression(xqFile, inputFile);
// String actual = null;
// try {
// XPath path = compileXPath(xpath);
//
// Evaluator eval = new DefaultEvaluator(dc, domDoc);
// ResultSequence rs = eval.evaluate(path);
//
// actual = buildResultString(rs);
//
// } catch (XPathParserException ex) {
// actual = ex.code();
// } catch (StaticError ex) {
// actual = ex.code();
// } catch (DynamicError ex) {
// actual = ex.code();
// }
//
// assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual);
//
//
// }
// Evaluation of a Node expression With the operands/operator set with the following format: Sequence of single Element Node "<<" Sequence of single Element Node.
public void test_nodeexpression32() throws Exception {
String inputFile = "/TestSources/staff.xml";
String xqFile = "/Queries/XQuery/Expressions/Operators/NodeOp/NodeBefore/nodeexpression32.xq";
String resultFile = "/ExpectedTestResults/Expressions/Operators/NodeOp/NodeBefore/nodeexpression32.txt";
String expectedResult = getExpectedResult(resultFile);
URL fileURL = bundle.getEntry(inputFile);
loadDOMDocument(fileURL);
// Get XML Schema Information for the Document
XSModel schema = getGrammar();
setupDynamicContext(schema);
String xpath = extractXPathExpression(xqFile, inputFile);
String actual = null;
try {
compileXPath(xpath);
ResultSequence rs = evaluate(domDoc);
actual = buildResultString(rs);
} catch (XPathParserException ex) {
actual = ex.code();
} catch (StaticError ex) {
actual = ex.code();
} catch (DynamicError ex) {
actual = ex.code();
}
assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
use of org.eclipse.wst.xml.xpath2.processor.Evaluator in project webtools.sourceediting by eclipse.
the class AbstractPsychoPathWTPTest method evaluateSimpleXPath.
protected AnyType evaluateSimpleXPath(String xpath, DynamicContext dc, Document doc, Class resultClass) {
XPath path;
try {
path = compileXPath(dc, xpath);
} catch (XPathParserException e) {
throw new RuntimeException("XPath parse: " + e.getMessage(), e);
} catch (StaticError e) {
throw new RuntimeException("Static error: " + e.getMessage(), e);
}
Evaluator eval = new DefaultEvaluator(dc, doc);
ResultSequence rs;
try {
rs = eval.evaluate(path);
} catch (DynamicError e) {
throw new RuntimeException("Evaluation error: " + e.getMessage(), e);
}
assertEquals("Expected single result from \'" + xpath + "\'", 1, rs.size());
AnyType result = rs.first();
assertTrue("Exected XPath result instanceof class " + resultClass.getSimpleName() + " from \'" + xpath + "\', got " + result.getClass(), resultClass.isInstance(result));
return result;
}
use of org.eclipse.wst.xml.xpath2.processor.Evaluator in project webtools.sourceediting by eclipse.
the class TestWTPDOMXPath2 method test_unabbreviatedSyntax_33.
// Evaluates unabbreviated syntax. Evaluate
// "child::*[self::empnum or self::pnum][fn:position() = fn:last()]".
// Selects the last empnum or pnum child of the context node.
public void test_unabbreviatedSyntax_33() throws Exception {
String inputFile = "/TestSources/works-mod.xml";
String xqFile = "/Queries/XQuery/Expressions/PathExpr/UnabbrAxes/unabbreviatedSyntax-33.xq";
String resultFile = "/ExpectedTestResults/Expressions/PathExpr/UnabbrAxes/unabbreviatedSyntax-33.txt";
String expectedResult = getExpectedResult(resultFile);
URL fileURL = bundle.getEntry(inputFile);
domDoc = load(fileURL);
// Get XML Schema Information for the Document
XSModel schema = null;
DynamicContext dc = setupDynamicContext(schema);
String xpath = extractXPathExpression(xqFile, inputFile);
String actual = null;
try {
XPath path = compileXPath(dc, xpath);
Evaluator eval = new DefaultEvaluator(dc, domDoc);
ResultSequence rs = eval.evaluate(path);
actual = buildXMLResultString(rs);
} catch (XPathParserException ex) {
actual = ex.code();
} catch (StaticError ex) {
actual = ex.code();
} catch (DynamicError ex) {
actual = ex.code();
}
assertXMLEqual("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
use of org.eclipse.wst.xml.xpath2.processor.Evaluator in project webtools.sourceediting by eclipse.
the class TestWTPDOMXPath2 method test_unabbreviatedSyntax_27.
// Evaluates unabbreviated syntax. Evaluate
// "/child::works/child::employee[fn:position() = 5]/child::hours[fn:position() = 2]".
// Selects the second "hours" of the fifth "employee" of the "works" whose
// parent is the document node that contains the context node.
public void test_unabbreviatedSyntax_27() throws Exception {
String inputFile = "/TestSources/works-mod.xml";
String xqFile = "/Queries/XQuery/Expressions/PathExpr/UnabbrAxes/unabbreviatedSyntax-27.xq";
String resultFile = "/ExpectedTestResults/Expressions/PathExpr/UnabbrAxes/unabbreviatedSyntax-27.txt";
String expectedResult = getExpectedResult(resultFile);
URL fileURL = bundle.getEntry(inputFile);
domDoc = load(fileURL);
// Get XML Schema Information for the Document
XSModel schema = null;
DynamicContext dc = setupDynamicContext(schema);
String xpath = extractXPathExpression(xqFile, inputFile);
String actual = null;
try {
XPath path = compileXPath(dc, xpath);
Evaluator eval = new DefaultEvaluator(dc, domDoc);
ResultSequence rs = eval.evaluate(path);
actual = buildXMLResultString(rs);
} catch (XPathParserException ex) {
actual = ex.code();
} catch (StaticError ex) {
actual = ex.code();
} catch (DynamicError ex) {
actual = ex.code();
}
assertXMLEqual("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
use of org.eclipse.wst.xml.xpath2.processor.Evaluator in project webtools.sourceediting by eclipse.
the class TestWTPDOMXPath2 method test_Axes079_2.
// elem//node() gets 1 child element.
public void test_Axes079_2() throws Exception {
String inputFile = "/TestSources/Tree1Child.xml";
String xqFile = "/Queries/XQuery/Expressions/PathExpr/Steps/Axes/Axes079.xq";
String resultFile = "/ExpectedTestResults/Expressions/PathExpr/Steps/Axes/Axes079-2.txt";
String expectedResult = getExpectedResult(resultFile);
URL fileURL = bundle.getEntry(inputFile);
domDoc = load(fileURL);
// Get XML Schema Information for the Document
XSModel schema = null;
DynamicContext dc = setupDynamicContext(schema);
String xpath = extractXPathExpression(xqFile, inputFile);
String actual = null;
try {
XPath path = compileXPath(dc, xpath);
Evaluator eval = new DefaultEvaluator(dc, domDoc);
ResultSequence rs = eval.evaluate(path);
actual = buildResultString(rs);
} catch (XPathParserException ex) {
actual = ex.code();
} catch (StaticError ex) {
actual = ex.code();
} catch (DynamicError ex) {
actual = ex.code();
}
assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
Aggregations