Search in sources :

Example 6 with TestCase

use of org.eclipse.n4js.tester.domain.TestCase 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)

Example 7 with TestCase

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

the class TestTreeRegistryImpl method updateWithResult.

private TestTree updateWithResult(final TestTree tree, final String testId, final TestResult result) {
    final TestCase testCase = tree.getTestCase(testId);
    if (null == testCase) {
        throw new IllegalStateException("Test case cannot be found in test tree. Test ID: " + testId);
    }
    testCase.setResult(result);
    return tree;
}
Also used : TestCase(org.eclipse.n4js.tester.domain.TestCase)

Example 8 with TestCase

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

the class MockTest method createNewTestTree.

private TestTree createNewTestTree(final String sessionId, final int testCaseCountFactor) {
    final List<TestSuite> testSuites = newArrayList();
    create(closed(1, testCaseCountFactor), integers()).forEach(i -> {
        final String suiteName = format("%05d", i) + "_TestSuite";
        final TestSuite suite = new TestSuite(suiteName);
        create(closed(1, testCaseCountFactor), integers()).forEach(j -> {
            final String testCaseId = getTestCaseId(i, j);
            suite.add(new TestCase(new ID(testCaseId), "origin." + suiteName + "." + testCaseId + ".0.0.1", suiteName + "." + testCaseId, testCaseId, testCaseId, URI.createURI("testURI_" + testCaseId)));
        });
        testSuites.add(suite);
    });
    return new TestTree(new ID(sessionId), testSuites);
}
Also used : TestSuite(org.eclipse.n4js.tester.domain.TestSuite) TestCase(org.eclipse.n4js.tester.domain.TestCase) ID(org.eclipse.n4js.tester.domain.ID) UUID.randomUUID(java.util.UUID.randomUUID) TestTree(org.eclipse.n4js.tester.domain.TestTree)

Example 9 with TestCase

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

the class MockTest method testMock.

/**
 * Mocks the {@link TestTree test tree} argument with fake test results.
 *
 * @param testTree
 *            the test tree to generate test result.
 * @param parallel
 *            {@code true} if the mock test should be executed in parallel fashion. For serial execution this flag
 *            is {@code false}.
 */
public void testMock(final TestTree testTree, final boolean parallel) {
    final String sessionId = testTree.getSessionId().getValue();
    final String mode = parallel ? "parallel" : "synchronous";
    log("Starting " + mode + " mock test session.");
    sendToServer(URL() + sessionId + "/start/", START_SESSION, POST, null);
    final AtomicInteger i = new AtomicInteger();
    final AtomicInteger percentage = new AtomicInteger();
    final int numberOfTests = size(testTree);
    getTestCaseStream(testTree, parallel).forEach(new Consumer<TestCase>() {

        @Override
        public void accept(final TestCase testCase) {
            final String testId = testCase.getId().getValue();
            if (0 < numberOfTests && 0 < i.get()) {
                final int value = (int) (((double) i.get() / (double) numberOfTests) * 100.0);
                if (value > percentage.get()) {
                    synchronized (MockTest.class) {
                        if (value > percentage.get()) {
                            percentage.set(value);
                            log(format("Running " + mode + " mock tests... [%2s%%]", value));
                        }
                    }
                }
            }
            sendToServer(URL() + sessionId + "/tests/" + testId + "/start/", START_TEST, POST, createTimeoutBody(TIME_OUT));
            final long timeout = getMockTestExecutionTime(i.get());
            sendToServer(URL() + sessionId + "/tests/" + testId + "/ping/", PING_TEST, POST, createTimeoutBody(timeout + TIME_OUT));
            sendToServer(URL() + sessionId + "/tests/" + testId + "/end/", END_TEST, POST, createTestResult(timeout, i.incrementAndGet()));
        }
    });
    log("Ending " + mode + " mock test session.");
    sendToServer(URL() + sessionId + "/end/", END_SESSION, POST, null);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestCase(org.eclipse.n4js.tester.domain.TestCase)

Example 10 with TestCase

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

the class TestTreeRegistryTest method newTestTree.

private TestTree newTestTree(final String sessionId, final String... testIds) {
    final List<TestSuite> testSuites = newArrayList(transform(newHashSet(testIds), new Function<String, TestSuite>() {

        @Override
        public TestSuite apply(String testId) {
            final TestSuite suite = new TestSuite("TestSuite_for_Test_" + testId);
            final TestCase testCase = new TestCase(new ID(testId), "testClassName_" + testId, "origin_" + testId + "name_" + testId + "_0.0.0", "name_" + testId, "displayName_" + testId, URI.createURI("testURI_" + testId));
            suite.setTestCases(singletonList(testCase));
            return suite;
        }
    }));
    return new TestTree(new ID(sessionId), testSuites);
}
Also used : Function(com.google.common.base.Function) TestSuite(org.eclipse.n4js.tester.domain.TestSuite) TestCase(org.eclipse.n4js.tester.domain.TestCase) ID(org.eclipse.n4js.tester.domain.ID) UUID.randomUUID(java.util.UUID.randomUUID) TestTree(org.eclipse.n4js.tester.domain.TestTree)

Aggregations

TestCase (org.eclipse.n4js.tester.domain.TestCase)11 UUID.randomUUID (java.util.UUID.randomUUID)5 ID (org.eclipse.n4js.tester.domain.ID)5 TestSuite (org.eclipse.n4js.tester.domain.TestSuite)5 TestTree (org.eclipse.n4js.tester.domain.TestTree)4 ISelection (org.eclipse.jface.viewers.ISelection)2 TestElement (org.eclipse.n4js.tester.domain.TestElement)2 Function (com.google.common.base.Function)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 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 TClass (org.eclipse.n4js.ts.types.TClass)1 TMethod (org.eclipse.n4js.ts.types.TMethod)1 IN4JSEclipseProject (org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject)1 Test (org.junit.Test)1