Search in sources :

Example 1 with CucumberTest

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

the class CucumberLaunchShortcut method performLaunch.

private void performLaunch(List<CucumberTest> tests, IFolder folder) throws CoreException {
    IProject project = tests.get(0).getProject();
    String launchName;
    if (folder == null)
        launchName = project.getName();
    else
        launchName = folder.getName();
    List<String> testCases = new ArrayList<>();
    for (CucumberTest test : tests) {
        String testPath = test.getPath();
        if (folder != null)
            testPath = testPath.substring(folder.getProjectRelativePath().toString().length() + 1);
        testCases.add(testPath);
    }
    ILaunchConfigurationWorkingCopy workingCopy = createLaunchConfiguration(project, folder, launchName, testCases);
    ILaunchConfiguration config = null;
    ILaunchConfigurationType configType = workingCopy.getType();
    ILaunchConfiguration[] configs = getLaunchManager().getLaunchConfigurations(configType);
    for (ILaunchConfiguration launchConfig : configs) {
        String projectAttr = launchConfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, "");
        String folderMatch = (folder == null) ? "" : folder.getProjectRelativePath().toString();
        String folderAttr = launchConfig.getAttribute(CucumberLaunchConfiguration.FOLDER, "");
        if (!project.getName().equals(projectAttr) || !folderMatch.equals(folderAttr))
            continue;
        config = launchConfig;
    }
    if (config == null) {
        // no existing found - create a new one
        config = workingCopy.doSave();
    } else {
        workingCopy = config.getWorkingCopy();
        workingCopy.setAttribute(CucumberLaunchConfiguration.FEATURES, testCases);
        config = workingCopy.doSave();
    }
    IStructuredSelection selection = new StructuredSelection(config);
    DebugUITools.openLaunchConfigurationDialogOnGroup(getShell(), selection, GROUP_ID);
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CucumberTest(com.centurylink.mdw.plugin.designer.model.CucumberTest) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject)

Example 2 with CucumberTest

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

the class CucumberLaunchShortcut method launch.

public void launch(ISelection sel, String mode) {
    StructuredSelection selection = (StructuredSelection) sel;
    Object firstElement = selection.getFirstElement();
    ResourceWrapper resourceWrapper = new ResourceWrapper(firstElement);
    try {
        List<CucumberTest> tests = new ArrayList<>();
        IFile file = resourceWrapper.getFile();
        if (file != null) {
            // launch gherkin feature test(s)
            for (Object obj : selection.toArray()) {
                ResourceWrapper fileWrapper = new ResourceWrapper(obj);
                tests.add(new CucumberTest(fileWrapper.getOwningProject(), fileWrapper.getFile()));
            }
            performLaunch(tests, new ResourceWrapper(file.getParent()).getFolder());
        } else {
            // package folder
            IFolder folder = resourceWrapper.getFolder();
            if (folder != null) {
                CucumberTest.findTests(folder, tests);
                performLaunch(tests, folder);
            } else {
                IProject proj = resourceWrapper.getProject();
                tests.addAll(CucumberTest.getTests(proj));
                performLaunch(tests, null);
            }
        }
    } catch (Exception ex) {
        WorkflowProject proj = firstElement instanceof WorkflowElement ? ((WorkflowElement) firstElement).getProject() : null;
        PluginMessages.uiError(ex, "Test Exec", proj);
    }
}
Also used : ResourceWrapper(com.centurylink.mdw.plugin.ResourceWrapper) CucumberTest(com.centurylink.mdw.plugin.designer.model.CucumberTest) 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) WorkflowElement(com.centurylink.mdw.plugin.designer.model.WorkflowElement) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with CucumberTest

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

the class CucumberLaunchTab method getAllTestCases.

/**
 * @return all project test cases to be displayed (or empty array if none)
 */
@Override
protected String[] getAllTestCases() {
    List<String> displayedCases = new ArrayList<>();
    try {
        if (project != null) {
            List<CucumberTest> tests;
            if (folder == null)
                tests = CucumberTest.getTests(project);
            else
                tests = CucumberTest.getTests(folder);
            for (CucumberTest test : tests) {
                String testPath = test.getPath();
                if (folder != null)
                    testPath = testPath.substring(folder.getProjectRelativePath().toString().length() + 1);
                displayedCases.add(testPath);
            }
        }
    } catch (CoreException ex) {
        PluginMessages.log(ex);
    }
    return displayedCases.toArray(new String[0]);
}
Also used : CucumberTest(com.centurylink.mdw.plugin.designer.model.CucumberTest) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList)

Aggregations

CucumberTest (com.centurylink.mdw.plugin.designer.model.CucumberTest)3 ArrayList (java.util.ArrayList)3 IProject (org.eclipse.core.resources.IProject)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 ResourceWrapper (com.centurylink.mdw.plugin.ResourceWrapper)1 WorkflowElement (com.centurylink.mdw.plugin.designer.model.WorkflowElement)1 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)1 ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)1 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)1