use of org.eclipse.n4js.tester.domain.ID in project n4js by eclipse.
the class TestDiscoveryHelper method collectTests.
private TestTree collectTests(final ResourceSet resSet, final IResourceDescriptions index, final URI... locations) {
// create test cases (aggregated in test suites)
final List<TestSuite> suites = newArrayList();
// create MultiMap from trimmed(!) URI -> original URIs for this prefix URI
final List<URI> testLocations = collectDistinctTestLocations(index, resSet, locations);
final HashMultimap<URI, URI> testLocationMapping = createTestLocationMapping(testLocations);
final Map<URI, TModule> moduleUri2Modules = loadModules(testLocationMapping.asMap().keySet(), index, resSet);
for (final URI moduleLocation : testLocationMapping.keys()) {
final TModule module = moduleUri2Modules.get(moduleLocation);
if (null == module) {
// Assuming broken AST.
continue;
}
// make sure trimmed URIs processed before non-trimmed ones, in other words we collects all tests for
// test modules first, then later we can skip individual test collecting for test methods.
// so we can make sure, iff there are more than one elements in the list, and the first one equals to
// the module location URI (with any fragments), we can skip the processing, since the whole module
// contains the individual test locations
final List<URI> testLocationsForModule = newArrayList(testLocationMapping.get(moduleLocation));
testLocationsForModule.sort(URI_COMPARATOR);
if (testLocationsForModule.get(0).equals(moduleLocation)) {
// The first item is referencing the entire module
// --> collect all test methods in module and ignore remaining URIs
suites.addAll(collectSuitsForModule(module));
} else {
// we have URIs pointing to individual test methods -> collect all URIs
for (final URI uri : testLocationsForModule) {
suites.addAll(collectSuitsForMethod(uri, module));
}
}
}
// TODO what should be the name of the test tree is multiple test locations are available?
// Improve the way how we got the name of the test tree.
final ID sessionId = createTestSessionId();
String name = valueOf(sessionId);
if (locations.length > 0) {
final URI uri = locations[0];
name = valueOf(uri.trimFragment()).replaceFirst("platform:/resource/", "");
// name = name.replace("." + N4JS_FILE_EXTENSION, "");
if (name.lastIndexOf('.') > 0) {
name = name.substring(0, name.lastIndexOf('.'));
}
// Assuming one single test case.
if (uri.hasFragment() && !suites.isEmpty() && !suites.get(0).getTestCases().isEmpty()) {
name = name + "#" + suites.get(0).getTestCases().get(0).getDisplayName();
}
}
return new TestTree(sessionId, suites, name);
}
use of org.eclipse.n4js.tester.domain.ID in project n4js by eclipse.
the class TestResultsView method notifyTestEvent.
/**
* Update UI according to given {@link TestEvent}.
*/
public void notifyTestEvent(TestEvent event) {
if (event instanceof SessionStartedEvent) {
// ignore
} else if (event instanceof TestStartedEvent) {
notifyTestCaseStarted(new ID(((TestStartedEvent) event).getTestId()));
} else if (event instanceof TestEndedEvent) {
final TestEndedEvent teev = (TestEndedEvent) event;
notifyTestCaseEnded(new ID(teev.getTestId()), teev.getResult());
} else if (event instanceof SessionEndedEvent) {
// event received from client side
notifySessionEnded(new ID(event.getSessionId()));
} else if (event instanceof SessionFinishedEvent) {
// server completed test session SUCCESS
// ignore
} else if (event instanceof SessionFailedEvent) {
// server completed test session FAILURE
// ignore
} else {
// ignore all other events (e.g. TestPingedEvent)
}
}
use of org.eclipse.n4js.tester.domain.ID 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.ID 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);
}
use of org.eclipse.n4js.tester.domain.ID in project n4js by eclipse.
the class TesterDomainTest method testTestTreeClone.
/**
*/
@Test
public void testTestTreeClone() throws Exception {
final List<TestSuite> originalTestSuites = newArrayList();
final TestSuite originalTestSuite = new TestSuite("name");
final TestCase originalTestCase = new TestCase(new ID("testId"), "testId", "testId", "testId", "testId", URI.createURI("testURI_testId"));
originalTestSuite.add(originalTestCase);
originalTestSuites.add(originalTestSuite);
final TestTree originalTestTree = new TestTree(new ID("value"), originalTestSuites);
final TestTree copyTestTree = originalTestTree.clone();
assertEquals(originalTestTree, copyTestTree);
assertFalse(originalTestTree == copyTestTree);
assertFalse(originalTestSuites == copyTestTree.getSuites());
assertFalse(originalTestSuite == getOnlyElement(copyTestTree.getSuites()));
assertEquals(originalTestCase, getOnlyElement(getOnlyElement(copyTestTree.getSuites()).getTestCases()));
assertFalse(originalTestCase == getOnlyElement(getOnlyElement(copyTestTree.getSuites()).getTestCases()));
}
Aggregations