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