Search in sources :

Example 11 with AutomatedTestCase

use of com.centurylink.mdw.plugin.designer.model.AutomatedTestCase in project mdw-designer by CenturyLinkCloud.

the class AutomatedTestView method handleSelectionChanged.

public void handleSelectionChanged(IStructuredSelection selection) {
    String output = "";
    if (selection.size() == 1 && selection.getFirstElement() instanceof WorkflowElement) {
        selectedItem = (WorkflowElement) selection.getFirstElement();
        if (selectedItem instanceof AutomatedTestCase) {
            AutomatedTestCase testCase = (AutomatedTestCase) selectedItem;
            output = readFile(testCase.getOutputFile()).replaceAll("\r\n", "\n").replaceAll("\n", "\r\n");
            if (testCase.isPostman() && testCase.getItemName() != null)
                output = readFile(testCase.getItemOutputFile()).replaceAll("\r\n", "\n").replaceAll("\n", "\r\n");
        } else if (selectedItem instanceof AutomatedTestResults) {
            AutomatedTestResults expectedResults = (AutomatedTestResults) selectedItem;
            output = "Results:\n-----------\n" + readFile(expectedResults.getActualResults());
        } else if (selectedItem instanceof LegacyExpectedResults) {
            LegacyExpectedResults expectedResult = (LegacyExpectedResults) selectedItem;
            output = "Results:\n-----------\n" + readFile(expectedResult.getActualResultFile());
        }
    } else {
        selectedItem = null;
    }
    outputText.setText(output);
}
Also used : LegacyExpectedResults(com.centurylink.mdw.plugin.designer.model.LegacyExpectedResults) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) WorkflowElement(com.centurylink.mdw.plugin.designer.model.WorkflowElement) AutomatedTestResults(com.centurylink.mdw.plugin.designer.model.AutomatedTestResults)

Example 12 with AutomatedTestCase

use of com.centurylink.mdw.plugin.designer.model.AutomatedTestCase in project mdw-designer by CenturyLinkCloud.

the class ProcessExplorerContentProvider method getChildren.

public Object[] getChildren(Object parentElement) {
    if (parentElement instanceof WorkflowProject) {
        final WorkflowProject workflowProject = (WorkflowProject) parentElement;
        if (!workflowProject.isLoaded()) {
            try {
                IRunnableWithProgress loader = new IRunnableWithProgress() {

                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        ProgressMonitor progressMonitor = new SwtProgressMonitor(monitor);
                        progressMonitor.start("Loading " + workflowProject.getLabel());
                        progressMonitor.progress(5);
                        try {
                            workflowProject.initialize(progressMonitor);
                            if (workflowProject.getDataAccess() != null) {
                                workflowProject.getTopLevelUserVisiblePackages(progressMonitor);
                                workflowProject.getArchivedUserVisiblePackagesFolder(progressMonitor);
                                progressMonitor.done();
                            }
                        } catch (Exception ex) {
                            throw new InvocationTargetException(ex);
                        }
                    }
                };
                ProgressMonitorDialog progMonDlg = new MdwProgressMonitorDialog(MdwPlugin.getShell());
                progMonDlg.run(true, false, loader);
            } catch (InvocationTargetException itx) {
                if (itx.getCause() instanceof DataUnavailableException) {
                    PluginMessages.log(itx);
                    MessageDialog.openWarning(MdwPlugin.getShell(), LOAD_WF_PROJECT, itx.getCause().getMessage());
                } else if (itx.getCause() instanceof DataAccessOfflineException) {
                    PluginMessages.log(itx);
                    MessageDialog.openError(MdwPlugin.getShell(), LOAD_WF_PROJECT, itx.getCause().getMessage());
                    return new WorkflowPackage[0];
                } else {
                    PluginMessages.uiError(itx, LOAD_WF_PROJECT, workflowProject);
                    return new WorkflowPackage[0];
                }
            } catch (Exception ex) {
                PluginMessages.uiError(ex, LOAD_WF_PROJECT, workflowProject);
                return new WorkflowPackage[0];
            }
        }
        if (workflowProject.getDataAccess() == null)
            return new WorkflowPackage[0];
        List<WorkflowPackage> topLevelPackages = workflowProject.getTopLevelUserVisiblePackages();
        Folder archivedPackageFolder = workflowProject.getArchivedUserVisiblePackagesFolder();
        int size = topLevelPackages.size();
        boolean showArchived = isShowArchivedItems(workflowProject);
        if (showArchived)
            size++;
        AutomatedTestSuite testSuite = workflowProject.getLegacyTestSuite();
        if (testSuite != null && !testSuite.isEmpty())
            size++;
        Object[] objects = new Object[size];
        for (int i = 0; i < topLevelPackages.size(); i++) objects[i] = topLevelPackages.get(i);
        int cur = topLevelPackages.size();
        if (showArchived) {
            objects[cur] = archivedPackageFolder;
            cur++;
        }
        if (testSuite != null && !testSuite.isEmpty())
            objects[cur] = testSuite;
        return objects;
    } else if (parentElement instanceof WorkflowPackage) {
        WorkflowPackage packageVersion = (WorkflowPackage) parentElement;
        if (packageVersion.isArchived() && packageVersion.hasDescendantPackageVersions()) {
            return packageVersion.getDescendantPackageVersions().toArray(new WorkflowPackage[0]);
        } else {
            List<WorkflowElement> elements = new ArrayList<>();
            IPreferenceStore prefsStore = MdwPlugin.getDefault().getPreferenceStore();
            if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_PROCESSES_IN_PEX))
                elements.addAll(packageVersion.getProcesses());
            if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_WORKFLOW_ASSETS_IN_PEX))
                elements.addAll(packageVersion.getAssets());
            if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_EVENT_HANDLERS_IN_PEX))
                elements.addAll(packageVersion.getExternalEvents());
            if (prefsStore.getBoolean(PreferenceConstants.PREFS_SHOW_ACTIVITY_IMPLEMENTORS_IN_PEX))
                elements.addAll(packageVersion.getActivityImpls());
            if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_TASK_TEMPLATES_IN_PEX))
                elements.addAll(packageVersion.getTaskTemplates());
            elements.addAll(packageVersion.getChildFolders());
            if (isSortPackageContentsAtoZ()) {
                Collections.sort(elements, new Comparator<WorkflowElement>() {

                    public int compare(WorkflowElement e1, WorkflowElement e2) {
                        return e1.getLabel().compareToIgnoreCase(e2.getLabel());
                    }
                });
            }
            return elements.toArray(new Object[0]);
        }
    } else if (parentElement instanceof WorkflowProcess) {
        WorkflowProcess processVersion = (WorkflowProcess) parentElement;
        if (processVersion.hasDescendantProcessVersions()) {
            return processVersion.getDescendantProcessVersions().toArray(new WorkflowProcess[0]);
        } else {
            return emptyARRAY;
        }
    } else if (parentElement instanceof Folder) {
        Folder folder = (Folder) parentElement;
        return folder.getChildren().toArray(new WorkflowElement[0]);
    } else if (parentElement instanceof AutomatedTestSuite) {
        AutomatedTestSuite testSuite = (AutomatedTestSuite) parentElement;
        return testSuite.getTestCases().toArray(new AutomatedTestCase[0]);
    } else if (parentElement instanceof AutomatedTestCase) {
        AutomatedTestCase testCase = (AutomatedTestCase) parentElement;
        if (!testCase.isLegacy())
            return emptyARRAY;
        List<LegacyExpectedResults> expectedResults = testCase.getLegacyExpectedResults();
        List<File> files = testCase.getFiles();
        Object[] objects = new Object[expectedResults.size() + files.size()];
        for (int i = 0; i < expectedResults.size(); i++) objects[i] = expectedResults.get(i);
        for (int i = expectedResults.size(); i < objects.length; i++) objects[i] = files.get(i - expectedResults.size());
        return objects;
    } else {
        return emptyARRAY;
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) SwtProgressMonitor(com.centurylink.mdw.plugin.designer.SwtProgressMonitor) MdwProgressMonitorDialog(com.centurylink.mdw.plugin.designer.dialogs.MdwProgressMonitorDialog) Folder(com.centurylink.mdw.plugin.designer.model.Folder) AutomatedTestSuite(com.centurylink.mdw.plugin.designer.model.AutomatedTestSuite) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Comparator(java.util.Comparator) ArrayList(java.util.ArrayList) List(java.util.List) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) MdwProgressMonitorDialog(com.centurylink.mdw.plugin.designer.dialogs.MdwProgressMonitorDialog) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DataUnavailableException(com.centurylink.mdw.designer.DataUnavailableException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProgressMonitor(com.centurylink.mdw.common.utilities.timer.ProgressMonitor) SwtProgressMonitor(com.centurylink.mdw.plugin.designer.SwtProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DataUnavailableException(com.centurylink.mdw.designer.DataUnavailableException) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) WorkflowElement(com.centurylink.mdw.plugin.designer.model.WorkflowElement)

Example 13 with AutomatedTestCase

use of com.centurylink.mdw.plugin.designer.model.AutomatedTestCase in project mdw-designer by CenturyLinkCloud.

the class WorkflowProject method findLegacyTests.

public AutomatedTestSuite findLegacyTests() {
    AutomatedTestSuite testSuite = new AutomatedTestSuite(this);
    if (testSuite.readLegacyCases()) {
        for (AutomatedTestCase testCase : testSuite.getTestCases()) {
            testCase.addElementChangeListener(this);
            for (LegacyExpectedResults expectedResult : testCase.getLegacyExpectedResults()) expectedResult.addElementChangeListener(this);
            for (com.centurylink.mdw.plugin.designer.model.File file : testCase.getFiles()) file.addElementChangeListener(this);
        }
    }
    testSuite.setLabel("Legacy Tests");
    testSuite.setIcon("folder.gif");
    return testSuite;
}
Also used : LegacyExpectedResults(com.centurylink.mdw.plugin.designer.model.LegacyExpectedResults) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) AutomatedTestSuite(com.centurylink.mdw.plugin.designer.model.AutomatedTestSuite)

Example 14 with AutomatedTestCase

use of com.centurylink.mdw.plugin.designer.model.AutomatedTestCase in project mdw-designer by CenturyLinkCloud.

the class AutomatedTestLaunchConfiguration method launch.

public void launch(ILaunchConfiguration launchConfig, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    WorkflowProject workflowProject = WorkflowProjectManager.getInstance().getWorkflowProject(launchConfig.getAttribute(WORKFLOW_PROJECT, ""));
    boolean isLoadTest = launchConfig.getAttribute(IS_LOAD_TEST, false);
    String attrPrefix = isLoadTest ? AutomatedTestCase.LOAD_TEST : AutomatedTestCase.FUNCTION_TEST;
    String resultsPath = launchConfig.getAttribute(attrPrefix + "_" + RESULTS_PATH, "");
    if (resultsPath.isEmpty())
        resultsPath = WorkflowProject.DEFAULT_TEST_RESULTS_PATH;
    workflowProject.setTestResultsPath(attrPrefix, resultsPath);
    int threadCount = launchConfig.getAttribute(attrPrefix + "_" + THREAD_COUNT, 5);
    int runCount = launchConfig.getAttribute(attrPrefix + "_" + RUN_COUNT, 100);
    int threadInterval = launchConfig.getAttribute(attrPrefix + "_" + THREAD_INTERVAL, 2);
    int runInterval = launchConfig.getAttribute(attrPrefix + "_" + RUN_INTERVAL, 2);
    boolean verbose = launchConfig.getAttribute(attrPrefix + "_" + VERBOSE, true);
    boolean stubbing = launchConfig.getAttribute(attrPrefix + "_" + STUBBING, false);
    boolean singleServer = launchConfig.getAttribute(attrPrefix + "_" + SINGLE_SERVER, true);
    boolean createReplace = launchConfig.getAttribute(attrPrefix + "_" + CREATE_REPLACE_RESULTS, false);
    boolean postmanTestsExists = false;
    HashMap<String, Boolean> testCaseOrder = null;
    testSuite = new AutomatedTestSuite(workflowProject);
    testSuite.setLoadTest(isLoadTest);
    testSuite.setThreadCount(threadCount);
    testSuite.setRunCount(runCount);
    if (isLoadTest)
        testSuite.setThreadInterval(runInterval);
    else
        testSuite.setThreadInterval(threadInterval);
    testSuite.setVerbose(verbose);
    testSuite.setStubbing(stubbing);
    testSuite.setSingleServer(singleServer);
    testSuite.setCreateReplaceResults(createReplace);
    List<AutomatedTestCase> testCases = new ArrayList<>();
    List<String> testCasesStr = launchConfig.getAttribute(attrPrefix + "_" + TEST_CASES, new ArrayList<String>());
    for (String testCaseStr : testCasesStr) {
        AutomatedTestCase autoTestCase;
        if (testCaseStr.startsWith("Legacy/"))
            autoTestCase = workflowProject.getLegacyTestSuite().getTestCase(testCaseStr);
        else if (testCaseStr.indexOf("postman") > -1) {
            String[] pathArray = testCaseStr.split("/");
            String method = pathArray[2];
            AutomatedTestCase cloneTestCase = (AutomatedTestCase) workflowProject.getAsset(pathArray[0] + "/" + pathArray[1]);
            autoTestCase = new AutomatedTestCase(cloneTestCase);
            autoTestCase.setId(cloneTestCase.getId());
            try {
                StringBuilder itemName = new StringBuilder(pathArray[3]);
                for (int i = 4; i < pathArray.length; i++) itemName = itemName.append("/" + pathArray[i]);
                autoTestCase.setItemName(itemName.toString());
                autoTestCase.setMethod(method);
                autoTestCase.getTestCase().resetItems();
                autoTestCase.getTestCase().addItem(cloneTestCase.getItem(itemName.toString(), method));
                postmanTestsExists = true;
            } catch (Exception e) {
                PluginMessages.log(e);
            }
        } else
            autoTestCase = (AutomatedTestCase) workflowProject.getAsset(testCaseStr);
        autoTestCase.setTestSuite(testSuite);
        if (!autoTestCase.getResultsDir().exists())
            autoTestCase.getResultsDir().mkdirs();
        testCases.add(autoTestCase);
    }
    testSuite.setTestCases(testCases);
    if (postmanTestsExists) {
        testCaseOrder = new HashMap<>();
        List<AutomatedTestCase> cases = new ArrayList<>();
        for (AutomatedTestCase testCase : testSuite.getTestCases()) {
            if (!testCase.isPostman())
                cases.add(testCase);
            else {
                if (testCaseOrder.get(testCase.getName()) == null) {
                    List<AutomatedTestCase> postmanCases = testSuite.getPostmanTestCasesByName(testCase.getName());
                    testCaseOrder.put(testCase.getName(), true);
                    AutomatedTestCase postmanCase = testSuite.getPostmanTestCaseByMethod(postmanCases, "GET");
                    if (postmanCase != null)
                        cases.add(postmanCase);
                    postmanCase = testSuite.getPostmanTestCaseByMethod(postmanCases, "DELETE");
                    if (postmanCase != null)
                        cases.add(postmanCase);
                    postmanCase = testSuite.getPostmanTestCaseByMethod(postmanCases, "POST");
                    if (postmanCase != null)
                        cases.add(postmanCase);
                    postmanCase = testSuite.getPostmanTestCaseByMethod(postmanCases, "PUT");
                    if (postmanCase != null)
                        cases.add(postmanCase);
                }
            }
        }
        testSuite.setTestCases(cases);
    }
    if (isLoadTest) {
        Map<String, String> testCaseCounts = launchConfig.getAttribute(attrPrefix + "_" + TESTCASE_COUNTS_MAP, new HashMap<String, String>());
        for (Map.Entry<String, String> entry : testCaseCounts.entrySet()) {
            int count = Integer.parseInt(entry.getValue());
            testSuite.getTestCase(entry.getKey()).setRunCount(count);
        }
    }
    if (!testSuite.getResultsDir().exists())
        testSuite.getResultsDir().mkdirs();
    testSuite.setDebug(ILaunchManager.DEBUG_MODE.equals(mode));
    showResultsView();
}
Also used : ArrayList(java.util.ArrayList) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) AutomatedTestSuite(com.centurylink.mdw.plugin.designer.model.AutomatedTestSuite) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with AutomatedTestCase

use of com.centurylink.mdw.plugin.designer.model.AutomatedTestCase in project mdw-designer by CenturyLinkCloud.

the class AutomatedTestContentProvider method getChildren.

public Object[] getChildren(Object parentElement) {
    if (parentElement instanceof AutomatedTestSuite) {
        AutomatedTestSuite testSuite = (AutomatedTestSuite) parentElement;
        List<WorkflowPackage> packages = new ArrayList<WorkflowPackage>();
        List<WorkflowElement> legacyTests = new ArrayList<WorkflowElement>();
        for (AutomatedTestCase testCase : testSuite.getTestCases()) {
            if (testCase.isLegacy()) {
                legacyTests.add(testCase);
            } else {
                WorkflowPackage pkg = testCase.getPackage();
                if (!packages.contains(pkg))
                    packages.add(pkg);
            }
        }
        Folder folder = null;
        if (!legacyTests.isEmpty()) {
            folder = new Folder("Legacy Tests");
            folder.setChildren(legacyTests);
            for (WorkflowElement legacyTest : legacyTests) legacyTest.setArchivedFolder(folder);
        }
        Object[] children = new Object[packages.size() + (folder == null ? 0 : 1)];
        for (int i = 0; i < packages.size(); i++) children[i] = packages.get(i);
        if (folder != null)
            children[children.length - 1] = folder;
        return children;
    } else if (parentElement instanceof WorkflowPackage) {
        WorkflowPackage pkg = (WorkflowPackage) parentElement;
        @SuppressWarnings("unchecked") AutomatedTestSuite suite = ((List<AutomatedTestSuite>) treeViewer.getInput()).get(0);
        List<AutomatedTestCase> selectedCases = new ArrayList<AutomatedTestCase>();
        List<String> testCasesStringList;
        try {
            testCasesStringList = pkg.getTestCaseStringList();
            for (AutomatedTestCase testCase : suite.getTestCases()) {
                String path = testCase.getPath();
                if (testCase.isPostman())
                    path = testCase.getItemPath();
                if (testCasesStringList.contains(path))
                    selectedCases.add(testCase);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return selectedCases.toArray();
    } else if (parentElement instanceof Folder) {
        return ((Folder) parentElement).getChildren().toArray();
    } else if (parentElement instanceof AutomatedTestCase) {
        AutomatedTestCase testCase = (AutomatedTestCase) parentElement;
        if (testCase.isLegacy()) {
            return testCase.getLegacyExpectedResults().toArray(new LegacyExpectedResults[0]);
        } else {
            AutomatedTestResults results = testCase.getExpectedResults();
            return results == null ? EMPTY_ARRAY : new Object[] { results };
        }
    } else {
        return EMPTY_ARRAY;
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) Folder(com.centurylink.mdw.plugin.designer.model.Folder) AutomatedTestSuite(com.centurylink.mdw.plugin.designer.model.AutomatedTestSuite) AutomatedTestResults(com.centurylink.mdw.plugin.designer.model.AutomatedTestResults) LegacyExpectedResults(com.centurylink.mdw.plugin.designer.model.LegacyExpectedResults) ArrayList(java.util.ArrayList) List(java.util.List) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) WorkflowElement(com.centurylink.mdw.plugin.designer.model.WorkflowElement)

Aggregations

AutomatedTestCase (com.centurylink.mdw.plugin.designer.model.AutomatedTestCase)27 AutomatedTestSuite (com.centurylink.mdw.plugin.designer.model.AutomatedTestSuite)14 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)11 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)11 WorkflowElement (com.centurylink.mdw.plugin.designer.model.WorkflowElement)10 ArrayList (java.util.ArrayList)10 LegacyExpectedResults (com.centurylink.mdw.plugin.designer.model.LegacyExpectedResults)8 JSONException (org.json.JSONException)7 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)6 File (java.io.File)6 IFile (org.eclipse.core.resources.IFile)6 PartInitException (org.eclipse.ui.PartInitException)6 ExternalEvent (com.centurylink.mdw.plugin.designer.model.ExternalEvent)4 JarFile (com.centurylink.mdw.plugin.designer.model.JarFile)4 IOException (java.io.IOException)4 CoreException (org.eclipse.core.runtime.CoreException)4 AutomatedTestResults (com.centurylink.mdw.plugin.designer.model.AutomatedTestResults)3 WorkflowAsset (com.centurylink.mdw.plugin.designer.model.WorkflowAsset)3 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)3 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)2