Search in sources :

Example 1 with TestCase

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

the class WorkflowProject method findTopLevelPackages.

/**
 * Finds the list of top level packages (including the default if
 * supported), populated with the appropriate processes, etc.
 */
private void findTopLevelPackages(ProgressMonitor progressMonitor) {
    CodeTimer timer = new CodeTimer("findTopLevelPackages()");
    topLevelPackages = new ArrayList<>();
    topLevelUserVisiblePackages = new ArrayList<>();
    activityImpls.clear();
    for (PackageVO packageVO : getTopLevelPackageVOs(progressMonitor)) {
        WorkflowPackage topLevelPackage = new WorkflowPackage(this, packageVO);
        topLevelPackage.setProcesses(findProcesses(topLevelPackage));
        topLevelPackage.setExternalEvents(findExternalEvents(topLevelPackage));
        topLevelPackage.setActivityImpls(findActivityImplementors(topLevelPackage));
        topLevelPackage.setAssets(findWorkflowAssets(topLevelPackage));
        topLevelPackage.setTaskTemplates(findTaskTemplates(topLevelPackage));
        topLevelPackages.add(topLevelPackage);
        if (topLevelPackage.isVisible())
            topLevelUserVisiblePackages.add(topLevelPackage);
        // register as a listener so that i can pass on element change
        // events
        topLevelPackage.addElementChangeListener(this);
        for (WorkflowProcess process : topLevelPackage.getProcesses()) process.addElementChangeListener(this);
    }
    Collections.sort(topLevelPackages);
    Collections.sort(topLevelUserVisiblePackages);
    File resultsFile = getFunctionTestResultsFile();
    if (resultsFile.exists()) {
        // update test case statuses
        List<TestCase> testCases = new ArrayList<>();
        for (WorkflowPackage pkg : topLevelPackages) {
            for (WorkflowAsset asset : pkg.getAssets()) {
                if (asset instanceof AutomatedTestCase)
                    testCases.add(((AutomatedTestCase) asset).getTestCase());
            }
        }
        if (!testCases.isEmpty()) {
            try {
                TestResultsParser parser = new TestResultsParser(resultsFile, testCases);
                if (resultsFile.getName().endsWith(".xml"))
                    parser.parseXml();
                else
                    parser.parseJson(getAssetDir());
            } catch (Exception ex) {
                PluginMessages.uiError(ex, "Parse Test Results", this);
            }
        }
    }
    timer.stopAndLog();
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) ArrayList(java.util.ArrayList) CoreException(org.eclipse.core.runtime.CoreException) JSONException(org.json.JSONException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException) MalformedURLException(java.net.MalformedURLException) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) TestCase(com.centurylink.mdw.designer.testing.TestCase) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) TestResultsParser(com.centurylink.mdw.designer.testing.TestResultsParser) CodeTimer(com.centurylink.mdw.plugin.CodeTimer) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 2 with TestCase

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

the class DesignerProxy method renameWorkflowAsset.

public void renameWorkflowAsset(final WorkflowAsset asset, final String newName) {
    if (asset.getPackage().workflowAssetNameExists(newName)) {
        Shell shell = MdwPlugin.getActiveWorkbenchWindow().getShell();
        MessageDialog.openError(shell, RENAME_ERROR, "Name already exists: '" + newName + "'");
        return;
    }
    String progressMsg = "Renaming to '" + newName + "'";
    String errorMsg = "Rename Workflow Asset";
    if (!asset.isLoaded())
        asset.load();
    designerRunner = new DesignerRunner(progressMsg, errorMsg, asset.getProject()) {

        public void perform() throws DataAccessException, RemoteException {
            asset.setVersion(1);
            dataAccess.getDesignerDataModel().removeRuleSet(asset.getRuleSetVO(), false);
            dataAccess.getDesignerDataAccess().renameRuleSet(asset.getRuleSetVO(), newName);
            if (asset instanceof AutomatedTestCase) {
                if (project.isFilePersist())
                    ((AutomatedTestCase) asset).setTestCase(new TestCase(asset.getPackage().getName(), asset.getRawFile()));
                else
                    ((AutomatedTestCase) asset).setTestCase(new TestCase(asset.getPackage().getName(), asset.getRuleSetVO()));
            }
            // roughly the same as db time
            asset.setModifyDate(new Date());
            // hopefully
            cacheRefresh.fireRefresh(RuleSetVO.JAVA.equals(asset.getLanguage()));
            dataAccess.getDesignerDataModel().addRuleSet(asset.getRuleSetVO());
        }
    };
    designerRunner.run();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) TestCase(com.centurylink.mdw.designer.testing.TestCase) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) RemoteException(java.rmi.RemoteException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) Date(java.util.Date)

Example 3 with TestCase

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

the class WorkflowAssetFactory method createAsset.

public static WorkflowAsset createAsset(RuleSetVO ruleSetVO, WorkflowPackage workflowPackage) {
    String language = ruleSetVO.getLanguage();
    if (language == null)
        return null;
    if (language.equals(RuleSetVO.GROOVY) || language.equals(RuleSetVO.JAVASCRIPT) || language.equals(RuleSetVO.JSX)) {
        return new Script(ruleSetVO, workflowPackage);
    } else if (language.equals(RuleSetVO.JAVA)) {
        return new JavaSource(ruleSetVO, workflowPackage);
    } else if (language.equals(RuleSetVO.DROOLS) || language.equals(RuleSetVO.GUIDED) || language.equals(RuleSetVO.EXCEL) || language.equals(RuleSetVO.EXCEL_2007)) {
        return new Rule(ruleSetVO, workflowPackage);
    } else if (language.equals(RuleSetVO.MS_WORD)) {
        return new WordDoc(ruleSetVO, workflowPackage);
    } else if (language.equals(RuleSetVO.CAMEL_ROUTE)) {
        return new CamelRoute(ruleSetVO, workflowPackage);
    } else if (language.equals(RuleSetVO.FACELET) || language.equals(RuleSetVO.JSP) || language.equals(RuleSetVO.HTML) || language.equals(RuleSetVO.FORM) || language.equals(RuleSetVO.PAGELET)) {
        return new Page(ruleSetVO, workflowPackage);
    } else if (language.equals(RuleSetVO.CSS) || language.equals(RuleSetVO.WEBSCRIPT) || language.equals(RuleSetVO.JAVASCRIPT) || language.equals(RuleSetVO.IMAGE_GIF) || language.equals(RuleSetVO.IMAGE_JPEG) || language.equals(RuleSetVO.IMAGE_PNG)) {
        return new WebResource(ruleSetVO, workflowPackage);
    } else if (language.equals(RuleSetVO.VELOCITY)) {
        try {
            return new Template(ruleSetVO, workflowPackage);
        } catch (NoClassDefFoundError er) {
            // don't prevent everything from loading
            PluginMessages.log(er);
        }
    } else if (language.equals(RuleSetVO.BIRT)) {
        return new Report(ruleSetVO, workflowPackage);
    } else if (language.equals(RuleSetVO.SPRING)) {
        return new SpringConfig(ruleSetVO, workflowPackage);
    } else if (language.equals(RuleSetVO.JAR)) {
        return new JarFile(ruleSetVO, workflowPackage);
    } else if (language.equals(RuleSetVO.TEXT)) {
        return new TextResource(ruleSetVO, workflowPackage);
    } else if (language.equals(RuleSetVO.XML) || language.equals(RuleSetVO.XSD) || language.equals(RuleSetVO.WSDL) || language.equals(RuleSetVO.XSL)) {
        return new XmlDoc(ruleSetVO, workflowPackage);
    } else if (language.startsWith("ATTRIBUTE_OVERFLOW")) {
        return null;
    } else if (language.equals(RuleSetVO.PROCESS)) {
        return null;
    } else if (language.equals(RuleSetVO.TEST) || language.equals(RuleSetVO.FEATURE) || language.equals(RuleSetVO.POSTMAN)) {
        if (// && !workflowPackage.isArchived()) We
        workflowPackage != null) // will pick latest version anyways -
        // Bigger problems if latest version is
        // the one from Archive folder
        {
            TestCase testCase;
            if (workflowPackage.getProject().isFilePersist())
                testCase = new TestCase(workflowPackage.getName(), ruleSetVO.getRawFile());
            else
                testCase = new TestCase(workflowPackage.getName(), ruleSetVO);
            return new AutomatedTestCase(ruleSetVO, workflowPackage, testCase);
        }
    } else if (language.equals(RuleSetVO.YAML)) {
        // TODO: should not assume all YAML assets are test results
        return new AutomatedTestResults(ruleSetVO, workflowPackage);
    } else if (language.equals(RuleSetVO.JSON)) {
        return new Json(ruleSetVO, workflowPackage);
    } else if (language.equals(RuleSetVO.KOTLIN)) {
        return new Kotlin(ruleSetVO, workflowPackage);
    }
    return new WorkflowAsset(ruleSetVO, workflowPackage);
}
Also used : TestCase(com.centurylink.mdw.designer.testing.TestCase)

Example 4 with TestCase

use of com.centurylink.mdw.designer.testing.TestCase 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)

Example 5 with TestCase

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

the class AutomatedTestSuite method readLegacyCases.

public boolean readLegacyCases() {
    testCases = new ArrayList<>();
    File oldTestCasesDir = getProject().getOldTestCasesDir();
    if (oldTestCasesDir.exists() && oldTestCasesDir.isDirectory()) {
        File[] caseDirs = oldTestCasesDir.listFiles(new FileFilter() {

            public boolean accept(File file) {
                if (!file.isDirectory())
                    return false;
                if (file.getName().equalsIgnoreCase("CVS") || file.getName().equals(".metadata"))
                    return false;
                for (String commandsFileName : TestCase.LEGACY_TEST_CASE_FILENAMES.values()) {
                    if (new File(file.toString() + "/" + commandsFileName).exists())
                        return true;
                }
                return false;
            }
        });
        List<TestCase> cases = new ArrayList<>();
        for (File caseDir : caseDirs) {
            AutomatedTestCase testCase = new AutomatedTestCase(getProject(), this, new TestCase("Legacy", caseDir));
            testCases.add(testCase);
            cases.add(testCase.getTestCase());
        }
        // update case statuses
        File suiteResults = getProject().getFunctionTestResultsFile();
        if (suiteResults != null && suiteResults.exists()) {
            try {
                TestResultsParser parser = new TestResultsParser(suiteResults, cases);
                if (suiteResults.getName().endsWith(".xml"))
                    parser.parseXml();
                else
                    parser.parseJson(getProject().getAssetDir());
            } catch (Exception ex) {
                PluginMessages.log(ex);
            }
        }
        return true;
    }
    return false;
}
Also used : TestCase(com.centurylink.mdw.designer.testing.TestCase) ArrayList(java.util.ArrayList) TestResultsParser(com.centurylink.mdw.designer.testing.TestResultsParser) FileFilter(java.io.FileFilter) File(java.io.File) IOException(java.io.IOException) JSONException(org.json.JSONException)

Aggregations

TestCase (com.centurylink.mdw.designer.testing.TestCase)5 File (java.io.File)3 ArrayList (java.util.ArrayList)3 TestResultsParser (com.centurylink.mdw.designer.testing.TestResultsParser)2 AutomatedTestCase (com.centurylink.mdw.plugin.designer.model.AutomatedTestCase)2 IOException (java.io.IOException)2 JSONException (org.json.JSONException)2 MdwSecurityException (com.centurylink.mdw.auth.MdwSecurityException)1 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)1 PackageDir (com.centurylink.mdw.dataaccess.file.PackageDir)1 TestCaseItem (com.centurylink.mdw.designer.testing.TestCaseItem)1 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)1 CodeTimer (com.centurylink.mdw.plugin.CodeTimer)1 WorkflowAsset (com.centurylink.mdw.plugin.designer.model.WorkflowAsset)1 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)1 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)1 AssetInfo (com.centurylink.mdw.test.AssetInfo)1 PackageTests (com.centurylink.mdw.test.PackageTests)1 TestCaseList (com.centurylink.mdw.test.TestCaseList)1 FileFilter (java.io.FileFilter)1