use of org.eclipse.n4js.tester.domain.TestTree in project n4js by eclipse.
the class TesterDomainTest method testTreeContainsTest.
/**
*/
@Test
public void testTreeContainsTest() {
final TestTree tree = new TestTree(new ID(valueOf(randomUUID())));
final TestSuite a = new TestSuite("A");
a.addAll(newTestCase("1", "2", "3"));
final TestSuite b = new TestSuite("B");
b.addAll(newTestCase("4", "5", "6"));
final TestSuite a1 = new TestSuite("A.1");
a1.addAll(newTestCase("7", "8"));
final TestSuite a2 = new TestSuite("A.2");
a2.addAll(newTestCase("9", "10"));
final TestSuite a11 = new TestSuite("A.1.1");
a11.addAll(newTestCase("11", "12"));
a1.getChildren().add(a11);
a.getChildren().add(a1);
a.getChildren().add(a2);
tree.getSuites().add(a);
tree.getSuites().add(b);
assertNotNull(tree.getTestCase("1"));
assertNotNull(tree.getTestCase("2"));
assertNotNull(tree.getTestCase("3"));
assertNotNull(tree.getTestCase("4"));
assertNotNull(tree.getTestCase("5"));
assertNotNull(tree.getTestCase("6"));
assertNotNull(tree.getTestCase("7"));
assertNotNull(tree.getTestCase("8"));
assertNotNull(tree.getTestCase("9"));
assertNotNull(tree.getTestCase("10"));
assertNotNull(tree.getTestCase("11"));
assertNotNull(tree.getTestCase("12"));
assertNull(tree.getTestCase("13"));
assertNull(tree.getTestCase((String) null));
assertNull(tree.getTestCase((ID) null));
}
use of org.eclipse.n4js.tester.domain.TestTree in project n4js by eclipse.
the class TestCatalogSupplier method get.
/**
* Returns with the test catalog as a string representing all available tests in the workspace. This method may
* return with a test catalog of an empty {@link TestTree test tree} if the the {@link Platform platform} is not
* running.
*
* @return the test catalog as a JSON formatted string.
*/
@Override
public String get() {
try {
final TestTree testTree = getTreeForAllTests();
final Object testCatalogObject = treeTransformer.apply(testTree);
return objectMapper.writeValueAsString(testCatalogObject);
} catch (final Exception e) {
throw new RuntimeException("Error while assembling test catalog.", e);
}
}
use of org.eclipse.n4js.tester.domain.TestTree 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.TestTree in project n4js by eclipse.
the class TesterFrontEnd method computeDerivedValues.
/**
* Similar to {@link RunnerFrontEnd#computeDerivedValues(RunConfiguration)}, but for testing.
*/
public void computeDerivedValues(TestConfiguration config) {
// A) compute derived values for the run(!) configuration (will delegate to runner)
runnerFrontEnd.computeDerivedValues(config, false);
// B) compute derived values for the test configuration
// B.1) compute the test tree (note: will create a new session ID every time this is called)
final TestTree testTree = testDiscoveryHelper.collectTests(config.getUserSelection());
config.setTestTree(testTree);
// B.2) pass test tree as execution data
try {
// Read out port of running IDE-server and pass it to end-point-computation in tree-transformer
TesterActivator testerActivator = TesterActivator.getInstance();
int port = testerActivator != null ? testerActivator.getServerPort() : PORT_PLACEHOLDER_MAGIC_NUMBER;
config.setResultReportingPort(port);
testTreeTransformer.setHttpServerPort(Integer.toString(port));
final String testTreeAsJSON = objectMapper.writeValueAsString(testTreeTransformer.apply(testTree));
config.setExecutionData(TestConfiguration.EXEC_DATA_KEY__TEST_TREE, testTreeAsJSON);
} catch (IOException e) {
e.printStackTrace();
}
// B.3) delegate further computation to the specific tester implementation
ITester tester = testerRegistry.getTester(config);
tester.prepareConfiguration(config);
}
use of org.eclipse.n4js.tester.domain.TestTree in project n4js by eclipse.
the class TesterFrontEnd method test.
/**
* Similar to {@link RunnerFrontEnd#run(RunConfiguration, IExecutor)}, but for testing.
*/
public Process test(TestConfiguration config, IExecutor executor) {
final TestTree testTree = config.getTestTree();
// prepare HTTP server for receiving test results
int port = testerFacade.prepareTestSession(testTree);
updateTestTreeDescription(config, port);
// actually launch the test
ITester tester = testerRegistry.getTester(config);
return tester.test(config, executor, runnerFrontEnd);
}
Aggregations