Search in sources :

Example 1 with LegacyExpectedResults

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

the class WorkflowElementActionHandler method open.

public boolean open(WorkflowElement element) {
    if (element instanceof WorkflowProcess) {
        WorkflowProcess processVersion = (WorkflowProcess) element;
        try {
            ProcessEditor processEditor = (ProcessEditor) getPage().openEditor(processVersion, "mdw.editors.process");
            showPropertiesView();
            processEditor.setFocus();
        } catch (PartInitException ex) {
            PluginMessages.uiError(getShell(), ex, "Open Process", processVersion.getProject());
        }
    } else if (element instanceof AutomatedTestCase && ((AutomatedTestCase) element).isLegacy()) {
        // open the old way instead of as workflow asset
        AutomatedTestCase testCase = (AutomatedTestCase) element;
        IFile file = testCase.getCommandsFile();
        IWorkbenchPage activePage = MdwPlugin.getActivePage();
        try {
            IDE.openEditor(activePage, file, true);
        } catch (PartInitException ex) {
            PluginMessages.uiError(ex, "Open Test Case", testCase.getProject());
        }
    } else if (element instanceof WorkflowAsset) {
        WorkflowAsset asset = (WorkflowAsset) element;
        asset.openFile(new NullProgressMonitor());
    } else if (element instanceof LegacyExpectedResults) {
        LegacyExpectedResults expectedResult = (LegacyExpectedResults) element;
        IFile file = expectedResult.getExpectedResult();
        IWorkbenchPage activePage = MdwPlugin.getActivePage();
        try {
            IDE.openEditor(activePage, file, true);
        } catch (PartInitException ex) {
            PluginMessages.uiError(ex, "Open Expected Result", expectedResult.getProject());
        }
    } else if (element instanceof com.centurylink.mdw.plugin.designer.model.File) {
        com.centurylink.mdw.plugin.designer.model.File file = (com.centurylink.mdw.plugin.designer.model.File) element;
        IFile workspaceFile = file.getWorkspaceFile();
        IWorkbenchPage activePage = MdwPlugin.getActivePage();
        try {
            IDE.openEditor(activePage, workspaceFile, true);
        } catch (PartInitException ex) {
            PluginMessages.uiError(ex, "Open File", file.getProject());
        }
    } else if (element instanceof ExternalEvent) {
        ExternalEvent event = (ExternalEvent) element;
        if (event.getProject().checkRequiredVersion(6, 0)) {
            IFile file = event.getProject().getAssetFolder().getFolder(event.getPackage().getName().replace('.', '/')).getFile(event.getName() + EVT_HANDLER_FILE_EXTENSION);
            IWorkbenchPage activePage = MdwPlugin.getActivePage();
            try {
                IDE.openEditor(activePage, file, true);
            } catch (PartInitException ex) {
                PluginMessages.uiError(ex, "Open File", event.getProject());
            }
        }
    } else {
        return false;
    }
    return true;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) LegacyExpectedResults(com.centurylink.mdw.plugin.designer.model.LegacyExpectedResults) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ExternalEvent(com.centurylink.mdw.plugin.designer.model.ExternalEvent) PartInitException(org.eclipse.ui.PartInitException) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) IFile(org.eclipse.core.resources.IFile) File(java.io.File) JarFile(com.centurylink.mdw.plugin.designer.model.JarFile) ProcessEditor(com.centurylink.mdw.plugin.designer.editors.ProcessEditor)

Example 2 with LegacyExpectedResults

use of com.centurylink.mdw.plugin.designer.model.LegacyExpectedResults 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 3 with LegacyExpectedResults

use of com.centurylink.mdw.plugin.designer.model.LegacyExpectedResults 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 4 with LegacyExpectedResults

use of com.centurylink.mdw.plugin.designer.model.LegacyExpectedResults 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)

Example 5 with LegacyExpectedResults

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

the class AutomatedTestView method updateTreeAndProgressBar.

private synchronized void updateTreeAndProgressBar(boolean done) {
    int completedCases = 0;
    int erroredCases = 0;
    int failedCases = 0;
    int casePercents = 0;
    boolean loadTest = testSuite.isLoadTest();
    for (AutomatedTestCase testCase : testSuite.getTestCases()) {
        String oldStatus = testCaseStatuses.get(testCase);
        boolean statusChanged = done || oldStatus == null || !oldStatus.equals(testCase.getStatus());
        if (statusChanged) {
            testSuite.getProject().fireTestCaseStatusChange(testCase, testCase.getStatus());
            testCaseStatuses.put(testCase, testCase.getStatus());
        }
        int casePercent = 0;
        if (testCase.isFinished()) {
            if (statusChanged && !done && testSuite.isCreateReplaceResults() && // only applies for VCS assets
            testCase.isSuccess()) {
                if (testCase.isLegacy()) {
                    // trigger
                    testCase.setTestCase(testCase.getTestCase());
                    // results
                    if (testCase.getLegacyExpectedResults() != null) {
                        for (LegacyExpectedResults legacyResults : testCase.getLegacyExpectedResults()) {
                            legacyResults.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, legacyResults);
                            testSuite.getProject().fireElementChangeEvent(ChangeType.ELEMENT_CREATE, legacyResults);
                        }
                    }
                } else {
                    try {
                        // create asset from newly-created results and
                        // refresh process explorer (only for VCS assets)
                        String resAssetName = testCase.getTestCase().getCaseName() + RuleSetVO.getFileExtension(RuleSetVO.YAML);
                        if (testCase.isPostman() && testCase.getItemName() != null)
                            resAssetName = testCase.getItemName().replace('/', '_') + RuleSetVO.getFileExtension(RuleSetVO.YAML);
                        File resFile = new File(testSuite.getProject().getProjectDir() + "/" + testCase.getPackage().getVcsAssetPath() + "/" + resAssetName);
                        if (// may not exist if test case
                        resFile.exists()) // does not launch any
                        // processes
                        {
                            byte[] bytes = PluginUtil.readFile(resFile);
                            WorkflowAsset existing = testSuite.getProject().getAsset(testCase.getPackage().getName() + "/" + resAssetName);
                            if (existing == null) {
                                // create (waiting a second or two for the
                                // results file to have been created)
                                RuleSetVO newRuleSet = new RuleSetVO();
                                newRuleSet.setName(resAssetName);
                                newRuleSet.setLanguage(RuleSetVO.YAML);
                                newRuleSet.setRaw(true);
                                newRuleSet.setRawFile(resFile);
                                newRuleSet.setRawContent(bytes);
                                WorkflowAsset newAsset = WorkflowAssetFactory.createAsset(newRuleSet, testCase.getPackage());
                                newAsset.setPackage(testCase.getPackage());
                                newAsset.setId(new Long(-1));
                                newAsset.setCreateUser(testSuite.getProject().getUser().getUsername());
                                newAsset.setLockingUser(testSuite.getProject().getUser().getUsername());
                                designerProxy.saveWorkflowAsset(newAsset, true);
                                testSuite.getProject().getDataAccess().getDesignerDataModel().addRuleSet(newAsset.getRuleSetVO());
                                newAsset.getPackage().addAsset(newAsset);
                                designerProxy.savePackage(newAsset.getPackage());
                                newAsset.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, newAsset);
                            } else {
                                // increment version
                                existing.getRuleSetVO().setRawContent(bytes);
                                existing.setVersion(existing.getNextMinorVersion());
                                existing.setRevisionComment("Auto-created");
                                testSuite.getProject().getDesignerProxy().saveWorkflowAsset(existing, true);
                                existing.fireElementChangeEvent(ChangeType.VERSION_CHANGE, existing.getVersion());
                            }
                        }
                    } catch (Exception ex) {
                        PluginMessages.uiError(ex, "Create/Replace Test Results", testSuite.getProject());
                    }
                }
            }
            updateExpectedResults(testCase);
            if (loadTest) {
                completedCases = testCase.getTestCase().getNumberPrepared();
                casePercents = testCase.getTestCase().getNumberPrepared() * 100;
            } else {
                completedCases++;
                casePercent = 100;
            }
        } else {
            casePercent = testCase.getTotalSteps() == 0 ? 0 : (testCase.getStepsCompleted() * 100) / testCase.getTotalSteps();
        }
        if (!loadTest)
            casePercents += casePercent;
        if (testCase.isErrored()) {
            if (loadTest)
                erroredCases = testCase.getTestCase().getNumberPrepared();
            else
                erroredCases++;
        } else if (testCase.isFailed()) {
            if (loadTest)
                failedCases = testCase.getTestCase().getNumberPrepared();
            else
                failedCases++;
        }
        if (statusChanged)
            try {
                testSuite.writeTestCaseResults(testCase);
            } catch (Exception ex) {
                PluginMessages.uiError(ex, "Create/Replace Test Results", testSuite.getProject());
            }
    }
    if (done) {
        testSuite.setRunning(false);
        updateCounterPanel(testSuite.getTestCases().size(), erroredCases, failedCases, true);
        updateProgressBar(100, testSuite.hasErrors() || testSuite.hasFailures(), testSuite.isStopped());
    } else {
        int count = testSuite.getTestCases().size();
        if (loadTest)
            count = testSuite.getRunCount();
        int totalPercents = count * 100;
        if (counterData.completed < completedCases) {
            updateCounterPanel(completedCases, erroredCases, failedCases, false);
            float percentComplete = totalPercents == 0 ? 0 : (casePercents * 100) / totalPercents;
            updateProgressBar(Math.round(percentComplete * 90 / 100) + 10, erroredCases + failedCases > 0, testSuite.isStopped());
        }
    }
    refreshOutputFromSelection();
}
Also used : LegacyExpectedResults(com.centurylink.mdw.plugin.designer.model.LegacyExpectedResults) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) File(java.io.File) JSONException(org.json.JSONException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO)

Aggregations

LegacyExpectedResults (com.centurylink.mdw.plugin.designer.model.LegacyExpectedResults)12 AutomatedTestCase (com.centurylink.mdw.plugin.designer.model.AutomatedTestCase)8 WorkflowElement (com.centurylink.mdw.plugin.designer.model.WorkflowElement)8 AutomatedTestResults (com.centurylink.mdw.plugin.designer.model.AutomatedTestResults)7 IFile (org.eclipse.core.resources.IFile)7 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)5 JarFile (com.centurylink.mdw.plugin.designer.model.JarFile)4 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)4 File (java.io.File)4 IOException (java.io.IOException)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 Action (org.eclipse.jface.action.Action)4 IAction (org.eclipse.jface.action.IAction)4 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)4 PartInitException (org.eclipse.ui.PartInitException)4 TestFile (com.centurylink.mdw.designer.testing.TestFile)3 AutomatedTestSuite (com.centurylink.mdw.plugin.designer.model.AutomatedTestSuite)3 WorkflowAsset (com.centurylink.mdw.plugin.designer.model.WorkflowAsset)3 ConnectException (java.net.ConnectException)3 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)2