### Question:
XPath20ExpressionRuntime implements ExpressionLanguageRuntime { @SuppressWarnings("unchecked") public List evaluate(OExpression cexp, EvaluationContext ctx) throws FaultException, EvaluationException { List result; Object someRes = null; try { someRes = evaluate(cexp, ctx, XPathConstants.NODESET); } catch (Exception e) { someRes = evaluate(cexp, ctx, XPathConstants.STRING); } if (someRes instanceof List) { result = (List) someRes; if (__log.isDebugEnabled()) { __log.debug("Returned list of size " + result.size()); } if ((result.size() == 1) && !(result.get(0) instanceof Node)) { Object simpleType = result.get(0); String textVal; if (simpleType instanceof Date) { textVal = ISO8601DateParser.format((Date) simpleType); } else if (simpleType instanceof DurationValue) { textVal = ((DurationValue)simpleType).getStringValue(); } else { textVal = simpleType.toString(); } Document document = DOMUtils.newDocument(); Element wrapper = document.createElement("wrapper"); Text text = document.createTextNode(textVal); wrapper.appendChild(text); document.appendChild(wrapper); result = Collections.singletonList(text); } } else if (someRes instanceof NodeList) { NodeList retVal = (NodeList) someRes; if (__log.isDebugEnabled()) { __log.debug("Returned node list of size " + retVal.getLength()); } result = new ArrayList(retVal.getLength()); for(int m = 0; m < retVal.getLength(); ++m) { Node val = retVal.item(m); if (val.getNodeType() == Node.DOCUMENT_NODE) { val = ((Document)val).getDocumentElement(); } result.add(val); } } else if (someRes instanceof String) { Document document = DOMUtils.newDocument(); Element wrapper = document.createElement("wrapper"); Text text = document.createTextNode((String) someRes); wrapper.appendChild(text); document.appendChild(wrapper); result = Collections.singletonList(text); } else { result = null; } return result; } 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 testMessageInsertMissingData() throws Exception { String insertElementName="InsertedNode"; OXPath20ExpressionBPEL20 exp = compile("$messageVar.parameters/"+insertElementName); exp.setInsertMissingData(true); _rootNode = DOMUtils.stringToDOM("<message><parameters>" + "<tns:ApplicationData xmlns:tns=\"http: java.util.List<?> list = _runtime.evaluate(exp, this); if (list == null || list.size() != 0) { fail("List should have no elements"); } if (((Element)_rootNode).getElementsByTagName(insertElementName).getLength() != 1) { fail("Missing '"+insertElementName+"' element has not been inserted"); } }
@Test public void testVariableInsertMissingData() throws Exception { String insertElementName="InsertedNode"; OXPath20ExpressionBPEL20 exp = compile("$reallyEmptyVar/"+insertElementName); exp.setInsertMissingData(true); _rootNode = DOMUtils.stringToDOM("<tns:ApplicationData xmlns:tns=\"http: java.util.List<?> list = _runtime.evaluate(exp, this); if (list == null || list.size() != 0) { fail("List should have no elements"); } if (((Element)_rootNode).getElementsByTagName(insertElementName).getLength() != 1) { fail("Missing '"+insertElementName+"' element has not been inserted"); } }