Search in sources :

Example 6 with AutomatedTestCase

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

the class AutomatedTestLaunchShortcut method launch.

public void launch(ISelection sel, String mode) {
    StructuredSelection selection = (StructuredSelection) sel;
    Object firstElement = selection.getFirstElement();
    WorkflowProject project = null;
    try {
        if (firstElement instanceof WorkflowElement) {
            WorkflowElement element = (WorkflowElement) firstElement;
            project = element.getProject();
            boolean prevEnablement = disableBuildBeforeLaunch();
            if (selection.size() > 1 || element instanceof AutomatedTestCase) {
                List<AutomatedTestCase> testCases = new ArrayList<>();
                for (Object obj : selection.toArray()) testCases.add((AutomatedTestCase) obj);
                performLaunch(testCases, mode);
            } else {
                performLaunch(element, mode);
            }
            setBuildBeforeLaunch(prevEnablement);
        } else {
            ResourceWrapper resourceWrapper = new ResourceWrapper(firstElement);
            IFile firstFile = resourceWrapper.getFile();
            if (firstFile != null) {
                project = WorkflowProjectManager.getInstance().getWorkflowProject(firstFile.getProject());
                // test case file(s)
                List<AutomatedTestCase> testCases = new ArrayList<>();
                Object[] objArr = selection.toArray();
                if (objArr.length == 1) {
                    WorkflowPackage pkg = project.getPackage((IFolder) firstFile.getParent());
                    testCases.add((AutomatedTestCase) pkg.getAsset(firstFile));
                } else {
                    for (Object obj : objArr) {
                        IFile file = (IFile) obj;
                        WorkflowPackage pkg = project.getPackage((IFolder) file.getParent());
                        testCases.add((AutomatedTestCase) pkg.getAsset(file));
                    }
                }
                performLaunch(testCases, mode);
            } else {
                IFolder folder = resourceWrapper.getFolder();
                if (folder != null) {
                    project = WorkflowProjectManager.getInstance().getWorkflowProject(folder.getProject());
                    performLaunch(project.getPackage(folder), mode);
                } else {
                    IProject proj = resourceWrapper.getProject();
                    project = WorkflowProjectManager.getInstance().getWorkflowProject(proj);
                    performLaunch(project, mode);
                }
            }
        }
    } catch (Exception ex) {
        PluginMessages.uiError(ex, "Test Exec", project);
    }
}
Also used : ResourceWrapper(com.centurylink.mdw.plugin.ResourceWrapper) WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) WorkflowElement(com.centurylink.mdw.plugin.designer.model.WorkflowElement) IFolder(org.eclipse.core.resources.IFolder)

Example 7 with AutomatedTestCase

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

the class AutomatedTestLaunchShortcut method performLaunch.

/**
 * All test cases must be in the same package or legacy suite.
 */
private void performLaunch(List<AutomatedTestCase> cases, String mode) throws CoreException, JSONException {
    AutomatedTestCase firstCase = cases.get(0);
    WorkflowProject workflowProject = firstCase.getProject();
    WorkflowPackage workflowPackage = firstCase.getPackage();
    boolean isLegacyLaunch = firstCase.isLegacy();
    String testName;
    if (isLegacyLaunch)
        testName = workflowProject.getName() + LEGACY;
    else
        testName = workflowPackage.getName();
    List<String> testCases = new ArrayList<>();
    for (AutomatedTestCase testCase : cases) {
        if (testCase.getItems() != null) {
            testCases.addAll(workflowPackage.getTestCaseItems(testCase));
        } else if (testCase.isPostman())
            testCases.add(testCase.getItemPath());
        else
            testCases.add(testCase.getPath());
    }
    ILaunchConfigurationWorkingCopy workingCopy = createLaunchConfiguration(workflowProject, workflowPackage, isLegacyLaunch, testName, testCases, ILaunchManager.DEBUG_MODE.equals(mode));
    ILaunchConfiguration config = findExistingLaunchConfiguration(workingCopy);
    if (config == null) {
        // no existing found - create a new one
        config = workingCopy.doSave();
    } else {
        workingCopy = config.getWorkingCopy();
        String prefix;
        if (workingCopy.getAttribute(AutomatedTestLaunchConfiguration.IS_LOAD_TEST, false))
            prefix = AutomatedTestCase.LOAD_TEST;
        else
            prefix = AutomatedTestCase.FUNCTION_TEST;
        workingCopy.setAttribute(prefix + "_" + AutomatedTestLaunchConfiguration.TEST_CASES, testCases);
        config = workingCopy.doSave();
    }
    IStructuredSelection selection = new StructuredSelection(config);
    if (ILaunchManager.DEBUG_MODE.equals(mode)) {
        DebugUITools.openLaunchConfigurationDialogOnGroup(getShell(), selection, DEBUG_GROUP_ID);
    } else {
        DebugUITools.openLaunchConfigurationDialogOnGroup(getShell(), selection, GROUP_ID);
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 8 with AutomatedTestCase

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

the class FunctionTestLaunchTab method validatePage.

@Override
protected void validatePage() {
    super.validatePage();
    if (getErrorMessage() == null) {
        List<String> selectedCases = Arrays.asList(getTestCases());
        int count = selectedCases.size();
        int gherkinCount = 0;
        // warn if mixed launch
        for (AutomatedTestCase autoTestCase : getProject().getTestCases()) {
            if (selectedCases.contains(autoTestCase.getPath()) && autoTestCase.isGherkin())
                gherkinCount++;
        }
        if (gherkinCount > 0 && count > gherkinCount) {
            setErrorMessage("Mixed Gherkin/non-Gherkin test selections not currently supported.");
        } else if (debug && count > 1) {
            setErrorMessage("Currently only one test case can be debugged.  Select Run mode for multiple cases.");
        } else if (!selectedCases.isEmpty() && createReplaceCheckBox.getSelection()) {
            setWarningMessage("Any existing test results assets will be overwritten.");
        } else {
            setErrorMessage(null);
            setWarningMessage(null);
        }
        updateLaunchConfigurationDialog();
    }
}
Also used : AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase)

Example 9 with AutomatedTestCase

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

the class AutomatedTestView method runTests.

public void runTests() {
    // TODO: currently mixed execution of Gherkin/Groovy scripts
    // fails to start LogMessageMonitor in Designer VM (otherwise will
    // conflict with Cucumber-JVM)
    boolean hasGherkin = false;
    for (AutomatedTestCase rtc : testSuite.getTestCases()) {
        if (rtc.isGherkin())
            hasGherkin = true;
    }
    try {
        prepForRun();
        counterData = new CounterData(testSuite.getTestCases().size());
        updateCounterPanel(0, 0, 0, true);
        monitor = null;
        if (!hasGherkin && !testSuite.isDebug())
            monitor = new LogMessageMonitor(testSuite.getProject().getDesignerProxy().getDesignerDataAccess(), testSuite.getProject().isOldNamespaces());
        String msg = designerProxy.checkForServerDbMismatch();
        if (msg != null) {
            MessageDialog.openError(getSite().getShell(), "Server DB Mismatch", msg);
            handleStop();
            return;
        }
        if (StubServer.isRunning())
            StubServer.stop();
        if (testSuite.isStubbing() && !hasGherkin && !testSuite.isDebug()) {
            StubServer.Stubber stubber = new TestStubber();
            int port = testSuite.getProject().getServerSettings().getStubServerPort();
            StubServer.start(testSuite.getProject().getDesignerProxy().getRestfulServer(), port, stubber, testSuite.getProject().isOldNamespaces());
        }
    } catch (Exception ex) {
        PluginMessages.uiError(ex, "Automated Test", testSuite.getProject());
        handleStop();
        return;
    }
    Thread background = new Thread(new Runnable() {

        public void run() {
            testCaseStatuses = new HashMap<>();
            updateProgressBar(5, false, false);
            threadPool = new ThreadPool(testSuite.getThreadCount());
            PrintStream printStream = null;
            updateProgressBar(10, false, false);
            if (monitor != null)
                monitor.start(true);
            for (AutomatedTestCase testCase : testSuite.getTestCases()) {
                if (!testSuite.isRunning())
                    continue;
                File resultDir = testCase.getResultsDir();
                try {
                    File executeLog = testCase.getOutputFile();
                    deleteFile(executeLog);
                    if (testCase.isPostman())
                        deleteFile(testCase.getItemOutputFile());
                    if (!executeLog.getParentFile().exists() && !executeLog.getParentFile().mkdirs())
                        throw new IOException("Unable to create test run directory: " + executeLog.getParentFile());
                    PrintStream log = new PrintStream(executeLog);
                    ImageDescriptor icon = MdwPlugin.getImageDescriptor("icons/auto_test.gif");
                    MessageConsole console = MessageConsole.findConsole("Tests", icon, display);
                    printStream = new PrintStream(console.newFileConsoleOutputStream(executeLog));
                    TestCaseRun testCaseRun = designerProxy.prepareTestCase(testCase, 0, resultDir, testSuite.isCreateReplaceResults(), testSuite.isVerbose(), log, monitor, testSuite.isSingleServer(), testSuite.isStubbing(), testSuite.isDebug());
                    masterRequestRunMap.put(testCaseRun.getMasterRequestId(), testCaseRun);
                    testCaseRun.setMasterRequestListener(AutomatedTestView.this);
                    threadPool.execute(testCaseRun);
                    updateTreeAndProgressBar(false);
                    try {
                        Thread.sleep(testSuite.getThreadInterval() * 1000);
                    } catch (InterruptedException ex) {
                    }
                } catch (Exception ex) {
                    PluginMessages.log(ex);
                    testCase.setErrored();
                    updateTreeAndProgressBar(true);
                    testSuite.setRunning(false);
                    if (printStream != null) {
                        ex.printStackTrace(printStream);
                        printStream.close();
                    }
                    handleStop();
                    return;
                }
            }
            while (!threadPool.isTerminated()) {
                // update the tree and the progress bar
                updateTreeAndProgressBar(false);
                if (testSuite.isFinished())
                    threadPool.shutdown();
                try {
                    Thread.sleep(2500);
                } catch (InterruptedException e) {
                }
            }
            updateTreeAndProgressBar(true);
            testSuite.setRunning(false);
            actionGroup.enableStopAction(false);
            actionGroup.enableRerunAction(true);
            File resultsFile = testSuite.getProject().getFunctionTestResultsFile();
            actionGroup.enableFormatFunctionTestResults(resultsFile != null && resultsFile.exists());
            locked = false;
            if (monitor != null && monitor.isBound())
                monitor.shutdown();
            if (printStream != null)
                printStream.close();
        }
    });
    background.start();
}
Also used : PrintStream(java.io.PrintStream) MessageConsole(com.centurylink.mdw.plugin.MessageConsole) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ThreadPool(com.centurylink.mdw.designer.testing.ThreadPool) Stubber(com.centurylink.mdw.designer.testing.StubServer.Stubber) IOException(java.io.IOException) JSONException(org.json.JSONException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) StubServer(com.centurylink.mdw.designer.testing.StubServer) LogMessageMonitor(com.centurylink.mdw.designer.testing.LogMessageMonitor) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) TestCaseRun(com.centurylink.mdw.designer.testing.TestCaseRun) File(java.io.File)

Example 10 with AutomatedTestCase

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

the class AutomatedTestView method handleRerunSelection.

public void handleRerunSelection() {
    if (selectedItem != null) {
        if (selectedItem instanceof AutomatedTestSuite) {
            handleRerun();
        } else if (selectedItem instanceof WorkflowPackage) {
            WorkflowPackage pkg = (WorkflowPackage) selectedItem;
            List<AutomatedTestCase> cases = new ArrayList<AutomatedTestCase>();
            List<String> testCasesStringList;
            try {
                testCasesStringList = pkg.getTestCaseStringList();
                for (AutomatedTestCase testCase : testSuite.getTestCases()) {
                    String path = testCase.getPath();
                    if (testCase.isPostman())
                        path = testCase.getItemPath();
                    if (testCasesStringList.contains(path))
                        cases.add(testCase);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            runTestCases(cases);
        } else if (selectedItem instanceof AutomatedTestCase) {
            AutomatedTestCase testCase = (AutomatedTestCase) selectedItem;
            runTestCase(testCase);
        }
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) JSONException(org.json.JSONException) List(java.util.List) ArrayList(java.util.ArrayList) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) AutomatedTestSuite(com.centurylink.mdw.plugin.designer.model.AutomatedTestSuite)

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