Search in sources :

Example 1 with MbengException

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

the class Graph method addNode.

private Node addNode(GraphCommon owner, ActivityImplementorVO nmi, int x, int y, boolean recordchange) {
    String name = "New " + nmi.getLabel();
    if (nmi.isManualTask()) {
        if (owner instanceof SubGraph)
            name = processVO.getProcessName() + " Fallout";
        else
            name = "New Task for " + processVO.getProcessName();
    }
    Long pActId = genNodeId();
    String pDesc = null;
    String pActImplClass = nmi.getImplementorClassName();
    ArrayList<AttributeVO> pAttribs = new ArrayList<AttributeVO>();
    if (nmi.isManualTask()) {
        pAttribs.add(new AttributeVO(TaskActivity.ATTRIBUTE_TASK_NAME, name));
        pAttribs.add(new AttributeVO(TaskActivity.ATTRIBUTE_TASK_CATEGORY, "COM"));
        pAttribs.add(new AttributeVO(TaskActivity.ATTRIBUTE_TASK_VARIABLES, TaskVO.getVariablesAsString(processVO.getVariables(), null)));
    }
    ActivityVO nodet = new ActivityVO(pActId, name, pDesc, pActImplClass, pAttribs);
    owner.getProcessVO().getActivities().add(nodet);
    Node node = new Node(nodet, owner, metainfo);
    String iconname = node.getIconName();
    javax.swing.Icon icon = getIconFactory().getIcon(iconname);
    if (nodestyle.equals(Node.NODE_STYLE_ICON)) {
        node.w = icon.getIconWidth();
        node.h = icon.getIconHeight();
    } else {
        if (icon instanceof ImageIcon) {
            node.w = 100;
            node.h = 60;
        } else {
            node.w = 60;
            node.h = 40;
        }
    }
    node.x = x;
    node.y = y;
    owner.nodes.add(node);
    String xmldesc = nmi.getAttributeDescription();
    if (xmldesc != null && xmldesc.length() > 0) {
        FormatDom fmter = new FormatDom();
        DomDocument doc = new DomDocument();
        try {
            fmter.load(doc, xmldesc);
            MbengNode widget;
            String default_value, attr_name;
            for (widget = doc.getRootNode().getFirstChild(); widget != null; widget = widget.getNextSibling()) {
                default_value = widget.getAttribute("DEFAULT");
                if (default_value == null)
                    continue;
                if (widget.getAttribute("UNITS_ATTR") != null)
                    continue;
                attr_name = widget.getAttribute("NAME");
                if (attr_name == null)
                    continue;
                if (default_value.equals("$DefaultNotices")) {
                    node.setAttribute(attr_name, TaskVO.getDefaultNotices());
                } else
                    node.setAttribute(attr_name, default_value);
            }
        } catch (MbengException e) {
        }
    }
    if (recordchange)
        node.getChanges().setChangeType(Changes.NEW);
    setDirtyLevel(DIRTY);
    return node;
}
Also used : ImageIcon(javax.swing.ImageIcon) MbengException(com.qwest.mbeng.MbengException) AttributeVO(com.centurylink.mdw.model.value.attribute.AttributeVO) ActivityVO(com.centurylink.mdw.model.value.activity.ActivityVO) MbengNode(com.qwest.mbeng.MbengNode) FormatDom(com.qwest.mbeng.FormatDom) ArrayList(java.util.ArrayList) MbengNode(com.qwest.mbeng.MbengNode) DomDocument(com.qwest.mbeng.DomDocument)

Example 2 with MbengException

use of com.qwest.mbeng.MbengException 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 3 with MbengException

use of com.qwest.mbeng.MbengException 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 4 with MbengException

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

the class TestCaseRun method getStubResponse.

public String getStubResponse(String masterRequestId, String request, int run) throws JSONException, TestException {
    if (request != null && request.startsWith("{\"ActivityRuntimeContext\":"))
        // no activity stubbing in old-style test syntax
        return "(EXECUTE_ACTIVITY)";
    MbengDocument reqdoc;
    if (verbose)
        log.println("Stub request: " + request);
    try {
        reqdoc = TestDataFilter.parseRequest(request);
    } catch (MbengException e1) {
        log.println("Failed to parse request as XML/JSON. Stub response: " + AdapterActivity.MAKE_ACTUAL_CALL);
        return AdapterActivity.MAKE_ACTUAL_CALL;
    }
    for (TestFileLine cmd : testcase.getCommands().getLines()) {
        if (cmd.getCommand().equalsIgnoreCase(TestCase.STUB)) {
            String condition = cmd.getWord(1);
            if (stubMatch(condition, reqdoc)) {
                int delay;
                String response;
                if (cmd.getWordCount() == 4) {
                    delay = Integer.parseInt(cmd.getWord(2));
                    response = cmd.getWord(3);
                } else {
                    response = cmd.getWord(2);
                    delay = 0;
                }
                response = stubResponseFilter(response, masterRequestId, reqdoc, run);
                response = "RESPONSE~" + delay + "~" + response;
                if (verbose)
                    log.println("Stub response: " + response);
                return response;
            }
        }
    }
    if (verbose)
        log.println("Stub response: " + AdapterActivity.MAKE_ACTUAL_CALL);
    return AdapterActivity.MAKE_ACTUAL_CALL;
}
Also used : MbengException(com.qwest.mbeng.MbengException) MbengDocument(com.qwest.mbeng.MbengDocument)

Example 5 with MbengException

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

the class TestCaseRun method executeVerifyResponse.

protected boolean executeVerifyResponse(String expected, String actual, String reference) throws TestException, IOException, DataAccessException, ParseException {
    expected = expected.replaceAll("\r", "");
    if (verbose)
        log.println("comparing response...");
    if (actual != null) {
        actual = actual.replaceAll("\r", "");
        Map<String, String> map = new HashMap<>();
        map.put(TestDataFilter.MasterRequestId, this.masterRequestId);
        map.put(TestDataFilter.RunNumber, Integer.toString(runNumber));
        TestDataFilter filter = new TestDataFilter(expected, log, true);
        MbengDocument refdoc;
        if (reference != null) {
            try {
                refdoc = TestDataFilter.parseRequest(reference);
            } catch (MbengException e) {
                log.println("Failed to parse reference document as XML/JSON: " + e.getMessage());
                refdoc = null;
            }
        } else
            refdoc = null;
        expected = filter.applyFilters(map, refdoc);
        expected = filter.applyAnyNumberFilters(expected, actual);
    }
    if (!expected.equals(actual)) {
        int firstDiffLine = TestCompare.matchRegex(expected, actual);
        if (firstDiffLine != 0) {
            passed = false;
            message = "response differs from line: " + firstDiffLine;
            if (!verbose) {
                // otherwise it was logged previously
                log.format("+++++ " + message + "\r%n");
                log.format("Actual response: %s\r%n", actual);
            }
            throw new TestFailedException(message);
        }
    }
    return passed;
}
Also used : MbengException(com.qwest.mbeng.MbengException) HashMap(java.util.HashMap) MbengDocument(com.qwest.mbeng.MbengDocument)

Aggregations

MbengException (com.qwest.mbeng.MbengException)14 MbengNode (com.qwest.mbeng.MbengNode)6 MbengDocument (com.qwest.mbeng.MbengDocument)3 MbengRuleSet (com.qwest.mbeng.MbengRuleSet)3 MbengRuntime (com.qwest.mbeng.MbengRuntime)3 StreamLogger (com.qwest.mbeng.StreamLogger)3 XmlPath (com.qwest.mbeng.XmlPath)3 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)1 FormDataDocument (com.centurylink.mdw.model.FormDataDocument)1 ActivityVO (com.centurylink.mdw.model.value.activity.ActivityVO)1 AttributeVO (com.centurylink.mdw.model.value.attribute.AttributeVO)1 BamMessageDefinition (com.centurylink.mdw.model.value.event.BamMessageDefinition)1 ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)1 TaskInstanceVO (com.centurylink.mdw.model.value.task.TaskInstanceVO)1 ActivityInstanceVO (com.centurylink.mdw.model.value.work.ActivityInstanceVO)1 WorkTransitionInstanceVO (com.centurylink.mdw.model.value.work.WorkTransitionInstanceVO)1 WorkTransitionVO (com.centurylink.mdw.model.value.work.WorkTransitionVO)1 DomDocument (com.qwest.mbeng.DomDocument)1