Search in sources :

Example 1 with ResourceWrapper

use of com.centurylink.mdw.plugin.ResourceWrapper 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 2 with ResourceWrapper

use of com.centurylink.mdw.plugin.ResourceWrapper 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 ResourceWrapper

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

the class CucumberTest method getTests.

public static List<CucumberTest> getTests(IProject project) throws CoreException {
    List<CucumberTest> tests = new ArrayList<CucumberTest>();
    for (IResource res : project.members(false)) {
        ResourceWrapper resourceWrapper = new ResourceWrapper(res);
        IFolder folder = resourceWrapper.getFolder();
        if (folder != null)
            findTests(folder, tests);
    }
    return tests;
}
Also used : ResourceWrapper(com.centurylink.mdw.plugin.ResourceWrapper) ArrayList(java.util.ArrayList) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 4 with ResourceWrapper

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

the class CucumberTest method findTests.

public static void findTests(IFolder folder, List<CucumberTest> addTo) throws CoreException {
    ResourceWrapper folderWrapper = new ResourceWrapper(folder);
    WorkflowProject workflowProject = folderWrapper.getOwningWorkflowProject();
    // include only non-workflow package folders
    if ((workflowProject == null || workflowProject.getPackage(folder) == null) && !"testCases".equals(folder.getProjectRelativePath().toString())) {
        for (IResource res : folder.members(false)) {
            ResourceWrapper resourceWrapper = new ResourceWrapper(res);
            IFile file = resourceWrapper.getFile();
            if (file != null) {
                if (file.exists() && !file.isDerived() && "feature".equals(file.getFileExtension()))
                    addTo.add(new CucumberTest(file.getProject(), file));
            } else {
                IFolder subFolder = resourceWrapper.getFolder();
                if (subFolder != null && !subFolder.isDerived())
                    findTests(subFolder, addTo);
            }
        }
    }
}
Also used : ResourceWrapper(com.centurylink.mdw.plugin.ResourceWrapper) IFile(org.eclipse.core.resources.IFile) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with ResourceWrapper

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

the class AutoTestPropertyTester method test.

// TODO: support multiple selections
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    ResourceWrapper resourceWrapper = new ResourceWrapper((IAdaptable) receiver);
    try {
        WorkflowProject workflowProject = resourceWrapper.getOwningWorkflowProject();
        if ("canLaunchAutoTest".equals(property)) {
            // currently only for
            // debug
            IFile file = resourceWrapper.getFile();
            if (file != null && ("test".equals(file.getFileExtension()) || "postman".equals(file.getFileExtension())) && file.exists() && !file.isDerived() && workflowProject != null) {
                WorkflowPackage pkg = workflowProject.getPackage((IFolder) file.getParent());
                if (pkg != null)
                    return pkg.getAsset(file) != null;
            }
        } else if ("canLaunchAutomatedTests".equals(property)) {
            IFolder folder = resourceWrapper.getFolder();
            if (folder != null) {
                workflowProject = WorkflowProjectManager.getInstance().getWorkflowProject(folder.getProject());
                if (workflowProject != null && workflowProject.isInitialized()) {
                    WorkflowPackage pkg = workflowProject.getPackage(folder);
                    if (pkg != null)
                        return !pkg.getTestCases().isEmpty();
                }
            } else {
                IProject project = resourceWrapper.getProject();
                if (project != null) {
                    WorkflowProject proj = WorkflowProjectManager.getInstance().getWorkflowProject(project);
                    if (proj != null && proj.isInitialized()) {
                        return !proj.getTestCases().isEmpty();
                    }
                }
            }
        } else if ("canLaunchCucumberTest".equals(property)) {
            if (resourceWrapper.getOwningJavaProject() != null) {
                IFile file = resourceWrapper.getFile();
                if (file != null && "feature".equals(file.getFileExtension()) && file.exists() && !file.isDerived()) {
                    // exclude mdw automated gherkin tests
                    if (workflowProject != null && workflowProject.isInitialized()) {
                        ResourceWrapper parentWrapper = new ResourceWrapper((IAdaptable) file.getParent());
                        IFolder folder = parentWrapper.getFolder();
                        if (folder != null && workflowProject.getPackage(folder) != null)
                            return false;
                    }
                    return true;
                }
            }
        } else if ("canLaunchCucumberTests".equals(property) && resourceWrapper.getOwningJavaProject() != null) {
            IFolder folder = resourceWrapper.getFolder();
            if (folder != null) {
                if (workflowProject != null && workflowProject.isInitialized() && workflowProject.getPackage(folder) != null)
                    return false;
                List<CucumberTest> tests = new ArrayList<>();
                CucumberTest.findTests(folder, tests);
                return !tests.isEmpty();
            } else {
                return false;
            }
        }
    } catch (CoreException ex) {
        PluginMessages.log(ex);
    }
    return false;
}
Also used : ResourceWrapper(com.centurylink.mdw.plugin.ResourceWrapper) WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) ArrayList(java.util.ArrayList) List(java.util.List) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

ResourceWrapper (com.centurylink.mdw.plugin.ResourceWrapper)5 IFolder (org.eclipse.core.resources.IFolder)5 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)4 ArrayList (java.util.ArrayList)4 IFile (org.eclipse.core.resources.IFile)4 IProject (org.eclipse.core.resources.IProject)3 CoreException (org.eclipse.core.runtime.CoreException)3 WorkflowElement (com.centurylink.mdw.plugin.designer.model.WorkflowElement)2 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)2 IResource (org.eclipse.core.resources.IResource)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 AutomatedTestCase (com.centurylink.mdw.plugin.designer.model.AutomatedTestCase)1 CucumberTest (com.centurylink.mdw.plugin.designer.model.CucumberTest)1 List (java.util.List)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1