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);
}
}
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);
}
}
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;
}
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);
}
}
}
}
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;
}
Aggregations