@L0.assert TESTS.STSTest.executionPriority -1
@L0.assert TESTS.ignore false
@L0.assert TESTS.ignoreReason ""
+ @L0.assert TESTS.dependencies ""
TESTS.STSTest : MOD.TypeWithChangeInformation
TESTS.STSTest : L0.TypeWithIdentifier
>-- TESTS.STSSuite.moduleNameFilter --> L0.String <R L0.HasProperty : L0.TotalFunction : SEL.GenericParameterType
@L0.assert TESTS.STSSuite.moduleNameFilter ""
@L0.assert TESTS.ignore false
+ @L0.assert TESTS.dependencies ""
TESTS.STSSuite : MOD.TypeWithChangeInformation
-TESTS.STSSuite : L0.TypeWithIdentifier
\ No newline at end of file
+TESTS.STSSuite : L0.TypeWithIdentifier
+
+TESTS.STSVariable <T L0.Entity
+ TESTS.STSVariable.definition ""
+
+TESTS.STSVariable.definition <R L0.HasProperty : L0.TotalFunction : SEL.GenericParameterType
+ L0.HasRange L0.String
+ L0.HasLabel "Variable definition"
+
+TESTS.dependencies <R L0.HasProperty : L0.TotalFunction : SEL.GenericParameterType
+ L0.HasRange L0.String
+ L0.HasLabel "Test dependencies"
@VP.namedConstantImageRule TestsUI.Contributions.SuiteImage TESTS.STSSuite TestsUI.testSuiteImage
@VP.namedRelationChildRule TestsUI.Contributions.STSTests L0.Entity L0.ConsistsOf TESTS.STSTest
@VP.customImageRule TESTS.STSTest MBC.TestImageRule
+ @VP.namedRelationChildRule TestsUI.Contributions.STSVariables L0.Entity L0.ConsistsOf TESTS.STSVariable
+ @VP.namedConstantImageRule TestsUI.Contributions.VariableImage TESTS.STSVariable SILK.page_white_edit
MBC
VP.BrowseContext.HasVisualsContribution _ : VP.VisualsContribution
@MOD.sclAction "createSTSTestAction"
ACTIONS.RunSTSTest
@MOD.sclAction "runSTSTestAction"
+ACTIONS.NewSTSVariable
+ @MOD.sclAction "createSTSVariableAction"
MAC
VP.BrowseContext.HasActionContribution TestsUI.Contributions.NewSTSSuite : VP.ActionContribution
VP.ActionContribution.HasImage SILK.control_play
VP.ActionContribution.HasCategory VP.EditActionCategory
VP.ActionContribution.HasNodeType TESTS.STSSuite
+ VP.ActionContribution.HasNodeType TESTS.STSTest
VP.ActionContribution.HasAction ACTIONS.RunSTSTest
VP.BrowseContext.HasActionContribution _ : VP.ActionContribution
- L0.HasLabel "Run"
- VP.ActionContribution.HasImage SILK.control_play
- VP.ActionContribution.HasCategory VP.EditActionCategory
+ L0.HasLabel "STS Variable"
+ VP.ActionContribution.HasImage SILK.page_white_edit
+ VP.ActionContribution.HasCategory VP.NewActionCategory
+ VP.ActionContribution.HasNodeType TESTS.STSSuite
VP.ActionContribution.HasNodeType TESTS.STSTest
- VP.ActionContribution.HasAction ACTIONS.RunSTSTest
\ No newline at end of file
+ VP.ActionContribution.HasAction ACTIONS.NewSTSVariable
createSTSSuiteAction :: Resource -> <Proc> ()
createSTSSuiteAction res = do
syncWrite (\() -> createSTSSuite res)
+ ()
+
+createSTSVariableAction :: Resource -> <Proc> ()
+createSTSVariableAction res = do
+ syncWrite(\() -> createSTSVariable res)
()
\ No newline at end of file
*/
public class STSCounterPanel extends Composite {
protected Text numberOfErrors;
+ protected Text numberOfSkipped;
protected Text numberOfFailures;
protected Text numberOfRuns;
protected int total;
setLayout(gridLayout);
numberOfRuns= createLabel("Runs:", null, " 0/0 "); //$NON-NLS-1$
+ numberOfSkipped = createLabel("Skipped:", null," 0 ");
numberOfErrors= createLabel("Errors:", fErrorIcon, " 0 "); //$NON-NLS-1$
numberOfFailures= createLabel("Failures:", fFailureIcon, " 0 "); //$NON-NLS-1$
assumptionFailedCount= assumptionFailureCount;
}
+ public void setIgnoredValue(int value) {
+ numberOfSkipped.setText(Integer.toString(value));
+ redraw();
+ }
+
public void setErrorValue(int value) {
numberOfErrors.setText(Integer.toString(value));
redraw();
public class STSTestEditor extends SCLModuleEditor2 {
+
+ @Override
+ public void setFocus() {
+ // TODO Auto-generated method stub
+ super.setFocus();
+ }
}
import javax.annotation.PreDestroy;
import org.eclipse.e4.ui.di.Focus;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.jface.layout.TreeColumnLayout;
import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Layout;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.ui.part.PageBook;
private Composite counterComposite;
@PostConstruct
- void createView(Composite parent) {
+ void createView(MPart part, Composite parent) {
GridLayout gridLayout= new GridLayout();
gridLayout.marginWidth= 0;
gridLayout.marginHeight= 0;
parent.setLayout(gridLayout);
- counterComposite= createProgressCountPanel(parent);
+ counterComposite = createProgressCountPanel(parent);
counterComposite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
counterComposite.pack();
SashForm sashForm = createSashForm(parent);
sashForm.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+// IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
}
private SashForm createSashForm(Composite parent) {
treeViewer.setContentProvider(provider);
treeViewer.setLabelProvider(provider);
+
+ Menu menu = new Menu(treeViewer.getControl());
+
+ MenuItem item1 = new MenuItem(menu, SWT.PUSH);
+ item1.setText("Stop");
+ item1.addListener(SWT.Selection, new Listener() {
+
+ @Override
+ public void handleEvent(Event event) {
+ TreeSelection selec = (TreeSelection) treeViewer.getSelection();
+ if (!selec.isEmpty()) {
+ Object elem = selec.getFirstElement();
+ provider.getModel().interrupt();
+
+ }
+ }
+ });
+
+ treeViewer.getControl().setMenu(menu);
+
viewerbook.showPage(treeViewer.getTree());
counterPanel.setTotal(totalCount);
counterPanel.setRunValue(startedCount, ignoredCount, assumptionFailureCount);
+ counterPanel.setIgnoredValue(ignoredCount);
counterPanel.setErrorValue(errorCount);
counterPanel.setFailureValue(failureCount);
package org.simantics.tests.modelled.ui;
-import java.io.BufferedReader;
-import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
-import java.util.regex.Pattern;
+import java.util.Map;
import java.util.stream.Collectors;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.swt.graphics.Image;
import org.simantics.Simantics;
import org.simantics.db.ReadGraph;
import org.simantics.db.common.request.ReadRequest;
import org.simantics.db.exception.DatabaseException;
import org.simantics.layer0.Layer0;
-import org.simantics.scl.compiler.commands.CommandSession;
-import org.simantics.scl.compiler.commands.TestScriptExecutor;
import org.simantics.scl.compiler.module.coverage.CombinedCoverage;
-import org.simantics.scl.compiler.module.options.ModuleCompilationOptions;
-import org.simantics.scl.compiler.module.options.ModuleCompilationOptionsAdvisor;
-import org.simantics.scl.compiler.module.repository.ModuleRepository;
-import org.simantics.scl.osgi.SCLOsgi;
+import org.simantics.scl.runtime.SCLContext;
import org.simantics.scl.runtime.reporting.AbstractSCLReportingHandler;
+import org.simantics.scl.runtime.reporting.SCLReportingHandler;
import org.simantics.tests.modelled.ontology.TestsResource;
import org.simantics.tests.modelled.utils.ModelledSTSSuite;
import org.simantics.tests.modelled.utils.ModelledSTSTest;
+import org.simantics.tests.modelled.utils.ModelledSTSTest.CommandSessionVariable;
import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
public class STSTestSuiteModel {
- static class STSTest {
+ private Map<String, List<CommandSessionVariable>> storedVars = new HashMap<>();
+
+ class STSTest {
private final ModelledSTSTest test;
return parent;
}
- public void execute(CommandSession session) {
+ public void execute() {
isRunning = true;
-
- TestScriptExecutor executor = new TestScriptExecutor(session, new BufferedReader(new StringReader(getDefinition())), new AbstractSCLReportingHandler() {
-
- @Override
- public void print(String text) {
- appendOutput(text + "\n");
- }
-
- @Override
- public void printCommand(String command) {
- appendOutput("> " + command + "\n");
- }
-
- @Override
- public void printError(String error) {
- appendOutput(error + "\n");
- }
- }, true);
long start = System.currentTimeMillis();
+ Object old = SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER);
try {
if (parent != null)
parent.startedCount++;
- executor.execute();
+
+ SCLContext.getCurrent().put(SCLReportingHandler.REPORTING_HANDLER, new AbstractSCLReportingHandler() {
+
+ @Override
+ public void print(String text) {
+ appendOutput(text + "\n");
+ }
+
+ @Override
+ public void printCommand(String command) {
+ appendOutput("> " + command + "\n");
+ }
+
+ @Override
+ public void printError(String error) {
+ appendOutput(error + "\n");
+ }
+ });
+ List<CommandSessionVariable> resolvedVars = new ArrayList<>();
+ for (String deps : test.getDependencies()) {
+ List<CommandSessionVariable> vars = storedVars.get(deps);
+ if (vars != null)
+ resolvedVars.addAll(vars);
+ }
+
+ List<CommandSessionVariable> vars = test.run(resolvedVars);
+ storedVars.put(test.getName(), vars);
+
executed = true;
} catch (Throwable t) {
t.printStackTrace();
isRunning = false;
long end = System.currentTimeMillis();
duration = end - start;
+
+ SCLContext.getCurrent().put(SCLReportingHandler.REPORTING_HANDLER, old);
}
-
}
protected void appendOutput(String text) {
}
}
- static class STSSuite {
+ class STSSuite {
private ModelledSTSSuite suite;
private STSTest[] children;
private STSSuite suite;
private STSTest test;
private final List<STSExecutionListener> listeners = new ArrayList<>();
+ private Job currentJob;
public STSTestSuiteModel() {
}
}
public void execute() {
-
- ModuleRepository repo = new ModuleRepository(SCLOsgi.SOURCE_REPOSITORY);
- if (suite != null) {
- repo.setAdvisor(new ModuleCompilationOptionsAdvisor() {
+ String command;
+ if (suite != null)
+ command = suite.getName();
+ else
+ command = test.getName();
+ if (currentJob != null)
+ currentJob.cancel();
+ currentJob = new Job(command) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ if (suite != null) {
+ executeSuite();
+ } else if (test != null) {
+ executeTest();
+ }
+ return Status.OK_STATUS;
+ }
+
+ @Override
+ protected void canceling() {
+ Thread thread = getThread();
+ if(thread != null)
+ thread.interrupt();
- @Override
- public ModuleCompilationOptions getOptions(String moduleName) {
- boolean coverage = false;
- for (Pattern p : suite.suite.getModuleNameFilterPatterns()) {
- if (p.matcher(moduleName.toLowerCase()).find()) {
- coverage = true;
- break;
- }
- }
- return new ModuleCompilationOptions(coverage);
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
- });
- }
- CommandSession session = new CommandSession(repo, null);
- if (suite != null) {
- executeSuite(session);
- } else if (test != null) {
- executeTest(session);
- }
+
+ thread = getThread();
+ if(thread != null)
+ thread.stop();
+ }
+ };
+ currentJob.schedule();
+ }
+
+ public void interrupt() {
+ if (currentJob != null)
+ currentJob.cancel();
}
private void testExecuted() {
});
}
- private void executeSuite(CommandSession session) {
+ private void executeSuite() {
for (STSTest test : suite.getChildren()) {
if (test.isIgnored()) {
testExecuted();
test.getParent().ignoredCount++;
continue;
}
- test.execute(session);
- STSSuiteTestCollector.setSuiteCoverage(test.test, suite.suite, session);
+ test.execute();
testExecuted();
}
}
- private void executeTest(CommandSession session) {
- test.execute(session);
+ private void executeTest() {
+ test.execute();
testExecuted();
- STSSuiteTestCollector.setTestCoverage(test.test, session);
}
public boolean hasChildren(Object element) {
include "Simantics/DB"
importJava "org.simantics.tests.modelled.TestsGraphUtils" where
- createSTSTest :: Resource -> <Proc, WriteGraph> Resource
- createSTSSuite :: Resource -> <WriteGraph, Proc> ()
+ createSTSTest :: Resource -> <WriteGraph, Proc> Resource
+ createSTSSuite :: Resource -> <WriteGraph, Proc> Resource
+ createSTSVariable :: Resource -> <WriteGraph, Proc> Resource
private static final String STS_TEST_PREFIX = "STSTest";
private static final String STS_SUITE_PREFIX = "STSSuite";
+ private static final String STS_VARIABLE_PREFIX = "STSVariable";
private TestsGraphUtils() {}
+ public static Resource createSTSVariable(WriteGraph graph, Resource parent) throws DatabaseException {
+ String name = NameUtils.findFreshEscapedName(graph, STS_VARIABLE_PREFIX, parent);
+ Resource stsVariable = graph.newResource();
+
+ Layer0 L0 = Layer0.getInstance(graph);
+ TestsResource TESTS = TestsResource.getInstance(graph);
+
+ graph.claim(parent, L0.ConsistsOf, L0.PartOf, stsVariable);
+ graph.claim(stsVariable, L0.InstanceOf, TESTS.STSVariable);
+ graph.claimLiteral(stsVariable, L0.HasName, name, Bindings.STRING);
+ graph.claimLiteral(stsVariable, TESTS.STSVariable_definition, "", Bindings.STRING);
+ return stsVariable;
+ }
+
public static Resource createSTSTest(WriteGraph graph, Resource parent) throws DatabaseException {
String name = NameUtils.findFreshEscapedName(graph, STS_TEST_PREFIX, parent);
Resource stsTest = graph.newResource();
package org.simantics.tests.modelled.junit.v2;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
-import java.util.stream.Collectors;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.junit.runner.Description;
import org.junit.runners.model.InitializationError;
import org.simantics.Simantics;
import org.simantics.db.testing.common.AcornTests;
-import org.simantics.scl.compiler.commands.CommandSession;
-import org.simantics.scl.osgi.SCLOsgi;
+import org.simantics.tests.modelled.utils.ModelledSTSSuite;
import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
public class ModelledSTSRunner extends ParentRunner<ModelledSTSSuiteRunner> {
- private CommandSession commandSession;
+ private final List<ModelledSTSSuiteRunner> children;
- public ModelledSTSRunner(Class<?> testClass) throws Exception {
+ public ModelledSTSRunner(Class<?> testClass) throws InitializationError {
super(testClass);
- initialize0();
+ try {
+ initialize0();
+ Collection<ModelledSTSSuite> suites = STSSuiteTestCollector.collectTests();
+ children = new ArrayList<>(suites.size());
+ for (ModelledSTSSuite suite : suites) {
+ children.add(new ModelledSTSSuiteRunner(suite));
+ }
+ } catch (Exception e) {
+ throw new InitializationError(e);
+ }
}
@Override
protected List<ModelledSTSSuiteRunner> getChildren() {
- return STSSuiteTestCollector.collectTests().stream().map(suite -> {
- try {
- return new ModelledSTSSuiteRunner(suite);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }).collect(Collectors.toList());
+ return children;
}
@Override
@Override
protected void runChild(ModelledSTSSuiteRunner child, RunNotifier notifier) {
- child.setCommandSesssion(commandSession);
child.run(notifier);
// TODO: Add coverage reporting to ModelledSTSRunner
// CombinedCoverage cover = child.getCoverage();
private void initialize0() throws Exception {
AcornTests.newSimanticsWorkspace(null, null);
- this.commandSession = new CommandSession(SCLOsgi.MODULE_REPOSITORY, null);
initialize();
}
package org.simantics.tests.modelled.junit.v2;
+import java.util.ArrayList;
import java.util.List;
-import java.util.stream.Collectors;
+import java.util.Map;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.ParentRunner;
-import org.simantics.scl.compiler.commands.CommandSession;
+import org.junit.runners.model.InitializationError;
import org.simantics.scl.compiler.module.coverage.CombinedCoverage;
-import org.simantics.scl.osgi.SCLOsgi;
import org.simantics.tests.modelled.utils.ModelledSTSSuite;
-import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
+import org.simantics.tests.modelled.utils.ModelledSTSTest;
+import org.simantics.tests.modelled.utils.ModelledSTSTest.CommandSessionVariable;
public class ModelledSTSSuiteRunner extends ParentRunner<ModelledSTSTestRunner> {
private final ModelledSTSSuite suite;
- private CommandSession commandSession;
+ private final List<ModelledSTSTestRunner> children;
+ private Map<String, List<CommandSessionVariable>> storedVariables;
- public ModelledSTSSuiteRunner(ModelledSTSSuite suite) throws Exception {
+ public ModelledSTSSuiteRunner(ModelledSTSSuite suite) throws InitializationError {
super(ModelledSTSSuiteRunner.class);
this.suite = suite;
+ this.children = new ArrayList<>(suite.getChildren().size());
+ for (ModelledSTSTest test : suite.getSortedChildren()) {
+ children.add(new ModelledSTSTestRunner(test));
+ }
}
@Override
@Override
protected List<ModelledSTSTestRunner> getChildren() {
- return suite.getChildren().stream().map(test -> new ModelledSTSTestRunner(test)).collect(Collectors.toList());
+ return children;
}
@Override
if (isIgnored(child)) {
notifier.fireTestIgnored(description);
} else {
- notifier.fireTestStarted(description);
try {
- child.run(getCommandSession());
+ List<CommandSessionVariable> variables = new ArrayList<>();
+ for (String dep : child.getTest().getDependencies()) {
+ List<CommandSessionVariable> storedVars = storedVariables.get(dep);
+ if (storedVars != null) {
+ variables.addAll(storedVars);
+ }
+ }
+ List<CommandSessionVariable> newVars = child.runWithVars(variables);
+ storedVariables.put(child.getTest().getName(), newVars);
notifier.fireTestFinished(description);
- STSSuiteTestCollector.setSuiteCoverage(child.getTest(), suite, getCommandSession());
- } catch (Throwable e) {
+ } catch (Exception e) {
notifier.fireTestFailure(new Failure(description, e));
}
- }
+ }
}
@Override
return child.isIgnored();
}
- public void setCommandSesssion(CommandSession commandSession) {
- this.commandSession = commandSession;
- }
-
- public CommandSession getCommandSession() {
- if (commandSession == null)
- commandSession = new CommandSession(SCLOsgi.MODULE_REPOSITORY, null);
- return commandSession;
- }
-
public CombinedCoverage getCoverage() {
return suite.getCoverage();
}
package org.simantics.tests.modelled.junit.v2;
-import java.io.BufferedReader;
-import java.io.StringReader;
+import java.io.IOException;
+import java.util.List;
import org.junit.runner.Description;
import org.junit.runner.Runner;
+import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunNotifier;
-import org.simantics.scl.compiler.commands.CommandSession;
-import org.simantics.scl.compiler.commands.TestScriptExecutor;
-import org.simantics.scl.osgi.SCLOsgi;
-import org.simantics.scl.runtime.SCLContext;
-import org.simantics.scl.runtime.reporting.SCLReportingHandler;
import org.simantics.tests.modelled.utils.ModelledSTSTest;
-import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
+import org.simantics.tests.modelled.utils.ModelledSTSTest.CommandSessionVariable;
public class ModelledSTSTestRunner extends Runner {
this.test = test;
}
- public String getName() {
- return test.getName();
- }
-
@Override
public Description getDescription() {
if (description == null)
- description = Description.createTestDescription(ModelledSTSTestRunner.class, getName());
+ description = Description.createTestDescription(ModelledSTSTestRunner.class, test.getName());
return description;
}
- /**
- * This method is called from ModelledSTSSuite (ParentRunner) with the same
- * CommandSession
- *
- * @param session
- */
- public void run(CommandSession session) {
- try (BufferedReader reader = new BufferedReader(new StringReader(test.getCode()))) {
- SCLReportingHandler handler = (SCLReportingHandler) SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER);
- new TestScriptExecutor(session, reader, handler, true).execute();
- STSSuiteTestCollector.setTestCoverage(test, session);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ public List<CommandSessionVariable> runWithVars(List<CommandSessionVariable> vars) throws IOException {
+ return test.run(vars);
}
-
+
@Override
public void run(RunNotifier notifier) {
- notifier.fireTestStarted(getDescription());
- try {
- run(new CommandSession(SCLOsgi.MODULE_REPOSITORY, null));
- } finally {
- notifier.fireTestFinished(getDescription());
- }
+ throw new UnsupportedOperationException();
}
public boolean isIgnored() {
package org.simantics.tests.modelled.utils;
import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
-import java.util.stream.Collectors;
import org.simantics.scl.compiler.module.Module;
import org.simantics.scl.compiler.module.coverage.CombinedCoverage;
private List<Pattern> moduleNameFilterPatterns = new ArrayList<>();
private CoverageBuilder coverageBuilder;
+ private Map<String, String> variables;
- ModelledSTSSuite(String name, List<ModelledSTSTest> children, String moduleNameFilter) {
+ ModelledSTSSuite(String name, List<ModelledSTSTest> children, String moduleNameFilter, Map<String, String> variables) {
this.name = name;
this.children = children;
+ this.variables = variables;
this.moduleNameFilter = moduleNameFilter;
for (String s : moduleNameFilter.split(",")) {
try {
return children;
}
+ static Comparator<ModelledSTSTest> comparator = (test1, test2) -> compareTests(test1, test2);
+
public List<ModelledSTSTest> getSortedChildren() {
- return new ArrayList<>(children).stream().sorted(ModelledSTSSuite::compareTests).collect(Collectors.toList());
+ Set<ModelledSTSTest> testsWithDeps = new HashSet<>();
+ // This TreeMap sorts the tests with the comparator
+ TreeMap<ModelledSTSTest, String> sortedTests = new TreeMap<>(comparator);
+ for (ModelledSTSTest test : getChildren()) {
+ Set<String> testDependencies = test.getDependencies();
+ if (testDependencies.isEmpty()) {
+ // First tests that have no dependencies
+ sortedTests.put(test, test.getName());
+ } else {
+ // These are resolved later
+ testsWithDeps.add(test);
+ }
+ }
+
+ // Construct a LinkedList that is returned as a result
+ LinkedList<ModelledSTSTest> results = new LinkedList<>(sortedTests.keySet());
+
+// Set<ModelledSTSTest> temp = new HashSet<>(testsWithDeps);
+ // Now resolve tests with dependencies
+ for (ModelledSTSTest testWithDep : testsWithDeps) {
+ boolean satisfied = true;
+ for (String dep : testWithDep.getDependencies()) {
+ if (!sortedTests.containsValue(dep)) {
+ satisfied = false;
+ } else {
+ testWithDep.resolveDependency(dep);
+ }
+ }
+ if (satisfied) {
+ results.addLast(testWithDep);
+ sortedTests.put(testWithDep, testWithDep.getName());
+ } else {
+ // Not satisfied
+ System.out.println(testWithDep.getName() + " not satisfied");
+ }
+ }
+ return results;
}
private static int compareTests(ModelledSTSTest test1, ModelledSTSTest test2) {
package org.simantics.tests.modelled.utils;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import org.simantics.scl.compiler.commands.CommandSession;
+import org.simantics.scl.compiler.commands.TestScriptExecutor;
import org.simantics.scl.compiler.module.coverage.CombinedCoverage;
+import org.simantics.scl.compiler.module.options.ModuleCompilationOptions;
+import org.simantics.scl.compiler.module.options.ModuleCompilationOptionsAdvisor;
+import org.simantics.scl.compiler.module.repository.ModuleRepository;
+import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.compiler.types.Types;
+import org.simantics.scl.osgi.SCLOsgi;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.reporting.SCLReportingHandler;
public class ModelledSTSTest {
private final String code;
private final int priority;
private final boolean ignored;
-
+ private Set<String> dependencies;
+ private Set<String> unresolvedDependencies;
+
private CombinedCoverage coverage;
+ private Map<String, String> variables;
- ModelledSTSTest(String name, String code, int priority, boolean ignored) {
+ ModelledSTSTest(String name, String code, int priority, boolean ignored, Set<String> dependencies, Map<String, String> variables) {
this.name = name;
this.code = code;
this.priority = priority;
this.ignored = ignored;
+ this.dependencies = dependencies;
+ this.unresolvedDependencies = new HashSet<>(dependencies);
+ this.variables = variables;
}
public String getName() {
}
public boolean isIgnored() {
- return ignored;
+ return (ignored || !unresolvedDependencies.isEmpty());
}
public void setCoverage(CombinedCoverage coverage) {
public CombinedCoverage getCoverage() {
return coverage;
}
+
+ public static class CommandSessionVariable {
+
+ private final String name;
+ private final Type type;
+ private final Object value;
+
+ public CommandSessionVariable(String name, Type type, Object value) {
+ this.name = name;
+ this.type = type;
+ this.value = value;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+ }
+
+ public List<CommandSessionVariable> run(List<CommandSessionVariable> vars) throws IOException {
+ ModuleRepository repo = new ModuleRepository(SCLOsgi.SOURCE_REPOSITORY);
+ repo.setAdvisor(new ModuleCompilationOptionsAdvisor() {
+
+ @Override
+ public ModuleCompilationOptions getOptions(String moduleName) {
+ // TODO: default to false
+ boolean coverage = true;
+ // TODO: add moduleName filters back
+// for (Pattern p : getModuleNameFilterPatterns()) {
+// if (p.matcher(moduleName.toLowerCase()).find()) {
+// coverage = true;
+// break;
+// }
+// }
+ return new ModuleCompilationOptions(coverage);
+ }
+ });
+
+ SCLReportingHandler handler = (SCLReportingHandler) SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER);
+ CommandSession session = new CommandSession(repo, handler);
+
+ for (CommandSessionVariable var : vars)
+ session.setVariable(var.getName(), var.getType(), var.getValue());
+
+ for (Map.Entry<String, String> entry : variables.entrySet())
+ session.setVariable(entry.getKey(), Types.STRING, entry.getValue());
+
+ new TestScriptExecutor(session, new BufferedReader(new StringReader(code)), handler, true).execute();
+ STSSuiteTestCollector.setTestCoverage(this, session);
+
+ // Return variables from this session
+ List<CommandSessionVariable> result = new ArrayList<>();
+ for (String var : session.getVariables())
+ result.add(new CommandSessionVariable(var, session.getVariableType(var), session.getVariableValue(var)));
+
+ return result;
+ }
+
+ public Set<String> getDependencies() {
+ return dependencies;
+ }
+
+ public Set<String> getUnresolvedDependencies() {
+ return unresolvedDependencies;
+ }
+
+ public boolean resolveDependency(String testDep) {
+ return unresolvedDependencies.remove(testDep);
+ }
}
package org.simantics.tests.modelled.utils;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.regex.Pattern;
import org.simantics.Simantics;
/**
* TODO: The idea of this class was to collect all the tests from shared libraries and construct
* JUnit tests out of them programmatically and then run them with JUnit to get results
+ * @throws DatabaseException
*
*/
- private static Collection<ModelledSTSSuite> collectTestsFromGraph() {
- try {
- Collection<ModelledSTSSuite> suitess = Simantics.getSession().syncRequest(new UniqueRead<Collection<ModelledSTSSuite>>() {
+ public static Collection<ModelledSTSSuite> collectTests() throws DatabaseException {
+ Collection<ModelledSTSSuite> suitess = Simantics.getSession().syncRequest(new UniqueRead<Collection<ModelledSTSSuite>>() {
- @Override
- public Collection<ModelledSTSSuite> perform(ReadGraph graph) throws DatabaseException {
-
- List<Resource> sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE);
+ @Override
+ public Collection<ModelledSTSSuite> perform(ReadGraph graph) throws DatabaseException {
+
+ List<Resource> sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE);
+ if (LOGGER.isInfoEnabled())
+ LOGGER.info("Found {} shared ontologies from graph", sharedOntologies.size());
+ Collection<ModelledSTSSuite> suites = new HashSet<>();
+ TestsResource TESTS = TestsResource.getInstance(graph);
+ Layer0 L0 = Layer0.getInstance(graph);
+ for (Resource sharedOntology : sharedOntologies) {
if (LOGGER.isInfoEnabled())
- LOGGER.info("Found {} shared ontologies from graph", sharedOntologies.size());
- Collection<ModelledSTSSuite> suites = new HashSet<>();
- TestsResource TESTS = TestsResource.getInstance(graph);
- Layer0 L0 = Layer0.getInstance(graph);
- for (Resource sharedOntology : sharedOntologies) {
- if (LOGGER.isInfoEnabled())
- LOGGER.info("Searching {} for modelled tests", graph.getURI(sharedOntology));
- List<Resource> stsSuites = ModelingUtils.searchByType(graph, sharedOntology, TESTS.STSSuite);
- for (Resource stsSuite : stsSuites) {
- try {
- Collection<Resource> tests = graph.syncRequest(new ObjectsWithType(stsSuite, L0.ConsistsOf, TESTS.STSTest));
- if (tests.isEmpty())
- continue;
-
- List<ModelledSTSTest> testRunners = new ArrayList<>(tests.size());
- for (Resource test : tests)
- testRunners.add(toModelledTest(graph, test));
+ LOGGER.info("Searching {} for modelled tests", graph.getURI(sharedOntology));
+ List<Resource> stsSuites = ModelingUtils.searchByType(graph, sharedOntology, TESTS.STSSuite);
+ for (Resource stsSuite : stsSuites) {
+ try {
+ Collection<Resource> tests = graph.syncRequest(new ObjectsWithType(stsSuite, L0.ConsistsOf, TESTS.STSTest));
+ if (tests.isEmpty())
+ continue;
+
+ List<ModelledSTSTest> testRunners = new ArrayList<>(tests.size());
+ for (Resource test : tests)
+ testRunners.add(toModelledTest(graph, test));
- suites.add(toModelledSuite(graph, stsSuite, testRunners));
- } catch (Exception e) {
- LOGGER.error("", e);
- }
+ suites.add(toModelledSuite(graph, stsSuite, testRunners));
+ } catch (Exception e) {
+ LOGGER.error("", e);
}
}
- return suites;
}
- });
- return suitess;
- } catch (DatabaseException e) {
- LOGGER.error("Could not find modelled tests", e);
- return Collections.emptyList();
- }
+ return suites;
+ }
+ });
+ return suitess;
}
public static ModelledSTSTest toModelledTest(ReadGraph graph, Resource test) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
TestsResource TESTS = TestsResource.getInstance(graph);
- String testName = graph.getRelatedValue(test, Layer0.getInstance(graph).HasName, Bindings.STRING);
+ String testName = graph.getRelatedValue(test, L0.HasName, Bindings.STRING);
String code = graph.getRelatedValue(test, TESTS.STSTest_definition, Bindings.STRING);
Integer priority = graph.getPossibleRelatedValue(test, TESTS.STSTest_executionPriority, Bindings.INTEGER);
Boolean ignored = graph.getPossibleRelatedValue(test, TESTS.ignore, Bindings.BOOLEAN);
- return new ModelledSTSTest(testName, code, priority != null ? priority : -1, ignored != null ? ignored : false);
+
+ String dependencies = graph.getPossibleRelatedValue(test, TESTS.dependencies, Bindings.STRING);
+ String[] actualDeps = dependencies.isEmpty() ? new String[0] : dependencies.split(",");
+
+ // collect variables
+ Collection<Resource> stsVariables = graph.getObjects(test, L0.ConsistsOf);
+ Map<String, String> variables = new HashMap<>(stsVariables.size());
+ for (Resource stsVariable : stsVariables) {
+ String name = graph.getRelatedValue(stsVariable, L0.HasName, Bindings.STRING);
+ String value = graph.getRelatedValue(stsVariable, TESTS.STSVariable_definition);
+ variables.put(name, value);
+ }
+ return new ModelledSTSTest(testName, code, priority != null ? priority : -1, ignored != null ? ignored : false, new HashSet<>(Arrays.asList(actualDeps)), variables);
}
public static ModelledSTSSuite toModelledSuite(ReadGraph graph, Resource suite, List<ModelledSTSTest> children) throws DatabaseException {
TestsResource TESTS = TestsResource.getInstance(graph);
String suiteName = graph.getURI(suite);
String moduleNameFilter = graph.getPossibleRelatedValue2(suite, TESTS.STSSuite_moduleNameFilter, Bindings.STRING);
- return new ModelledSTSSuite(suiteName, children, moduleNameFilter);
+
+ Layer0 L0 = Layer0.getInstance(graph);
+ Collection<Resource> stsVariables = graph.sync(new ObjectsWithType(suite, L0.ConsistsOf, TESTS.STSVariable));
+ Map<String, String> variables = new HashMap<>(stsVariables.size());
+ for (Resource stsVariable : stsVariables) {
+ String name = graph.getRelatedValue(stsVariable, L0.HasName, Bindings.STRING);
+ String value = graph.getRelatedValue(stsVariable, TESTS.STSVariable_definition);
+ variables.put(name, value);
+ }
+ return new ModelledSTSSuite(suiteName, children, moduleNameFilter, variables);
}
public static void setTestCoverage(ModelledSTSTest test, CommandSession session) {
test.setCoverage(CoverageUtils.getCoverage(modules));
CoverageUtils.resetCoverage(modules);
}
-
- public static List<ModelledSTSSuite> collectTests() {
- return new ArrayList<>(collectTestsFromGraph());
- }
-
public static void setSuiteCoverage(ModelledSTSTest test, ModelledSTSSuite suite, CommandSession session) {
Collection<RuntimeModule> runtimeModules = session.getRuntimeEnvironment().getRuntimeModules();