use of com.centurylink.mdw.plugin.designer.model.AutomatedTestCase in project mdw-designer by CenturyLinkCloud.
the class AutomatedTestView method updateTreeAndProgressBar.
private synchronized void updateTreeAndProgressBar(boolean done) {
int completedCases = 0;
int erroredCases = 0;
int failedCases = 0;
int casePercents = 0;
boolean loadTest = testSuite.isLoadTest();
for (AutomatedTestCase testCase : testSuite.getTestCases()) {
String oldStatus = testCaseStatuses.get(testCase);
boolean statusChanged = done || oldStatus == null || !oldStatus.equals(testCase.getStatus());
if (statusChanged) {
testSuite.getProject().fireTestCaseStatusChange(testCase, testCase.getStatus());
testCaseStatuses.put(testCase, testCase.getStatus());
}
int casePercent = 0;
if (testCase.isFinished()) {
if (statusChanged && !done && testSuite.isCreateReplaceResults() && // only applies for VCS assets
testCase.isSuccess()) {
if (testCase.isLegacy()) {
// trigger
testCase.setTestCase(testCase.getTestCase());
// results
if (testCase.getLegacyExpectedResults() != null) {
for (LegacyExpectedResults legacyResults : testCase.getLegacyExpectedResults()) {
legacyResults.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, legacyResults);
testSuite.getProject().fireElementChangeEvent(ChangeType.ELEMENT_CREATE, legacyResults);
}
}
} else {
try {
// create asset from newly-created results and
// refresh process explorer (only for VCS assets)
String resAssetName = testCase.getTestCase().getCaseName() + RuleSetVO.getFileExtension(RuleSetVO.YAML);
if (testCase.isPostman() && testCase.getItemName() != null)
resAssetName = testCase.getItemName().replace('/', '_') + RuleSetVO.getFileExtension(RuleSetVO.YAML);
File resFile = new File(testSuite.getProject().getProjectDir() + "/" + testCase.getPackage().getVcsAssetPath() + "/" + resAssetName);
if (// may not exist if test case
resFile.exists()) // does not launch any
// processes
{
byte[] bytes = PluginUtil.readFile(resFile);
WorkflowAsset existing = testSuite.getProject().getAsset(testCase.getPackage().getName() + "/" + resAssetName);
if (existing == null) {
// create (waiting a second or two for the
// results file to have been created)
RuleSetVO newRuleSet = new RuleSetVO();
newRuleSet.setName(resAssetName);
newRuleSet.setLanguage(RuleSetVO.YAML);
newRuleSet.setRaw(true);
newRuleSet.setRawFile(resFile);
newRuleSet.setRawContent(bytes);
WorkflowAsset newAsset = WorkflowAssetFactory.createAsset(newRuleSet, testCase.getPackage());
newAsset.setPackage(testCase.getPackage());
newAsset.setId(new Long(-1));
newAsset.setCreateUser(testSuite.getProject().getUser().getUsername());
newAsset.setLockingUser(testSuite.getProject().getUser().getUsername());
designerProxy.saveWorkflowAsset(newAsset, true);
testSuite.getProject().getDataAccess().getDesignerDataModel().addRuleSet(newAsset.getRuleSetVO());
newAsset.getPackage().addAsset(newAsset);
designerProxy.savePackage(newAsset.getPackage());
newAsset.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, newAsset);
} else {
// increment version
existing.getRuleSetVO().setRawContent(bytes);
existing.setVersion(existing.getNextMinorVersion());
existing.setRevisionComment("Auto-created");
testSuite.getProject().getDesignerProxy().saveWorkflowAsset(existing, true);
existing.fireElementChangeEvent(ChangeType.VERSION_CHANGE, existing.getVersion());
}
}
} catch (Exception ex) {
PluginMessages.uiError(ex, "Create/Replace Test Results", testSuite.getProject());
}
}
}
updateExpectedResults(testCase);
if (loadTest) {
completedCases = testCase.getTestCase().getNumberPrepared();
casePercents = testCase.getTestCase().getNumberPrepared() * 100;
} else {
completedCases++;
casePercent = 100;
}
} else {
casePercent = testCase.getTotalSteps() == 0 ? 0 : (testCase.getStepsCompleted() * 100) / testCase.getTotalSteps();
}
if (!loadTest)
casePercents += casePercent;
if (testCase.isErrored()) {
if (loadTest)
erroredCases = testCase.getTestCase().getNumberPrepared();
else
erroredCases++;
} else if (testCase.isFailed()) {
if (loadTest)
failedCases = testCase.getTestCase().getNumberPrepared();
else
failedCases++;
}
if (statusChanged)
try {
testSuite.writeTestCaseResults(testCase);
} catch (Exception ex) {
PluginMessages.uiError(ex, "Create/Replace Test Results", testSuite.getProject());
}
}
if (done) {
testSuite.setRunning(false);
updateCounterPanel(testSuite.getTestCases().size(), erroredCases, failedCases, true);
updateProgressBar(100, testSuite.hasErrors() || testSuite.hasFailures(), testSuite.isStopped());
} else {
int count = testSuite.getTestCases().size();
if (loadTest)
count = testSuite.getRunCount();
int totalPercents = count * 100;
if (counterData.completed < completedCases) {
updateCounterPanel(completedCases, erroredCases, failedCases, false);
float percentComplete = totalPercents == 0 ? 0 : (casePercents * 100) / totalPercents;
updateProgressBar(Math.round(percentComplete * 90 / 100) + 10, erroredCases + failedCases > 0, testSuite.isStopped());
}
}
refreshOutputFromSelection();
}
use of com.centurylink.mdw.plugin.designer.model.AutomatedTestCase in project mdw-designer by CenturyLinkCloud.
the class AutomatedTestView method runLoadTests.
public void runLoadTests() {
int totalRunCount = 0;
for (AutomatedTestCase testCase : testSuite.getTestCases()) totalRunCount += testCase.getRunCount();
testSuite.setRunCount(totalRunCount);
try {
prepForRun();
counterData = new CounterData(testSuite.getRunCount());
updateCounterPanel(0, 0, 0, true);
monitorObj = new LoadTestLogMonitor(testSuite.getProject().getDesignerProxy().getDesignerDataAccess(), masterRequestRunMap, null);
String msg = designerProxy.checkForServerDbMismatch();
if (msg != null) {
MessageDialog.openError(getSite().getShell(), "Server DB Mismatch", msg);
handleStop();
return;
}
if (testSuite.isStubbing()) {
StubServer.Stubber stubber = new TestStubber();
if (StubServer.isRunning())
StubServer.stop();
int port = testSuite.getProject().getServerSettings().getStubServerPort();
StubServer.start(testSuite.getProject().getDesignerProxy().getRestfulServer(), port, stubber, testSuite.getProject().isOldNamespaces());
}
} catch (Exception ex) {
PluginMessages.uiError(ex, "Load 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());
long startTime = System.currentTimeMillis();
int totalPrepared = 0;
int totalCompleted = 0;
try {
startTime = System.currentTimeMillis();
monitorObj.start(true);
for (AutomatedTestCase testCase : testSuite.getTestCases()) {
File resultDir = testCase.getResultsDir();
File executeLog = new File(resultDir.getPath() + "/execute.log");
int ct = testCase.getRunCount();
for (int k = 0; k < ct; k++) {
deleteFile(executeLog);
if (!executeLog.getParentFile().exists() && !executeLog.getParentFile().mkdirs())
throw new IOException("Unable to create test run directory: " + executeLog.getParentFile());
PrintStream log = new PrintStream(executeLog);
TestCaseRun testCaseRun = designerProxy.prepareTestCase(testCase, k, resultDir, false, testSuite.isVerbose(), log, monitorObj, testSuite.isSingleServer(), testSuite.isStubbing(), false);
totalPrepared++;
testCase.getTestCase().setNumberPrepared(totalPrepared);
masterRequestRunMap.put(testCaseRun.getMasterRequestId(), testCaseRun);
threadPool.execute(testCaseRun);
updateTreeAndProgressBar(false);
try {
Thread.sleep(testSuite.getThreadInterval() * 1000);
} catch (InterruptedException ex) {
}
}
}
updateProgressBar(10, false, false);
// server's commonThreadPool
while (!threadPool.isTerminated()) {
// update the tree and the progress bar
updateTreeAndProgressBar(false);
if (testSuite.isFinished())
threadPool.shutdown();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
testSuite.setRunning(false);
actionGroup.enableStopAction(false);
actionGroup.enableRerunAction(true);
File resultsFile = testSuite.getProject().getLoadTestResultsFile();
actionGroup.enableFormatLoadTestResults(resultsFile != null && resultsFile.exists());
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (monitorObj != null)
monitorObj.shutdown();
locked = false;
}
try {
generateLoadTestReport(totalPrepared, totalCompleted, monitorObj, startTime, testSuite.getResultsDir().toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
});
background.start();
}
use of com.centurylink.mdw.plugin.designer.model.AutomatedTestCase in project mdw-designer by CenturyLinkCloud.
the class AutomatedTestView method refreshOutputFromSelection.
private void refreshOutputFromSelection() {
display.asyncExec(new Runnable() {
public void run() {
String output = "";
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());
}
if (!outputText.getText().equals(output)) {
outputText.setText(output);
outputText.setSelection(outputText.getText().length());
}
}
});
}
use of com.centurylink.mdw.plugin.designer.model.AutomatedTestCase in project mdw-designer by CenturyLinkCloud.
the class AutomatedTestView method prepForRun.
public void prepForRun() {
locked = true;
display = getSite().getShell().getDisplay();
actionGroup.enableRerunAction(false);
actionGroup.enableStopAction(true);
masterRequestRunMap = new ConcurrentHashMap<>();
for (AutomatedTestCase testCase : testSuite.getTestCases()) {
testCase.setStatus(TestCase.STATUS_NOT_RUN);
testSuite.getProject().fireTestCaseStatusChange(testCase, testCase.getStatus());
}
testSuite.setRunning(true);
List<AutomatedTestSuite> rootElements = new ArrayList<>();
rootElements.add(testSuite);
treeViewer.setInput(rootElements);
treeViewer.expandToLevel(3);
BusyIndicator.showWhile(display, new Runnable() {
public void run() {
// can take a long time if the project has not been loaded
designerProxy = testSuite.getProject().getDesignerProxy();
}
});
}
use of com.centurylink.mdw.plugin.designer.model.AutomatedTestCase in project mdw-designer by CenturyLinkCloud.
the class ProcessExplorerContentProvider method handleElementChange.
private void handleElementChange(ElementChangeEvent ece) {
if (ece.getChangeType().equals(ChangeType.ELEMENT_CREATE)) {
Object parent = getParent(ece.getElement());
if (parent == null) {
treeViewer.refresh(true);
ece.getElement().addElementChangeListener(this);
} else {
if (parent instanceof WorkflowPackage) {
try {
((WorkflowPackage) parent).getFolder().refreshLocal(IResource.DEPTH_ONE, null);
} catch (Exception ex) {
PluginMessages.log(ex);
}
}
treeViewer.refresh(parent, true);
}
treeViewer.expandToLevel(ece.getElement(), 0);
treeViewer.setSelection(ece.getElement());
} else if (ece.getChangeType().equals(ChangeType.ELEMENT_DELETE)) {
Object parent = getParent(ece.getElement());
if (parent != null) {
if (ece.getElement() instanceof ActivityImpl)
// impl can be associated with
treeViewer.refresh();
else
// multiple packages
treeViewer.refresh(parent, true);
} else {
// must be a workflowProject
ece.getElement().removeElementChangeListener(this);
treeViewer.refresh();
}
} else if (ece.getChangeType().equals(ChangeType.RENAME)) {
treeViewer.refresh(ece.getElement(), true);
treeViewer.getControl().forceFocus();
} else if (ece.getChangeType().equals(ChangeType.VERSION_CHANGE)) {
treeViewer.refresh(ece.getElement(), true);
if (ece.getElement() instanceof WorkflowPackage)
treeViewer.refresh(ece.getElement().getProject().getArchivedUserVisiblePackagesFolder(), true);
} else if (ece.getChangeType().equals(ChangeType.LABEL_CHANGE)) {
treeViewer.update(ece.getElement(), null);
} else if (ece.getChangeType().equals(ChangeType.SETTINGS_CHANGE)) {
// only applies for workflow projects
if (ece.getElement() instanceof WorkflowProject) {
WorkflowProject workflowProject = (WorkflowProject) ece.getElement();
if (ece.getNewValue() instanceof JdbcDataSource) {
treeViewer.collapseToLevel(workflowProject, TreeViewer.ALL_LEVELS);
treeViewer.refresh(workflowProject, true);
} else if (ece.getNewValue() == null) {
// general refresh
treeViewer.refresh(workflowProject, true);
}
} else {
treeViewer.refresh(ece.getElement(), true);
}
} else if (ece.getChangeType().equals(ChangeType.STATUS_CHANGE)) {
treeViewer.update(ece.getElement(), null);
if (ece.getElement() instanceof AutomatedTestCase) {
AutomatedTestCase testCase = (AutomatedTestCase) ece.getElement();
Object testResults;
if (testCase.isLegacy())
testResults = testCase.getLegacyExpectedResults();
else
testResults = testCase.getExpectedResults();
if (testResults != null)
treeViewer.refresh(testResults, true);
}
}
}
Aggregations