Search in sources :

Example 1 with TestElement

use of org.eclipse.n4js.tester.domain.TestElement in project n4js by eclipse.

the class TestResultsView method onSingleClick.

/**
 * Invoked when user double-clicks a result node in the UI.
 *
 * On invocation clears stack trace text are. If selection is a test case with stack trace, trace is shown in the
 * trace area.
 */
protected void onSingleClick() {
    stackTrace.setText("");
    final ISelection selection = testTreeViewer.getSelection();
    if (selection.isEmpty()) {
        return;
    }
    if (selection instanceof IStructuredSelection) {
        final Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof ResultNode) {
            final ResultNode resultNode = (ResultNode) element;
            final TestElement testElement = resultNode.getElement();
            if (testElement instanceof TestCase) {
                final TestCase testCase = (TestCase) testElement;
                final TestResult result = testCase.getResult();
                if (result != null) {
                    if (result.getTrace() != null && !result.getTrace().isEmpty()) {
                        final List<String> trace = newArrayList(result.getTrace());
                        final String firstLine = trace.get(0);
                        if ("Error".equals(firstLine) && !isNullOrEmpty(result.getMessage())) {
                            trace.set(0, result.getMessage());
                        }
                        final StringBuilder sb = new StringBuilder();
                        trace.forEach(line -> sb.append(line).append(lineSeparator()));
                        stackTrace.setText(sb.toString());
                        stackTrace.setSelection(0);
                    } else if ((SKIPPED_IGNORE.equals(result.getTestStatus()) || SKIPPED_FIXME.equals(result.getTestStatus())) && !isNullOrEmpty(result.getMessage())) {
                        stackTrace.setText(result.getMessage());
                        stackTrace.setSelection(0);
                    }
                }
            }
        }
    }
}
Also used : TestCase(org.eclipse.n4js.tester.domain.TestCase) ISelection(org.eclipse.jface.viewers.ISelection) TestResult(org.eclipse.n4js.tester.domain.TestResult) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TestElement(org.eclipse.n4js.tester.domain.TestElement)

Example 2 with TestElement

use of org.eclipse.n4js.tester.domain.TestElement in project n4js by eclipse.

the class TestResultsView method onDoubleClick.

/**
 * Invoked when user double-clicks a result node in the UI.
 */
protected void onDoubleClick() {
    final ISelection selection = testTreeViewer.getSelection();
    final ResultNode resultNode = (ResultNode) ((IStructuredSelection) selection).getFirstElement();
    if (resultNode == null) {
        return;
    }
    TestElement testElement = resultNode.getElement();
    if (testElement instanceof TestCase) {
        final URI testCaseURI = ((TestCase) testElement).getURI();
        if (testCaseURI == null) {
            return;
        }
        final IN4JSEclipseProject project = core.findProject(testCaseURI).orNull();
        if (null != project && project.exists()) {
            final URI moduleLocation = testCaseURI.trimFragment();
            final String[] projectRelativeSegments = moduleLocation.deresolve(project.getLocation()).segments();
            final String path = Joiner.on(SEPARATOR).join(copyOfRange(projectRelativeSegments, 1, projectRelativeSegments.length));
            final IFile module = project.getProject().getFile(path);
            if (null != module && module.isAccessible()) {
                uriOpener.open(testCaseURI, true);
            } else {
                openError(getShell(), "Cannot open editor", "Test class not found in selected project.");
            }
        } else {
            openError(getShell(), "Cannot open editor", "The container project not found in the workspace.");
        }
    }
}
Also used : IN4JSEclipseProject(org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject) IFile(org.eclipse.core.resources.IFile) TestCase(org.eclipse.n4js.tester.domain.TestCase) ISelection(org.eclipse.jface.viewers.ISelection) TestElement(org.eclipse.n4js.tester.domain.TestElement) URI(org.eclipse.emf.common.util.URI)

Aggregations

ISelection (org.eclipse.jface.viewers.ISelection)2 TestCase (org.eclipse.n4js.tester.domain.TestCase)2 TestElement (org.eclipse.n4js.tester.domain.TestElement)2 IFile (org.eclipse.core.resources.IFile)1 URI (org.eclipse.emf.common.util.URI)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 TestResult (org.eclipse.n4js.tester.domain.TestResult)1 IN4JSEclipseProject (org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject)1