Search in sources :

Example 1 with MbengRuleSet

use of com.qwest.mbeng.MbengRuleSet 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 2 with MbengRuleSet

use of com.qwest.mbeng.MbengRuleSet 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)

Example 3 with MbengRuleSet

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

the class ScriptSyntaxValidator method verifyMagicBoxSyntax.

private void verifyMagicBoxSyntax(String script) throws MbengException {
    MbengRuleSet ruleset = new MbengRuleSet("validate", type.equals("EXPRESSION") ? MbengRuleSet.RULESET_EXPR : type.equals("CONDITION") ? MbengRuleSet.RULESET_COND : MbengRuleSet.RULESET_RULE, false, false);
    String varName, varType;
    for (int i = 0; i < variables.size(); i++) {
        varName = variables.get(i).getVariableName();
        varType = variables.get(i).getVariableType();
        if (varType.equals(MbengTableArray.class.getName()))
            ruleset.defineTable(varName, varType, null, null);
        else if (varType.equals(Document.class.getName()))
            ruleset.defineDocument(varName, DomDocument.class.getName());
        else
            ruleset.defineVariable(varName, true);
    }
    ruleset.defineVariable(VariableVO.MASTER_REQUEST_ID, false);
    ruleset.parse(script);
}
Also used : MbengRuleSet(com.qwest.mbeng.MbengRuleSet) MbengTableArray(com.qwest.mbeng.MbengTableArray) DomDocument(com.qwest.mbeng.DomDocument)

Example 4 with MbengRuleSet

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

the class SwingFormGenerator method evaluateCondition.

private boolean evaluateCondition(String name, String cond) {
    try {
        if (cond == null || cond.length() == 0)
            return true;
        MbengRuleSet ruleset = new MyRuleSet(name, MbengRuleSet.RULESET_COND);
        ruleset.parse(cond);
        MbengRuntime runtime = new MbengRuntime(ruleset, new StreamLogger(System.out));
        runtime.bind("$", dataxml);
        return runtime.verify();
    } catch (MbengException e) {
        e.printStackTrace();
        return false;
    }
}
Also used : MbengRuntime(com.qwest.mbeng.MbengRuntime) MbengRuleSet(com.qwest.mbeng.MbengRuleSet) MbengException(com.qwest.mbeng.MbengException) StreamLogger(com.qwest.mbeng.StreamLogger)

Aggregations

MbengRuleSet (com.qwest.mbeng.MbengRuleSet)4 MbengException (com.qwest.mbeng.MbengException)3 MbengRuntime (com.qwest.mbeng.MbengRuntime)3 StreamLogger (com.qwest.mbeng.StreamLogger)3 XmlPath (com.qwest.mbeng.XmlPath)2 DomDocument (com.qwest.mbeng.DomDocument)1 MbengNode (com.qwest.mbeng.MbengNode)1 MbengTableArray (com.qwest.mbeng.MbengTableArray)1