use of com.centurylink.mdw.plugin.designer.model.AutomatedTestCase in project mdw-designer by CenturyLinkCloud.
the class AutomatedTestView method handleSelectionChanged.
public void handleSelectionChanged(IStructuredSelection selection) {
String output = "";
if (selection.size() == 1 && selection.getFirstElement() instanceof WorkflowElement) {
selectedItem = (WorkflowElement) selection.getFirstElement();
if (selectedItem instanceof AutomatedTestCase) {
AutomatedTestCase testCase = (AutomatedTestCase) selectedItem;
output = readFile(testCase.getOutputFile()).replaceAll("\r\n", "\n").replaceAll("\n", "\r\n");
if (testCase.isPostman() && testCase.getItemName() != null)
output = readFile(testCase.getItemOutputFile()).replaceAll("\r\n", "\n").replaceAll("\n", "\r\n");
} else if (selectedItem instanceof AutomatedTestResults) {
AutomatedTestResults expectedResults = (AutomatedTestResults) selectedItem;
output = "Results:\n-----------\n" + readFile(expectedResults.getActualResults());
} else if (selectedItem instanceof LegacyExpectedResults) {
LegacyExpectedResults expectedResult = (LegacyExpectedResults) selectedItem;
output = "Results:\n-----------\n" + readFile(expectedResult.getActualResultFile());
}
} else {
selectedItem = null;
}
outputText.setText(output);
}
use of com.centurylink.mdw.plugin.designer.model.AutomatedTestCase in project mdw-designer by CenturyLinkCloud.
the class ProcessExplorerContentProvider method getChildren.
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof WorkflowProject) {
final WorkflowProject workflowProject = (WorkflowProject) parentElement;
if (!workflowProject.isLoaded()) {
try {
IRunnableWithProgress loader = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
ProgressMonitor progressMonitor = new SwtProgressMonitor(monitor);
progressMonitor.start("Loading " + workflowProject.getLabel());
progressMonitor.progress(5);
try {
workflowProject.initialize(progressMonitor);
if (workflowProject.getDataAccess() != null) {
workflowProject.getTopLevelUserVisiblePackages(progressMonitor);
workflowProject.getArchivedUserVisiblePackagesFolder(progressMonitor);
progressMonitor.done();
}
} catch (Exception ex) {
throw new InvocationTargetException(ex);
}
}
};
ProgressMonitorDialog progMonDlg = new MdwProgressMonitorDialog(MdwPlugin.getShell());
progMonDlg.run(true, false, loader);
} catch (InvocationTargetException itx) {
if (itx.getCause() instanceof DataUnavailableException) {
PluginMessages.log(itx);
MessageDialog.openWarning(MdwPlugin.getShell(), LOAD_WF_PROJECT, itx.getCause().getMessage());
} else if (itx.getCause() instanceof DataAccessOfflineException) {
PluginMessages.log(itx);
MessageDialog.openError(MdwPlugin.getShell(), LOAD_WF_PROJECT, itx.getCause().getMessage());
return new WorkflowPackage[0];
} else {
PluginMessages.uiError(itx, LOAD_WF_PROJECT, workflowProject);
return new WorkflowPackage[0];
}
} catch (Exception ex) {
PluginMessages.uiError(ex, LOAD_WF_PROJECT, workflowProject);
return new WorkflowPackage[0];
}
}
if (workflowProject.getDataAccess() == null)
return new WorkflowPackage[0];
List<WorkflowPackage> topLevelPackages = workflowProject.getTopLevelUserVisiblePackages();
Folder archivedPackageFolder = workflowProject.getArchivedUserVisiblePackagesFolder();
int size = topLevelPackages.size();
boolean showArchived = isShowArchivedItems(workflowProject);
if (showArchived)
size++;
AutomatedTestSuite testSuite = workflowProject.getLegacyTestSuite();
if (testSuite != null && !testSuite.isEmpty())
size++;
Object[] objects = new Object[size];
for (int i = 0; i < topLevelPackages.size(); i++) objects[i] = topLevelPackages.get(i);
int cur = topLevelPackages.size();
if (showArchived) {
objects[cur] = archivedPackageFolder;
cur++;
}
if (testSuite != null && !testSuite.isEmpty())
objects[cur] = testSuite;
return objects;
} else if (parentElement instanceof WorkflowPackage) {
WorkflowPackage packageVersion = (WorkflowPackage) parentElement;
if (packageVersion.isArchived() && packageVersion.hasDescendantPackageVersions()) {
return packageVersion.getDescendantPackageVersions().toArray(new WorkflowPackage[0]);
} else {
List<WorkflowElement> elements = new ArrayList<>();
IPreferenceStore prefsStore = MdwPlugin.getDefault().getPreferenceStore();
if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_PROCESSES_IN_PEX))
elements.addAll(packageVersion.getProcesses());
if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_WORKFLOW_ASSETS_IN_PEX))
elements.addAll(packageVersion.getAssets());
if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_EVENT_HANDLERS_IN_PEX))
elements.addAll(packageVersion.getExternalEvents());
if (prefsStore.getBoolean(PreferenceConstants.PREFS_SHOW_ACTIVITY_IMPLEMENTORS_IN_PEX))
elements.addAll(packageVersion.getActivityImpls());
if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_TASK_TEMPLATES_IN_PEX))
elements.addAll(packageVersion.getTaskTemplates());
elements.addAll(packageVersion.getChildFolders());
if (isSortPackageContentsAtoZ()) {
Collections.sort(elements, new Comparator<WorkflowElement>() {
public int compare(WorkflowElement e1, WorkflowElement e2) {
return e1.getLabel().compareToIgnoreCase(e2.getLabel());
}
});
}
return elements.toArray(new Object[0]);
}
} else if (parentElement instanceof WorkflowProcess) {
WorkflowProcess processVersion = (WorkflowProcess) parentElement;
if (processVersion.hasDescendantProcessVersions()) {
return processVersion.getDescendantProcessVersions().toArray(new WorkflowProcess[0]);
} else {
return emptyARRAY;
}
} else if (parentElement instanceof Folder) {
Folder folder = (Folder) parentElement;
return folder.getChildren().toArray(new WorkflowElement[0]);
} else if (parentElement instanceof AutomatedTestSuite) {
AutomatedTestSuite testSuite = (AutomatedTestSuite) parentElement;
return testSuite.getTestCases().toArray(new AutomatedTestCase[0]);
} else if (parentElement instanceof AutomatedTestCase) {
AutomatedTestCase testCase = (AutomatedTestCase) parentElement;
if (!testCase.isLegacy())
return emptyARRAY;
List<LegacyExpectedResults> expectedResults = testCase.getLegacyExpectedResults();
List<File> files = testCase.getFiles();
Object[] objects = new Object[expectedResults.size() + files.size()];
for (int i = 0; i < expectedResults.size(); i++) objects[i] = expectedResults.get(i);
for (int i = expectedResults.size(); i < objects.length; i++) objects[i] = files.get(i - expectedResults.size());
return objects;
} else {
return emptyARRAY;
}
}
use of com.centurylink.mdw.plugin.designer.model.AutomatedTestCase in project mdw-designer by CenturyLinkCloud.
the class WorkflowProject method findLegacyTests.
public AutomatedTestSuite findLegacyTests() {
AutomatedTestSuite testSuite = new AutomatedTestSuite(this);
if (testSuite.readLegacyCases()) {
for (AutomatedTestCase testCase : testSuite.getTestCases()) {
testCase.addElementChangeListener(this);
for (LegacyExpectedResults expectedResult : testCase.getLegacyExpectedResults()) expectedResult.addElementChangeListener(this);
for (com.centurylink.mdw.plugin.designer.model.File file : testCase.getFiles()) file.addElementChangeListener(this);
}
}
testSuite.setLabel("Legacy Tests");
testSuite.setIcon("folder.gif");
return testSuite;
}
use of com.centurylink.mdw.plugin.designer.model.AutomatedTestCase in project mdw-designer by CenturyLinkCloud.
the class AutomatedTestLaunchConfiguration method launch.
public void launch(ILaunchConfiguration launchConfig, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
WorkflowProject workflowProject = WorkflowProjectManager.getInstance().getWorkflowProject(launchConfig.getAttribute(WORKFLOW_PROJECT, ""));
boolean isLoadTest = launchConfig.getAttribute(IS_LOAD_TEST, false);
String attrPrefix = isLoadTest ? AutomatedTestCase.LOAD_TEST : AutomatedTestCase.FUNCTION_TEST;
String resultsPath = launchConfig.getAttribute(attrPrefix + "_" + RESULTS_PATH, "");
if (resultsPath.isEmpty())
resultsPath = WorkflowProject.DEFAULT_TEST_RESULTS_PATH;
workflowProject.setTestResultsPath(attrPrefix, resultsPath);
int threadCount = launchConfig.getAttribute(attrPrefix + "_" + THREAD_COUNT, 5);
int runCount = launchConfig.getAttribute(attrPrefix + "_" + RUN_COUNT, 100);
int threadInterval = launchConfig.getAttribute(attrPrefix + "_" + THREAD_INTERVAL, 2);
int runInterval = launchConfig.getAttribute(attrPrefix + "_" + RUN_INTERVAL, 2);
boolean verbose = launchConfig.getAttribute(attrPrefix + "_" + VERBOSE, true);
boolean stubbing = launchConfig.getAttribute(attrPrefix + "_" + STUBBING, false);
boolean singleServer = launchConfig.getAttribute(attrPrefix + "_" + SINGLE_SERVER, true);
boolean createReplace = launchConfig.getAttribute(attrPrefix + "_" + CREATE_REPLACE_RESULTS, false);
boolean postmanTestsExists = false;
HashMap<String, Boolean> testCaseOrder = null;
testSuite = new AutomatedTestSuite(workflowProject);
testSuite.setLoadTest(isLoadTest);
testSuite.setThreadCount(threadCount);
testSuite.setRunCount(runCount);
if (isLoadTest)
testSuite.setThreadInterval(runInterval);
else
testSuite.setThreadInterval(threadInterval);
testSuite.setVerbose(verbose);
testSuite.setStubbing(stubbing);
testSuite.setSingleServer(singleServer);
testSuite.setCreateReplaceResults(createReplace);
List<AutomatedTestCase> testCases = new ArrayList<>();
List<String> testCasesStr = launchConfig.getAttribute(attrPrefix + "_" + TEST_CASES, new ArrayList<String>());
for (String testCaseStr : testCasesStr) {
AutomatedTestCase autoTestCase;
if (testCaseStr.startsWith("Legacy/"))
autoTestCase = workflowProject.getLegacyTestSuite().getTestCase(testCaseStr);
else if (testCaseStr.indexOf("postman") > -1) {
String[] pathArray = testCaseStr.split("/");
String method = pathArray[2];
AutomatedTestCase cloneTestCase = (AutomatedTestCase) workflowProject.getAsset(pathArray[0] + "/" + pathArray[1]);
autoTestCase = new AutomatedTestCase(cloneTestCase);
autoTestCase.setId(cloneTestCase.getId());
try {
StringBuilder itemName = new StringBuilder(pathArray[3]);
for (int i = 4; i < pathArray.length; i++) itemName = itemName.append("/" + pathArray[i]);
autoTestCase.setItemName(itemName.toString());
autoTestCase.setMethod(method);
autoTestCase.getTestCase().resetItems();
autoTestCase.getTestCase().addItem(cloneTestCase.getItem(itemName.toString(), method));
postmanTestsExists = true;
} catch (Exception e) {
PluginMessages.log(e);
}
} else
autoTestCase = (AutomatedTestCase) workflowProject.getAsset(testCaseStr);
autoTestCase.setTestSuite(testSuite);
if (!autoTestCase.getResultsDir().exists())
autoTestCase.getResultsDir().mkdirs();
testCases.add(autoTestCase);
}
testSuite.setTestCases(testCases);
if (postmanTestsExists) {
testCaseOrder = new HashMap<>();
List<AutomatedTestCase> cases = new ArrayList<>();
for (AutomatedTestCase testCase : testSuite.getTestCases()) {
if (!testCase.isPostman())
cases.add(testCase);
else {
if (testCaseOrder.get(testCase.getName()) == null) {
List<AutomatedTestCase> postmanCases = testSuite.getPostmanTestCasesByName(testCase.getName());
testCaseOrder.put(testCase.getName(), true);
AutomatedTestCase postmanCase = testSuite.getPostmanTestCaseByMethod(postmanCases, "GET");
if (postmanCase != null)
cases.add(postmanCase);
postmanCase = testSuite.getPostmanTestCaseByMethod(postmanCases, "DELETE");
if (postmanCase != null)
cases.add(postmanCase);
postmanCase = testSuite.getPostmanTestCaseByMethod(postmanCases, "POST");
if (postmanCase != null)
cases.add(postmanCase);
postmanCase = testSuite.getPostmanTestCaseByMethod(postmanCases, "PUT");
if (postmanCase != null)
cases.add(postmanCase);
}
}
}
testSuite.setTestCases(cases);
}
if (isLoadTest) {
Map<String, String> testCaseCounts = launchConfig.getAttribute(attrPrefix + "_" + TESTCASE_COUNTS_MAP, new HashMap<String, String>());
for (Map.Entry<String, String> entry : testCaseCounts.entrySet()) {
int count = Integer.parseInt(entry.getValue());
testSuite.getTestCase(entry.getKey()).setRunCount(count);
}
}
if (!testSuite.getResultsDir().exists())
testSuite.getResultsDir().mkdirs();
testSuite.setDebug(ILaunchManager.DEBUG_MODE.equals(mode));
showResultsView();
}
use of com.centurylink.mdw.plugin.designer.model.AutomatedTestCase in project mdw-designer by CenturyLinkCloud.
the class AutomatedTestContentProvider method getChildren.
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof AutomatedTestSuite) {
AutomatedTestSuite testSuite = (AutomatedTestSuite) parentElement;
List<WorkflowPackage> packages = new ArrayList<WorkflowPackage>();
List<WorkflowElement> legacyTests = new ArrayList<WorkflowElement>();
for (AutomatedTestCase testCase : testSuite.getTestCases()) {
if (testCase.isLegacy()) {
legacyTests.add(testCase);
} else {
WorkflowPackage pkg = testCase.getPackage();
if (!packages.contains(pkg))
packages.add(pkg);
}
}
Folder folder = null;
if (!legacyTests.isEmpty()) {
folder = new Folder("Legacy Tests");
folder.setChildren(legacyTests);
for (WorkflowElement legacyTest : legacyTests) legacyTest.setArchivedFolder(folder);
}
Object[] children = new Object[packages.size() + (folder == null ? 0 : 1)];
for (int i = 0; i < packages.size(); i++) children[i] = packages.get(i);
if (folder != null)
children[children.length - 1] = folder;
return children;
} else if (parentElement instanceof WorkflowPackage) {
WorkflowPackage pkg = (WorkflowPackage) parentElement;
@SuppressWarnings("unchecked") AutomatedTestSuite suite = ((List<AutomatedTestSuite>) treeViewer.getInput()).get(0);
List<AutomatedTestCase> selectedCases = new ArrayList<AutomatedTestCase>();
List<String> testCasesStringList;
try {
testCasesStringList = pkg.getTestCaseStringList();
for (AutomatedTestCase testCase : suite.getTestCases()) {
String path = testCase.getPath();
if (testCase.isPostman())
path = testCase.getItemPath();
if (testCasesStringList.contains(path))
selectedCases.add(testCase);
}
} catch (JSONException e) {
e.printStackTrace();
}
return selectedCases.toArray();
} else if (parentElement instanceof Folder) {
return ((Folder) parentElement).getChildren().toArray();
} else if (parentElement instanceof AutomatedTestCase) {
AutomatedTestCase testCase = (AutomatedTestCase) parentElement;
if (testCase.isLegacy()) {
return testCase.getLegacyExpectedResults().toArray(new LegacyExpectedResults[0]);
} else {
AutomatedTestResults results = testCase.getExpectedResults();
return results == null ? EMPTY_ARRAY : new Object[] { results };
}
} else {
return EMPTY_ARRAY;
}
}
Aggregations