Search in sources :

Example 1 with TestCaseItem

use of com.centurylink.mdw.designer.testing.TestCaseItem in project mdw-designer by CenturyLinkCloud.

the class WorkflowProject method getTestCaseItems.

public List<String> getTestCaseItems(AutomatedTestCase testCase) throws JSONException {
    List<String> items = new ArrayList<>();
    for (TestCaseItem item : testCase.getItems()) {
        String method = "";
        if (item.getObject().has("request")) {
            JSONObject request = item.getObject().getJSONObject("request");
            if (request.has("method"))
                method = "/" + request.getString("method");
        }
        items.add(testCase.getPath() + method + "/" + item.getName());
    }
    return items;
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) TestCaseItem(com.centurylink.mdw.designer.testing.TestCaseItem)

Example 2 with TestCaseItem

use of com.centurylink.mdw.designer.testing.TestCaseItem in project mdw-designer by CenturyLinkCloud.

the class WorkflowPackage method getTestCaseItems.

public List<String> getTestCaseItems(AutomatedTestCase testCase) throws JSONException {
    List<String> items = new ArrayList<>();
    for (TestCaseItem item : testCase.getItems()) {
        String method = "";
        if (item.getObject().has("request")) {
            JSONObject request = item.getObject().getJSONObject("request");
            if (request.has("method"))
                method = "/" + request.getString("method");
        }
        items.add(testCase.getPath() + method + "/" + item.getName());
    }
    return items;
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) TestCaseItem(com.centurylink.mdw.designer.testing.TestCaseItem)

Example 3 with TestCaseItem

use of com.centurylink.mdw.designer.testing.TestCaseItem in project mdw-designer by CenturyLinkCloud.

the class AutomatedTestCase method getItem.

public TestCaseItem getItem(String name, String method) {
    try {
        if (items != null) {
            TestCaseItem testCaseitem = null;
            for (TestCaseItem item : items) {
                JSONObject itemObj = item.getObject();
                String itemObjName = itemObj.getString("name");
                if (name.equals(itemObjName) && item.getObject().has("request")) {
                    JSONObject request = itemObj.getJSONObject("request");
                    if (request.has("method") && request.getString("method").equals(method))
                        testCaseitem = new TestCaseItem(itemName);
                }
                if (testCaseitem != null) {
                    testCaseitem.setObject(itemObj);
                    return testCaseitem;
                }
            }
        }
    } catch (JSONException ex) {
        PluginMessages.log(ex);
    }
    return null;
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) TestCaseItem(com.centurylink.mdw.designer.testing.TestCaseItem)

Example 4 with TestCaseItem

use of com.centurylink.mdw.designer.testing.TestCaseItem in project mdw-designer by CenturyLinkCloud.

the class AutomatedTestCase method setItems.

public void setItems(File caseFile) {
    try {
        String json = new String(FileHelper.read(caseFile));
        JSONObject coll = new JSONObject(json);
        if (coll.has("item")) {
            JSONArray requestItems = coll.getJSONArray("item");
            for (int i = 0; i < requestItems.length(); i++) {
                JSONObject item = requestItems.getJSONObject(i);
                TestCaseItem testCaseItem = new TestCaseItem(item.getString("name"));
                if (item.has("request")) {
                    JSONObject request = item.getJSONObject("request");
                    testCaseItem.getObject().put("request", request);
                }
                addItem(testCaseItem);
            }
        }
    } catch (Exception ex) {
        PluginMessages.log(ex);
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) TestCaseItem(com.centurylink.mdw.designer.testing.TestCaseItem) JSONException(org.json.JSONException)

Example 5 with TestCaseItem

use of com.centurylink.mdw.designer.testing.TestCaseItem in project mdw-designer by CenturyLinkCloud.

the class AutomatedTestSuite method writeTestResults.

public void writeTestResults(AutomatedTestCase exeTestCase) throws JSONException, IOException {
    String jsonString = null;
    File resultsFile = getProject().getFunctionTestResultsFile();
    TestCaseList testCaseList = null;
    if (resultsFile.exists())
        jsonString = new String(Files.readAllBytes(resultsFile.toPath()));
    if (jsonString != null && !jsonString.isEmpty())
        testCaseList = new TestCaseList(getProject().getAssetDir(), new JSONObject(jsonString));
    if (testCaseList == null) {
        testCaseList = new TestCaseList(getProject().getAssetDir());
        testCaseList.setPackageTests(new ArrayList<PackageTests>());
    }
    for (WorkflowPackage pkg : getProject().getTopLevelUserVisiblePackages()) {
        if (pkg.getTestCases() != null && !pkg.getTestCases().isEmpty()) {
            PackageTests pkgTests = testCaseList.getPackageTests(pkg.getName());
            for (AutomatedTestCase autoTestCase : pkg.getTestCases()) {
                com.centurylink.mdw.test.TestCase testCase = null;
                List<com.centurylink.mdw.test.TestCase> cases = new ArrayList<>();
                boolean caseMatched = true;
                if (autoTestCase.isPostman() && exeTestCase.isPostman())
                    testCase = testCaseList.getTestCaseByItemName(autoTestCase.getPath(), exeTestCase.getMethod() + "/" + exeTestCase.getItemName());
                else
                    testCase = testCaseList.getTestCase(autoTestCase.getPath());
                if (testCase == null) {
                    if (autoTestCase.getItems() != null) {
                        for (TestCaseItem item : autoTestCase.getItems()) {
                            com.centurylink.mdw.test.TestCase itemTestCase = new com.centurylink.mdw.test.TestCase(pkg.getName(), new AssetInfo(autoTestCase.getRawFile()));
                            String method = "";
                            if (item.getObject().has("request")) {
                                JSONObject request = item.getObject().getJSONObject("request");
                                if (request.has("method"))
                                    method = request.getString("method");
                            }
                            itemTestCase.setItemName(method + "/" + item.getName());
                            if (exeTestCase.getMethod() != null && exeTestCase.getMethod().equals(method) && exeTestCase.getItemName() != null && exeTestCase.getItemName().equals(item.getName()))
                                testCase = itemTestCase;
                            else
                                cases.add(itemTestCase);
                        }
                    } else
                        testCase = new com.centurylink.mdw.test.TestCase(pkg.getName(), new AssetInfo(autoTestCase.getRawFile()));
                }
                if (pkgTests == null) {
                    PackageDir pkgDir = new PackageDir(getProject().getAssetDir(), pkg.getPackageVO(), null);
                    pkgTests = new PackageTests(pkgDir);
                    pkgTests.setTestCases(new ArrayList<com.centurylink.mdw.test.TestCase>());
                }
                if (testCase != null) {
                    if (testCase.getPackage().equals(pkg.getName()) && !pkgTests.getTestCases().contains(testCase)) {
                        pkgTests.getTestCases().add(testCase);
                        if (!cases.isEmpty())
                            pkgTests.getTestCases().addAll(cases);
                    }
                    if (autoTestCase.getItems() != null && exeTestCase.getItemName() != null && !(exeTestCase.getMethod() + "/" + exeTestCase.getItemName()).equals(testCase.getItemName()))
                        caseMatched = false;
                    if (exeTestCase.getPath().equals(autoTestCase.getPath()) && caseMatched) {
                        getProject().fireTestCaseStatusChange(exeTestCase, autoTestCase.getStatus());
                        testCase.setStatus(exeTestCase.getCaseStatus());
                        testCase.setStart(exeTestCase.getStartTime());
                        testCase.setEnd(exeTestCase.getEndTime());
                        testCase.setMessage(exeTestCase.getMessage());
                    }
                }
            }
            if (!testCaseList.getPackageTests().contains(pkgTests))
                testCaseList.getPackageTests().add(pkgTests);
        }
    }
    testCaseList.setCount(testCaseList.getTestCases().size());
    PluginUtil.writeFile(resultsFile, testCaseList.getJson().toString(2).getBytes());
}
Also used : TestCaseList(com.centurylink.mdw.test.TestCaseList) ArrayList(java.util.ArrayList) TestCaseItem(com.centurylink.mdw.designer.testing.TestCaseItem) AssetInfo(com.centurylink.mdw.test.AssetInfo) PackageTests(com.centurylink.mdw.test.PackageTests) JSONObject(org.json.JSONObject) TestCase(com.centurylink.mdw.designer.testing.TestCase) PackageDir(com.centurylink.mdw.dataaccess.file.PackageDir) File(java.io.File)

Aggregations

TestCaseItem (com.centurylink.mdw.designer.testing.TestCaseItem)5 JSONObject (org.json.JSONObject)5 ArrayList (java.util.ArrayList)3 JSONException (org.json.JSONException)2 PackageDir (com.centurylink.mdw.dataaccess.file.PackageDir)1 TestCase (com.centurylink.mdw.designer.testing.TestCase)1 AssetInfo (com.centurylink.mdw.test.AssetInfo)1 PackageTests (com.centurylink.mdw.test.PackageTests)1 TestCaseList (com.centurylink.mdw.test.TestCaseList)1 File (java.io.File)1 JSONArray (org.json.JSONArray)1