Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.simantics.sysdyn.tests.Activator
Require-Bundle: org.simantics.modelica;bundle-version="1.0.0",
- org.junit;bundle-version="4.8.2"
+ org.junit;bundle-version="4.8.2",
+ org.simantics.db.testing;bundle-version="1.0.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.osgi.framework
--- /dev/null
+package org.simantics.sysdyn.tests.scl;\r
+\r
+import junit.runner.Version;\r
+\r
+import org.junit.Test;\r
+import org.simantics.db.testing.base.ScriptTestBase;\r
+\r
+public class SCLTestScripts extends ScriptTestBase {\r
+\r
+ public SCLTestScripts() {\r
+ super("../scripts");\r
+ System.out.println("JUnit version is: " + Version.id());\r
+ }\r
+\r
+ @Test public void ImportModel_DiscoveryAndExploitationOfResources() { test(300); }\r
+ @Test public void ImportModel_GlobalCarbonCycle() { test(300); }\r
+ @Test public void ImportModel_PredatorAndLimitedPrey() { test(300); }\r
+ @Test public void ImportModel_ResourceExploitationUseRecycling() { test(300); }\r
+ @Test public void ImportModel_TouristsEnvironmentsAndHotelFacilities() { test(300); }\r
+ \r
+}
\ No newline at end of file
--- /dev/null
+package org.simantics.sysdyn.tests.scl;\r
+\r
+import org.junit.BeforeClass;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.junit.runners.Suite.SuiteClasses;\r
+import org.simantics.db.testing.common.RegressionSuiteRunner;\r
+\r
+@RunWith(RegressionSuiteRunner.class)\r
+@SuiteClasses({SCLTestScripts.class})\r
+\r
+public class SCLTests {\r
+\r
+ @BeforeClass\r
+ public static void setUp() {\r
+\r
+ }\r
+ \r
+ @Test\r
+ public static void asd() {\r
+ System.out.println("asd");\r
+ }\r
+ \r
+}\r
--- /dev/null
+>import "File"\r
+>import "Simantics/Misc"\r
+>import "Simantics/Testing"\r
+>import "Simantics/Sysdyn"\r
+>m = importModel $ (getSystemProperty "scl.test.path") + "/../../../../../../../org.simantics.sysdyn.feature/rootFiles/sampleModels/Discovery And Exploitation Of Resources.sysdyn"\r
+>exp = fromJust $ possibleResourceChild m "Experiment"\r
+>id = activateExperiment exp\r
+>run id\r
--- /dev/null
+>import "File"\r
+>import "Simantics/Misc"\r
+>import "Simantics/Testing"\r
+>import "Simantics/Sysdyn"\r
+>m = importModel $ (getSystemProperty "scl.test.path") + "/../../../../../../../org.simantics.sysdyn.feature/rootFiles/sampleModels/Global Carbon Cycle.sysdyn"\r
+>exp = fromJust $ possibleResourceChild m "Experiment"\r
+>id = activateExperiment exp\r
+>run id\r
+>withinEpsilon (lastValue exp id "/Carbon In Biosphere") 2710.604 0.001\r
+True
\ No newline at end of file
--- /dev/null
+>import "File"\r
+>import "Simantics/Misc"\r
+>import "Simantics/Testing"\r
+>import "Simantics/Sysdyn"\r
+>m = importModel $ (getSystemProperty "scl.test.path") + "/../../../../../../../org.simantics.sysdyn.feature/rootFiles/sampleModels/Predator And Limited Prey.sysdyn"\r
+>exp = fromJust $ possibleResourceChild m "Experiment"\r
+>id = activateExperiment exp\r
+>run id\r
--- /dev/null
+>import "File"\r
+>import "Simantics/Misc"\r
+>import "Simantics/Testing"\r
+>import "Simantics/Sysdyn"\r
+>m = importModel $ (getSystemProperty "scl.test.path") + "/../../../../../../../org.simantics.sysdyn.feature/rootFiles/sampleModels/Resource Exploitation Use Recycling.sysdyn"\r
+>exp = fromJust $ possibleResourceChild m "Experiment"\r
+>id = activateExperiment exp\r
+>run id\r
--- /dev/null
+>import "File"\r
+>import "Simantics/Misc"\r
+>import "Simantics/Testing"\r
+>import "Simantics/Sysdyn"\r
+>m = importModel $ (getSystemProperty "scl.test.path") + "/../../../../../../../org.simantics.sysdyn.feature/rootFiles/sampleModels/Tourists Environments And Hotel Facilities.sysdyn"\r
+>exp = fromJust $ possibleResourceChild m "Experiment"\r
+>id = activateExperiment exp\r
+>run id\r
import org.simantics.sysdyn.ui.editor.SysdynEditorNamingService;\r
import org.simantics.ui.workbench.IEditorNamingService;\r
import org.simantics.utils.FileUtils;\r
+import org.simantics.utils.ui.BundleUtils;\r
\r
public class SysdynProject extends AbstractProjectFeature {\r
private static final String DEFAULT_PERSPECTIVE = "org.simantics.sysdyn.ui.perspective";\r
final IProject project = getProject();\r
final Session session = getSession();\r
\r
+ try {\r
+ File base = BundleUtils.findFile("org.simantics.sysdyn.ui", "");\r
+ File f = new File(base, "../org.simantics.sysdyn.tests/src/org/simantics/sysdyn/tests/scripts");\r
+ if(f.exists()) {\r
+ System.setProperty("scl.test.path", f.getAbsolutePath());\r
+ }\r
+ } catch (Exception e) {\r
+ \r
+ }\r
+ \r
+\r
getProjectElement().setHint(ProjectKeys.DEFAULT_PERSPECTIVE, DEFAULT_PERSPECTIVE);\r
\r
// Multi for simupedia use\r
+include "UI/Progress"\r
include "Simantics/DB"\r
include "Simantics/Variables"\r
\r
formatDate :: Long -> <ReadGraph> String \r
\r
@JavaName importModel\r
- importModel :: String -> <Proc> ()\r
+ importModel :: String -> <Proc> Resource\r
\r
@JavaName isParameter\r
isParameter :: Variable -> <ReadGraph> Boolean\r
+\r
+ lastValue :: Resource -> String -> String -> Double\r
+\r
+importJava "org.simantics.sysdyn.manager.SysdynExperiments" where\r
+ \r
+ activateExperiment :: Resource -> String\r
+ run :: String -> ()\r
\ No newline at end of file
super(graph, parent, indexes);\r
}\r
\r
+ public static double[] UNRESOLVED = new double[0];\r
+ \r
@Override\r
public double[] getValue() {\r
if(experiment == null)\r
- return new double[0];\r
+ return UNRESOLVED;\r
\r
Collection<SysdynResult> results = experiment.getActiveResults();\r
ArrayList<String> variableNames = getVariableNamesWithIndexNumbers();\r
if(ds != null && ds.values != null && ds.values.length > 0) {\r
result[i] = ds.values[ds.values.length-1];\r
} else {\r
- result[i] = 0;\r
+ return UNRESOLVED;\r
}\r
}\r
}\r
import java.util.Comparator;\r
import java.util.Date;\r
import java.util.List;\r
+import java.util.concurrent.TimeUnit;\r
\r
import org.eclipse.core.runtime.NullProgressMonitor;\r
+import org.simantics.Simantics;\r
import org.simantics.databoard.Bindings;\r
import org.simantics.databoard.util.Base64;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.common.request.ObjectsWithSupertype;\r
+import org.simantics.db.common.request.UniqueRead;\r
+import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.common.utils.ListUtils;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.EvaluatingListener;\r
+import org.simantics.db.layer0.util.EvaluatingListener.Criterion;\r
+import org.simantics.db.layer0.util.EvaluatingListener.Evaluation;\r
import org.simantics.db.layer0.variable.Variables;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.modeling.ModelingResources;\r
+import org.simantics.scl.runtime.function.FunctionImpl1;\r
import org.simantics.simulation.ontology.SimulationResource;\r
import org.simantics.structural.stubs.StructuralResource2;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.adapter.ValueIndexVariable;\r
import org.simantics.sysdyn.manager.SysdynModel;\r
import org.simantics.sysdyn.manager.SysdynModelManager;\r
import org.simantics.sysdyn.representation.Book;\r
import org.simantics.sysdyn.representation.Variability;\r
import org.simantics.sysdyn.representation.Variable;\r
import org.simantics.sysdyn.utils.imports.ImportUtils;\r
+import org.simantics.utils.DataContainer;\r
\r
public class DocumentationUtils {\r
\r
* \r
* @param path\r
*/\r
- public static void importModel(String path) {\r
- ImportUtils.importModelFile(path, new NullProgressMonitor());\r
+ public static Resource importModel(String path) {\r
+ final DataContainer<Resource> m = new DataContainer<Resource>();\r
+ ImportUtils.importModelFile(path, new NullProgressMonitor(), new FunctionImpl1<Resource,WriteRequest>() {\r
+\r
+ @Override\r
+ public WriteRequest apply(Resource model) {\r
+ m.set(model);\r
+ return null;\r
+ }\r
+ \r
+ });\r
+ return m.get();\r
}\r
\r
public static boolean isParameter(ReadGraph graph, org.simantics.db.layer0.variable.Variable variable) throws DatabaseException {\r
Resource expression = expressions.get(0);\r
return graph.isInstanceOf(expression, SR.ParameterExpression);\r
}\r
+ \r
+ public static double lastValue(final Resource experiment, final String runId, final String path) throws DatabaseException {\r
+ \r
+ try {\r
+ double[] values = EvaluatingListener.<double[]>trySyncRequest(Simantics.getSession(),\r
+ \r
+ new UniqueRead<double[]>(){\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public double[] perform(ReadGraph graph) throws DatabaseException{\r
+ \r
+ org.simantics.db.layer0.variable.Variable var = Variables.getVariable(graph, experiment);\r
+ if(var == null) return null;\r
+ org.simantics.db.layer0.variable.Variable run = var.getPossibleChild(graph, runId);\r
+ if(run == null) return null;\r
+ org.simantics.db.layer0.variable.Variable v = run.browsePossible(graph, path + "#value#");\r
+ if(v == null) return null;\r
+ return v.getPossibleValue(graph);\r
+ \r
+ } \r
+ }, \r
+ new Criterion<double[]>() {\r
+\r
+ @Override\r
+ public Evaluation evaluate(double[] result) {\r
+ if(result == null) return Evaluation.DISCARD;\r
+ return (result != ValueIndexVariable.UNRESOLVED) ? Evaluation.ACCEPT : Evaluation.IGNORE;\r
+ }\r
+ \r
+ },\r
+ 15, TimeUnit.SECONDS);\r
+ return values[0];\r
+ } catch (InterruptedException e) {\r
+ e.printStackTrace();\r
+ return Double.NaN;\r
+ }\r
+ \r
+ }\r
+ \r
}\r