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