### Question:
XPath20ExpressionRuntime implements ExpressionLanguageRuntime { public Node evaluateNode(OExpression cexp, EvaluationContext ctx) throws FaultException, EvaluationException { List retVal = evaluate(cexp, ctx); if (retVal.size() == 0 || retVal.size() > 1) { StringBuffer msg = new StringBuffer((retVal.size() == 0) ? "No results for expression: '" : "Multiple results for expression: '"); if (cexp instanceof OXPath10Expression) { msg.append(((OXPath10Expression)cexp).getXpath()); } else { msg.append(cexp.toString()); } msg.append('\''); if (ctx.getRootNode() != null) { msg.append(" against '"); msg.append(DOMUtils.domToString(ctx.getRootNode())); msg.append('\''); } if (retVal.size() == 0) throw new FaultException(cexp.getOwner().getConstants().getQnSelectionFailure(), msg.toString(), new Throwable("ignoreMissingFromData")); if (retVal.size() > 1) throw new FaultException(cexp.getOwner().getConstants().getQnSelectionFailure(), msg.toString()); } return (Node) retVal.get(0); } XPath20ExpressionRuntime(); void initialize(Map properties); String evaluateAsString(OExpression cexp, EvaluationContext ctx); boolean evaluateAsBoolean(OExpression cexp, EvaluationContext ctx); Number evaluateAsNumber(OExpression cexp, EvaluationContext ctx); @SuppressWarnings("unchecked") List evaluate(OExpression cexp, EvaluationContext ctx); Node evaluateNode(OExpression cexp, EvaluationContext ctx); Calendar evaluateAsDate(OExpression cexp, EvaluationContext context); Duration evaluateAsDuration(OExpression cexp, EvaluationContext context);  }### Answer:
@Test public void testVariableSelection() throws Exception { OXPath20ExpressionBPEL20 exp = compile("$foo"); Node retVal = _runtime.evaluateNode(exp, this); assertNotNull(retVal); assertSame(retVal , _vars.get("foo")); assertSame(retVal.getOwnerDocument(),_vardoc); }
@Test public void testVariableSelectionEmpty() throws Exception { OXPath20ExpressionBPEL20 exp = compile("$emptyVar"); Node retVal = _runtime.evaluateNode(exp, this); assertNotNull(retVal); assertSame(retVal , _vars.get("emptyVar")); assertTrue(DOMUtils.getFirstChildElement((Element)retVal).getLocalName().equals("empty")); }
@Test public void testVariableSelectionReallyEmpty() throws Exception { OXPath20ExpressionBPEL20 exp = compile("$reallyEmptyVar"); Node retVal = _runtime.evaluateNode(exp, this); assertNotNull(retVal); assertSame(retVal , _vars.get("reallyEmptyVar")); assertNull(DOMUtils.getFirstChildElement((Element)retVal)); }
@Test public void testXpathDocFunction() throws Exception { URL url = getClass().getResource("/xpath20/variables.xml"); OXPath20ExpressionBPEL20 exp = compile("doc('" + url.toExternalForm() + "')"); Node retVal = _runtime.evaluateNode(exp, this); assertNotNull(retVal); assertEquals("Unexpected root node", "variables", retVal.getNodeName()); }
@Test public void testMessageTypeVariableSelection() throws Exception { OXPath20ExpressionBPEL20 exp = compile("$messageVar.parameters"); Node retVal = _runtime.evaluateNode(exp, this); assertNotNull(retVal); assertSame(retVal , _vars.get("messageVar")); assertSame(retVal.getOwnerDocument(),_vardoc); }