Search in sources :

Example 1 with MbengDocument

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

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

Example 3 with MbengDocument

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

the class TestCaseRun method sendMessage.

protected String sendMessage(TestCaseAsset testCaseAsset, String protocol, String msg, String reference) throws IOException, DataAccessException {
    TestDataFilter filter = new TestDataFilter(msg, log, true);
    Map<String, String> map = new HashMap<>();
    map.put(TestDataFilter.MasterRequestId, this.masterRequestId);
    map.put(TestDataFilter.RunNumber, Integer.toString(runNumber));
    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;
    // TODO: XLSX asset instead of CSV
    File mapfile;
    if (testcase.isLegacy())
        mapfile = new File(testcase.getCaseDirectory().getPath() + "/" + TestCase.PLACEHOLDER_MAP_FILENAME);
    else
        mapfile = new File(testCaseAsset.getPackageDir() + "/" + TestCase.PLACEHOLDER_MAP_FILENAME);
    TestDataFilter.loadPlaceHolderMap(mapfile, map, runNumber);
    msg = filter.applyFilters(map, refdoc);
    String server = getNextServer();
    if (server == null)
        return dao.sendMessage(protocol, msg, getDefaultMessageHeaders());
    else
        return dao.engineCall(dao.getPeerServerUrl(server), msg, getDefaultMessageHeaders());
}
Also used : MbengException(com.qwest.mbeng.MbengException) HashMap(java.util.HashMap) MbengDocument(com.qwest.mbeng.MbengDocument) File(java.io.File)

Example 4 with MbengDocument

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

the class AttributesTableContainer method createTableEditor.

private void createTableEditor(Composite parent) {
    FormatXml fmter = new FormatXml();
    MbengDocument mbengDocument = new MbengDocumentClass();
    try {
        fmter.load(mbengDocument, pageletTable.xmlText());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    tableEditor = new TableEditor(null, mbengDocument.getRootNode());
    // label was already rendered
    tableEditor.setLabel(null);
    tableEditor.setModelUpdater(new TableModelUpdater() {

        public Object create() {
            int i = 1;
            String attrName = "New Field";
            while (getAttribute(attrName) != null) attrName = "New Field (" + i++ + ")";
            return new AttributeVO(attrName, null);
        }

        @SuppressWarnings("rawtypes")
        public void updateModelValue(List tableValue) {
            fireDirtyStateChange(true);
        }
    });
    tableEditor.setCellModifier(new AttributeCellModifier());
    tableEditor.setContentProvider(new AttributeContentProvider());
    tableEditor.setLabelProvider(new AttributeLabelProvider());
    tableEditor.addValueChangeListener(new ValueChangeListener() {

        public void propertyValueChanged(Object newValue) {
        // value changed
        }
    });
    tableEditor.render(parent, true);
}
Also used : AttributeVO(com.centurylink.mdw.model.value.attribute.AttributeVO) TableModelUpdater(com.centurylink.mdw.plugin.designer.properties.editor.TableEditor.TableModelUpdater) FormatXml(com.qwest.mbeng.FormatXml) MbengDocument(com.qwest.mbeng.MbengDocument) ArrayList(java.util.ArrayList) List(java.util.List) MbengDocumentClass(com.qwest.mbeng.MbengDocumentClass)

Aggregations

MbengDocument (com.qwest.mbeng.MbengDocument)4 MbengException (com.qwest.mbeng.MbengException)3 HashMap (java.util.HashMap)2 AttributeVO (com.centurylink.mdw.model.value.attribute.AttributeVO)1 TableModelUpdater (com.centurylink.mdw.plugin.designer.properties.editor.TableEditor.TableModelUpdater)1 FormatXml (com.qwest.mbeng.FormatXml)1 MbengDocumentClass (com.qwest.mbeng.MbengDocumentClass)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1