Assert the value of an Xpath expression in an DOM Document
@param expectedValue
@param xpathExpression
@param inDocument
@see XpathEngine which provides the underlying evaluation mechanism
183466
public static void assertXpathEvaluatesTo(QualifiedName expectedValue,
                                              String xpathExpression,
                                              Document inDocument)
        throws XpathException {
        XpathEngine simpleXpathEngine = XMLUnit.newXpathEngine();
        NodeList nl =
            simpleXpathEngine.getMatchingNodes(xpathExpression, inDocument);
        NamespaceContext ctx = null;
        if (nl.getLength() > 0) {
            ctx = new NodeBasedNamespaceContext(nl.item(0));
        }
        assertEquals(expectedValue,
                     QualifiedName
                     .valueOf(simpleXpathEngine.evaluate(xpathExpression,
                                                         inDocument),
                              ctx));
    }
216872
public static Object evaluateExpression(Node node, String xPathExpression, NamespaceContext nsContext, QName returnType) {
        try {
            return buildExpression(xPathExpression, nsContext).evaluate(node, returnType);
        } catch (XPathExpressionException e) {
            throw new CitrusRuntimeException("Can not evaluate xpath expression '" + xPathExpression + "'", e);
        }
    }
1300648
public void hasValue(long expected) {
    if (actual() == null) {
      failWithActual("expected an optional with value", expected);
    } else if (!actual().isPresent()) {
      failWithoutActual(fact("expected to have value", expected), simpleFact("but was absent"));
    } else {
      checkNoNeedToDisplayBothValues("getAsLong()").that(actual().getAsLong()).isEqualTo(expected);
    }
  }
1248927
public static String evaluate(String xpath, String html) throws XPathExpressionException,
            ParserConfigurationException {
        HtmlCleaner hc = new HtmlCleaner();
        TagNode tn = hc.clean(html);
        Document document = new DomSerializer(new CleanerProperties()).createDOM(tn);
        XPath xPath = XPathFactory.newInstance().newXPath();
        return xPath.evaluate(xpath, document);
    }
983174
private static <T> T getAnnotationValue(Annotation annotation, String value, Class<T> expectedType) {
        Class<? extends Annotation> annotationType = annotation.annotationType();
        Method valueMethod;
        try {
            valueMethod = annotationType.getDeclaredMethod(value);
        } catch (NoSuchMethodException e) {
            throw new IllegalStateException("Cannot resolve required method '" + value + "()' for '" + annotationType + "'.");
        }
        Object elementValue;
        try {
            elementValue = valueMethod.invoke(annotation);
        } catch (ReflectiveOperationException e) {
            throw new IllegalStateException("Cannot invoke method value() for " + annotationType);
        }
        return elementValue != null ? expectedType.cast(elementValue) : null;
    }
948800
function (newValue) {
            var barEl = this.getDom().childNodes[0];
            if (barEl !== null) {
                barEl.innerHTML = newValue;
            }
            barEl = null;
        }
549830
protected boolean matchesExpectation(LightweightTypeReference elementType, LightweightTypeReference expectation) {
		return expectation != null && expectation.isResolved() && !expectation.isWildcard() && expectation.isAssignableFrom(elementType);
	}
1243582
private Attribute attributeAnnotationValue(Type expectedElementType, JCExpression tree,
            Env<AttrContext> env)
    {
        //first, try completing the symbol for the annotation value - if acompletion
        //error is thrown, we should recover gracefully, and display an
        //ordinary resolution diagnostic.
        try {
            expectedElementType.tsym.complete();
        } catch(CompletionFailure e) {
            log.error(tree.pos(), "cant.resolve", Kinds.kindName(e.sym), e.sym);
            expectedElementType = syms.errType;
        }

        if (expectedElementType.hasTag(ARRAY)) {
            return getAnnotationArrayValue(expectedElementType, tree, env);

        }

        //error recovery
        if (tree.hasTag(NEWARRAY)) {
            if (!expectedElementType.isErroneous())
                log.error(tree.pos(), "annotation.value.not.allowable.type");
            JCNewArray na = (JCNewArray)tree;
            if (na.elemtype != null) {
                log.error(na.elemtype.pos(), "new.not.allowed.in.annotation");
            }
            for (List<JCExpression> l = na.elems; l.nonEmpty(); l=l.tail) {
                attributeAnnotationValue(syms.errType,
                        l.head,
                        env);
            }
            return new Attribute.Error(syms.errType);
        }

        if (expectedElementType.tsym.isAnnotationType()) {
            if (tree.hasTag(ANNOTATION)) {
                return attributeAnnotation((JCAnnotation)tree, expectedElementType, env);
            } else {
                log.error(tree.pos(), "annotation.value.must.be.annotation");
                expectedElementType = syms.errType;
            }
        }

        //error recovery
        if (tree.hasTag(ANNOTATION)) {
            if (!expectedElementType.isErroneous())
                log.error(tree.pos(), "annotation.not.valid.for.type", expectedElementType);
            attributeAnnotation((JCAnnotation)tree, syms.errType, env);
            return new Attribute.Error(((JCAnnotation)tree).annotationType.type);
        }

        if (expectedElementType.isPrimitive() ||
                (types.isSameType(expectedElementType, syms.stringType) && !expectedElementType.hasTag(TypeTag.ERROR))) {
            return getAnnotationPrimitiveValue(expectedElementType, tree, env);
        }

        if (expectedElementType.tsym == syms.classType.tsym) {
            return getAnnotationClassValue(expectedElementType, tree, env);
        }

        if (expectedElementType.hasTag(CLASS) &&
                (expectedElementType.tsym.flags() & Flags.ENUM) != 0) {
            return getAnnotationEnumValue(expectedElementType, tree, env);
        }

        //error recovery:
        if (!expectedElementType.isErroneous())
            log.error(tree.pos(), "annotation.value.not.allowable.type");
        return new Attribute.Error(attr.attribExpr(tree, env, expectedElementType));
    }
824819
public static void assertXpathsEqual(String controlXpath,
                                         Document controlDocument,
                                         String testXpath,
                                         Document testDocument)
        throws XpathException {
        assertXpathEquality(controlXpath, controlDocument, testXpath,
                            testDocument, true);
    }
75972
private void evaluateExpressions() throws JspException {
        /*
         * Note: we don't check for type mismatches here; we assume
         * the expression evaluator will return the expected type
         * (by virtue of knowledge we give it about what that type is).
         * A ClassCastException here is truly unexpected, so we let it
         * propagate up.
         */

        if (begin_ != null) {
            Object r = ExpressionEvaluatorManager.evaluate(
                    "begin", begin_, Integer.class, this, pageContext);
            if (r == null) {
                throw new NullAttributeException("forTokens", "begin");
            }
            begin = ((Integer) r).intValue();
            validateBegin();
        }

        if (end_ != null) {
            Object r = ExpressionEvaluatorManager.evaluate(
                    "end", end_, Integer.class, this, pageContext);
            if (r == null) {
                throw new NullAttributeException("forTokens", "end");
            }
            end = ((Integer) r).intValue();
            validateEnd();
        }

        if (step_ != null) {
            Object r = ExpressionEvaluatorManager.evaluate(
                    "step", step_, Integer.class, this, pageContext);
            if (r == null) {
                throw new NullAttributeException("forTokens", "step");
            }
            step = ((Integer) r).intValue();
            validateStep();
        }

        if (items_ != null) {
            items = (String) ExpressionEvaluatorManager.evaluate(
                    "items", items_, String.class, this, pageContext);
            // use the empty string to indicate "no iteration"
            if (items == null) {
                items = "";
            }
        }

        if (delims_ != null) {
            delims = (String) ExpressionEvaluatorManager.evaluate(
                    "delims", delims_, String.class, this, pageContext);
            // use the empty string to cause monolithic tokenization
            if (delims == null) {
                delims = "";
            }
        }
    }
669047
public static Node getElement(Node node, String xExpr, XPath xPath) throws XPathExpressionException {
        return (Node) xPath.compile(xExpr).evaluate(node, XPathConstants.NODE);
    }
455943
public static void assertXpathsEqual(String controlXpath, String testXpath,
                                         Document document)
        throws XpathException {
        assertXpathsEqual(controlXpath, document, testXpath, document);
    }
917092
public static void assertXpathExists(String xPathExpression, 
                                         Document inDocument)
        throws XpathException {
        XpathEngine simpleXpathEngine = XMLUnit.newXpathEngine();
        NodeList nodeList = simpleXpathEngine.getMatchingNodes(
                                                               xPathExpression, inDocument);
        int matches = nodeList.getLength();
        assertTrue("Expecting to find matches for Xpath " + 
                   xPathExpression, matches > 0);
    }
820295
public void annotateDefaultValueLater(JCExpression defaultValue, Env<AttrContext> localEnv,
            MethodSymbol m, DiagnosticPosition deferPos)
    {
        normal(() -> {
            JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
            DiagnosticPosition prevLintPos = deferredLintHandler.setPos(deferPos);
            try {
                enterDefaultValue(defaultValue, localEnv, m);
            } finally {
                deferredLintHandler.setPos(prevLintPos);
                log.useSource(prev);
            }
        });

        validate(() -> { //validate annotations
            JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
            try {
                // if default value is an annotation, check it is a well-formed
                // annotation value (e.g. no duplicate values, no missing values, etc.)
                chk.validateAnnotationTree(defaultValue);
            } finally {
                log.useSource(prev);
            }
        });
    }
191432
public static Object evalNotNull(String tagName,
                                     String attributeName,
                                     String expression,
                                     Class expectedType,
                                     Tag tag,
                                     PageContext pageContext)
            throws JspException {
        if (expression != null) {
            Object r = ExpressionEvaluatorManager.evaluate(
                    attributeName, expression, expectedType, tag, pageContext);
            if (r == null) {
                throw new NullAttributeException(tagName, attributeName);
            }
            return r;
        } else {
            return null;
        }
    }
168281
private @Nonnull NodeList evaluate(String xpath) {
        try {
            XPathExpression expr = xpf.newXPath().compile(xpath);
            return (NodeList) expr.evaluate(node, XPathConstants.NODESET);
        } catch (XPathExpressionException ex) {
            throw new IllegalArgumentException("Invalid XPath '" + xpath + "'", ex);
        }
    }
1124147
public static void assertXpathValuesNotEqual(String controlXpath,
                                                 InputSource control,
                                                 String testXpath,
                                                 InputSource test)
        throws SAXException, IOException, XpathException {
        assertXpathValuesNotEqual(controlXpath,
                                  XMLUnit.buildControlDocument(control),
                                  testXpath,
                                  XMLUnit.buildTestDocument(test));
    }