Search in sources :

Example 1 with XmlPath

use of com.qwest.mbeng.XmlPath in project mdw-designer by CenturyLinkCloud.

the class GroovyTestCaseScript method xpath.

/**
 * Matches according to MDW XPath.
 */
public Closure<Boolean> xpath(final String condition) throws TestException {
    return new Closure<Boolean>(this, this) {

        @Override
        public Boolean call(Object request) {
            try {
                XmlPath xpath = new XmlPath(condition);
                String v = xpath.evaluate(TestDataFilter.parseRequest(request.toString()));
                return v != null;
            } catch (MbengException ex) {
                getTestCaseRun().log.println("Failed to parse request as XML/JSON. Stub response: " + AdapterActivity.MAKE_ACTUAL_CALL);
                return false;
            }
        }
    };
}
Also used : XmlPath(com.qwest.mbeng.XmlPath) MbengException(com.qwest.mbeng.MbengException) Closure(groovy.lang.Closure) JSONObject(org.json.JSONObject)

Example 2 with XmlPath

use of com.qwest.mbeng.XmlPath in project mdw-designer by CenturyLinkCloud.

the class TestCaseRun method stubMatch.

protected boolean stubMatch(String condition, MbengDocument reqdoc) {
    try {
        if (condition.contains("$")) {
            MbengRuleSet ruleset = new MyRuleSet("stub_condition", MbengRuleSet.RULESET_COND);
            ruleset.parse(condition);
            MbengRuntime runtime = new MbengRuntime(ruleset, new StreamLogger(System.out));
            runtime.bind("$", reqdoc);
            return runtime.verify();
        } else {
            XmlPath xpath = new XmlPath(condition);
            String v = xpath.evaluate(reqdoc);
            return v != null;
        }
    } catch (MbengException e) {
        log.println("Exception in evaluating condition in stub: " + e.getMessage());
        return false;
    }
}
Also used : MbengRuntime(com.qwest.mbeng.MbengRuntime) XmlPath(com.qwest.mbeng.XmlPath) MbengRuleSet(com.qwest.mbeng.MbengRuleSet) MbengException(com.qwest.mbeng.MbengException) StreamLogger(com.qwest.mbeng.StreamLogger)

Example 3 with XmlPath

use of com.qwest.mbeng.XmlPath in project mdw-designer by CenturyLinkCloud.

the class TestDataFilter method evaluateExpression.

private String evaluateExpression(String exp, MbengDocument refdata) {
    try {
        if (exp.startsWith("/")) {
            // assuming XPath expression
            XmlPath xpathobj = new XmlPath(exp);
            MbengNode node = xpathobj.findNode(refdata);
            return node == null ? null : node.getValue();
        } else {
            MbengRuleSet ruleset = new MyRuleSet("filter_exp", MbengRuleSet.RULESET_EXPR);
            ruleset.parse(exp);
            MbengRuntime runtime = new MbengRuntime(ruleset, new StreamLogger(System.out));
            runtime.bind("$", refdata);
            return runtime.evaluate();
        }
    } catch (MbengException e) {
        log.println("Exception in evaluating expression in test data filter " + exp + ": " + e.getMessage());
        return null;
    }
}
Also used : XmlPath(com.qwest.mbeng.XmlPath) MbengRuntime(com.qwest.mbeng.MbengRuntime) MbengRuleSet(com.qwest.mbeng.MbengRuleSet) MbengException(com.qwest.mbeng.MbengException) StreamLogger(com.qwest.mbeng.StreamLogger) MbengNode(com.qwest.mbeng.MbengNode)

Aggregations

MbengException (com.qwest.mbeng.MbengException)3 XmlPath (com.qwest.mbeng.XmlPath)3 MbengRuleSet (com.qwest.mbeng.MbengRuleSet)2 MbengRuntime (com.qwest.mbeng.MbengRuntime)2 StreamLogger (com.qwest.mbeng.StreamLogger)2 MbengNode (com.qwest.mbeng.MbengNode)1 Closure (groovy.lang.Closure)1 JSONObject (org.json.JSONObject)1