use of org.eclipse.elk.alg.test.framework.io.AbstractResourcePath in project elk by eclipse.
the class GraphFromFile method fromTestClass.
/**
* Loads graphs from files as specified by configuration methods in the test class.
*
* @param testClass
* the test class.
* @param test
* instance of the test class to call methods.
* @param errors
* list of error conditions encountered.
* @return a list of graphs.
*/
public static List<GraphFromFile> fromTestClass(final TestClass testClass, final Object test, final List<Throwable> errors) {
List<AbstractResourcePath> resourcePaths = new ArrayList<>();
for (FrameworkMethod method : testClass.getAnnotatedMethods(GraphResourceProvider.class)) {
TestUtil.ensurePublic(method, errors);
TestUtil.ensureReturnsType(method, errors, List.class);
TestUtil.ensureParameters(method, errors);
// Invoke the method to obtain the resource paths
try {
List<?> result = (List<?>) method.invokeExplosively(test);
// Check that these are all resource paths
if (!result.stream().allMatch(o -> o instanceof AbstractResourcePath)) {
errors.add(new Exception("Method " + method.getName() + " must return List<AbstractResourcePath"));
} else {
result.stream().map(o -> (AbstractResourcePath) o).forEach(path -> resourcePaths.add(path));
}
} catch (Throwable e) {
errors.add(e);
}
}
// Set a default graph file filter in case no explicit filter has been specified
resourcePaths.stream().filter(path -> path.getFilter() == null).forEach(path -> path.setFilter(GRAPH_FILE_FILTER));
// Turn the abstract paths into absolute paths
return resourcePaths.stream().flatMap(path -> path.listResources().stream()).map(path -> new GraphFromFile(path)).collect(Collectors.toList());
}
use of org.eclipse.elk.alg.test.framework.io.AbstractResourcePath in project elk by eclipse.
the class RandomGraphFromFile method fromTestClass.
/**
* Loads random graphs from files as specified by configuration methods in the test class.
*
* @param testClass
* the test class.
* @param test
* instance of the test class to call methods.
* @param errors
* list of error conditions encountered.
* @return a list of graphs.
*/
public static List<RandomGraphFromFile> fromTestClass(final TestClass testClass, final Object test, final List<Throwable> errors) {
List<AbstractResourcePath> resourcePaths = new ArrayList<>();
for (FrameworkMethod method : testClass.getAnnotatedMethods(RandomGeneratorFile.class)) {
TestUtil.ensurePublic(method, errors);
TestUtil.ensureReturnsType(method, errors, AbstractResourcePath.class);
TestUtil.ensureParameters(method, errors);
// Invoke the method to obtain the resource paths
try {
resourcePaths.add((AbstractResourcePath) method.invokeExplosively(test));
} catch (Throwable e) {
errors.add(e);
}
}
// Set proper file filters and load graphs
List<RandomGraphFromFile> graphs = new ArrayList<>();
for (AbstractResourcePath abstractPath : resourcePaths) {
abstractPath.setFilter(RANDOM_GRAPH_FILE_FILTER);
for (AbsoluteResourcePath absolutePath : abstractPath.listResources()) {
try {
for (ElkNode graph : randomGraphs(absolutePath)) {
graphs.add(new RandomGraphFromFile(absolutePath, graph));
}
} catch (Throwable e) {
errors.add(new Exception("Unable to load random graphs from " + absolutePath));
}
}
}
return graphs;
}
Aggregations