]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Added missing org.simantics.modeling.tests plug-ins.
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 20 Jan 2017 09:21:37 +0000 (11:21 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 20 Jan 2017 09:21:37 +0000 (11:21 +0200)
This was previously only in SVN trunk which is now locked
and is needed by tests in other projects.

refs #6994

42 files changed:
bundles/org.simantics.modeling.tests/.classpath [new file with mode: 0644]
bundles/org.simantics.modeling.tests/.project [new file with mode: 0644]
bundles/org.simantics.modeling.tests/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
bundles/org.simantics.modeling.tests/META-INF/MANIFEST.MF [new file with mode: 0644]
bundles/org.simantics.modeling.tests/build.properties [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/cases/ModelingCommandSequenceTest.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/ActivateProfile.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AddDiagram.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AddModule.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertIssueCount.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertMappedComponent.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertMappedConnection.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertMemoryConsumption.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertModelIssueCount.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertStateValue.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/CollectMemory.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/Connect.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/FailingWrite.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/ForAllDiagrams.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/LoadDiagram.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/MergeFlags.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/MergeFlagsInvoker.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/ModificationEvents.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/OpenAndCloseDiagram.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/PrintListeners.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/ResourceWriteCommand.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/RunAllBatchValidations.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/SetDevelopmentProperty.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/UnloadDiagram.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/Utils.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/WaitActiveExperiment.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/WaitMapping.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/WriteConfiguration.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/WriteHeapDump.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/WriteState.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/AbstractSingleResourceTrait.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/ActiveExperimentRunTrait.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/DiagramElementTrait.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/SingleModelTrait.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/SingleResourceTrait.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/SingleResourceTraitImpl.java [new file with mode: 0644]
bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/UriResourceTrait.java [new file with mode: 0644]

diff --git a/bundles/org.simantics.modeling.tests/.classpath b/bundles/org.simantics.modeling.tests/.classpath
new file mode 100644 (file)
index 0000000..eca7bdb
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/bundles/org.simantics.modeling.tests/.project b/bundles/org.simantics.modeling.tests/.project
new file mode 100644 (file)
index 0000000..61b979c
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>org.simantics.modeling.tests</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.ManifestBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.SchemaBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>
diff --git a/bundles/org.simantics.modeling.tests/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.modeling.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..374f61e
--- /dev/null
@@ -0,0 +1,8 @@
+#Fri May 04 09:08:52 EEST 2012
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bundles/org.simantics.modeling.tests/META-INF/MANIFEST.MF b/bundles/org.simantics.modeling.tests/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..fb52383
--- /dev/null
@@ -0,0 +1,18 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Modeling Tests
+Bundle-SymbolicName: org.simantics.modeling.tests
+Bundle-Version: 1.0.0.qualifier
+Bundle-Vendor: Semantum Oy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Require-Bundle: org.simantics.modeling;bundle-version="1.1.1",
+ org.simantics;bundle-version="1.0.0",
+ org.simantics.db.testing;bundle-version="1.0.0",
+ org.simantics.issues.common;bundle-version="1.1.0",
+ org.simantics.layer0.utils;bundle-version="1.1.0",
+ org.simantics.simulation;bundle-version="1.1.0",
+ org.junit;bundle-version="4.12.0"
+Import-Package: org.simantics
+Export-Package: org.simantics.modeling.tests.cases,
+ org.simantics.modeling.tests.commands,
+ org.simantics.modeling.tests.traits
diff --git a/bundles/org.simantics.modeling.tests/build.properties b/bundles/org.simantics.modeling.tests/build.properties
new file mode 100644 (file)
index 0000000..34d2e4d
--- /dev/null
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/cases/ModelingCommandSequenceTest.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/cases/ModelingCommandSequenceTest.java
new file mode 100644 (file)
index 0000000..7b86380
--- /dev/null
@@ -0,0 +1,62 @@
+package org.simantics.modeling.tests.cases;
+
+import org.simantics.db.testing.base.CommandList;
+import org.simantics.db.testing.base.CommandListImpl;
+import org.simantics.db.testing.base.CommandSequenceTest;
+import org.simantics.db.testing.common.Command;
+import org.simantics.db.testing.common.CommandSequenceEnvironment;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.modeling.tests.commands.CollectMemory;
+import org.simantics.modeling.tests.commands.WaitActiveExperiment;
+import org.simantics.modeling.tests.commands.WaitMapping;
+import org.simantics.modeling.tests.commands.WriteHeapDump;
+
+public class ModelingCommandSequenceTest extends CommandSequenceTest {
+
+       protected WaitActiveExperiment waitExperiment = new WaitActiveExperiment();
+       protected WaitMapping waitMapping = new WaitMapping();
+       protected CollectMemory collectMemory = new CollectMemory();
+       protected WriteHeapDump heapDump = new WriteHeapDump(getClass().getSimpleName()+ ".hprof");
+
+       protected DiagramResource DIA;
+
+       @Override
+       protected void initialize(CommandSequenceEnvironment environment) throws Exception {
+               
+               DIA = DiagramResource.getInstance(environment.getSession());
+               
+       }
+       
+       protected void createBeforeSequence(CommandList result) throws Exception {
+       }
+
+       protected void createAfterSequence(CommandList result) throws Exception {
+       }
+
+       protected void createSequence(CommandList result) throws Exception {
+       }
+
+       @Override
+       protected Command[] beforeSequence(CommandSequenceEnvironment environment) throws Exception {
+               CommandListImpl result = new CommandListImpl();
+               createBeforeSequence(result);
+               return result.toArray();
+       }
+
+       
+       @Override
+       protected Command[] newSequence() throws Exception {
+               CommandListImpl result = new CommandListImpl();
+               createSequence(result);
+               return result.toArray();
+       }
+
+
+       @Override
+       protected Command[] afterSequence(CommandSequenceEnvironment environment) throws Exception {
+               CommandListImpl result = new CommandListImpl();
+               createAfterSequence(result);
+               return result.toArray();
+       }
+       
+}
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/ActivateProfile.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/ActivateProfile.java
new file mode 100644 (file)
index 0000000..3ffe5a5
--- /dev/null
@@ -0,0 +1,44 @@
+package org.simantics.modeling.tests.commands;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.simantics.Simantics;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.request.ModelInstances;
+import org.simantics.db.testing.common.CommandSequenceEnvironment;
+import org.simantics.db.testing.common.WriteCommand;
+import org.simantics.diagram.elements.DiagramNodeUtil;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.g2d.canvas.ICanvasContext;
+
+public class ActivateProfile extends WriteCommand<CommandSequenceEnvironment> {
+
+       private LoadDiagram diagram;
+       private String profileName;
+       private Collection<Resource> entries;
+       
+       public ActivateProfile(LoadDiagram diagram, String profileName, Collection<Resource> entries) {
+               this.diagram = diagram;
+               this.profileName = profileName;
+               this.entries = entries;
+       }
+       
+       @Override
+       public void run(CommandSequenceEnvironment environment) throws DatabaseException {
+               
+       ICanvasContext ctx = diagram.getContext();
+
+        Resource runtime = DiagramNodeUtil.getRuntime(ctx);
+        
+        DiagramResource DIA = DiagramResource.getInstance(Simantics.getSession());
+
+        Map<String, Resource> profiles = Simantics.getSession().sync(new ModelInstances(diagram.getResource(), DIA.Profile));
+        Resource profile = profiles.get(profileName);
+
+        DiagramNodeUtil.activateProfileWithEntries(runtime, profile, entries);
+               
+       }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AddDiagram.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AddDiagram.java
new file mode 100644 (file)
index 0000000..021cb46
--- /dev/null
@@ -0,0 +1,42 @@
+package org.simantics.modeling.tests.commands;
+
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.testing.common.CommandSequenceEnvironment;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.modeling.tests.traits.SingleModelTrait;
+import org.simantics.modeling.tests.traits.SingleResourceTrait;
+import org.simantics.simulation.ontology.SimulationResource;
+import org.simantics.structural2.utils.StructuralUtils;
+
+public class AddDiagram extends ResourceWriteCommand<CommandSequenceEnvironment> implements SingleResourceTrait {
+
+       private SingleModelTrait model;
+       private Resource compositeType;
+       private String name;
+       
+       public AddDiagram(SingleModelTrait model, Resource compositeType, String name) {
+               this.model = model;
+               this.compositeType = compositeType;
+               this.name = name;
+       }
+       
+       @Override
+       protected Resource run(WriteGraph graph, CommandSequenceEnvironment environment) throws DatabaseException {
+               
+        SimulationResource SIMU = SimulationResource.getInstance(graph);
+        
+        Resource target = graph.getSingleObject(model.getResource(), SIMU.HasConfiguration);
+
+        Resource composite = StructuralUtils.newComponent(graph, target, name, compositeType);
+        
+               return graph.getSingleObject(composite, ModelingResources.getInstance(graph).CompositeToDiagram);
+               
+       }
+       
+       public String getName() {
+               return name;
+       }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AddModule.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AddModule.java
new file mode 100644 (file)
index 0000000..1bdeb3a
--- /dev/null
@@ -0,0 +1,59 @@
+package org.simantics.modeling.tests.commands;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.utils.OrderedSetUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.diagram.stubs.G2DResource;
+import org.simantics.diagram.synchronization.graph.AddElement;
+import org.simantics.layer0.Layer0;
+import org.simantics.modeling.tests.cases.ModelingCommandSequenceTest;
+import org.simantics.modeling.tests.traits.SingleResourceTrait;
+import org.simantics.modeling.tests.traits.SingleResourceTraitImpl;
+
+
+public class AddModule extends ResourceWriteCommand<ModelingCommandSequenceTest> implements SingleResourceTrait {
+
+       private AddDiagram diagram;
+       private SingleResourceTrait type;
+       private double x,y;
+       
+       public AddModule(AddDiagram diagram, SingleResourceTrait type, double x, double y) {
+               this.diagram = diagram;
+               this.type = type;
+               this.x = x;
+               this.y = y;
+       }
+       
+       public AddModule(AddDiagram diagram, Resource type, double x, double y) {
+               this.diagram = diagram;
+               this.type = new SingleResourceTraitImpl(type);
+               this.x = x;
+               this.y = y;
+       }
+
+       @Override
+       protected Resource run(WriteGraph graph, ModelingCommandSequenceTest environment) throws DatabaseException {
+               
+               Layer0 L0 = Layer0.getInstance(graph);
+        DiagramResource DIA = DiagramResource.getInstance(graph);
+        G2DResource G2D = G2DResource.getInstance(graph);
+               
+               Resource diagramResource = diagram.getResource();
+               
+               // Diagram
+        Resource resource = graph.newResource();
+        graph.claim(resource, L0.InstanceOf, null, type.getResource(graph));
+        graph.claimLiteral(resource, DIA.HasTransform, G2D.Transform, new double[] { 1, 0, 0, 1, x, y }, Bindings.DOUBLE_ARRAY);
+        graph.claim(resource, L0.PartOf, diagramResource);
+
+               AddElement.claimFreshElementName(graph, diagramResource, resource);
+        OrderedSetUtils.addFirst(graph, diagramResource, resource);
+        
+        return resource;
+        
+       }
+       
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertIssueCount.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertIssueCount.java
new file mode 100644 (file)
index 0000000..c88a9cc
--- /dev/null
@@ -0,0 +1,38 @@
+package org.simantics.modeling.tests.commands;
+
+import java.util.Set;
+
+import junit.framework.Assert;
+
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.testing.common.WriteCommand;
+import org.simantics.issues.common.IssuesWithContext;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.modeling.tests.cases.ModelingCommandSequenceTest;
+
+
+public class AssertIssueCount extends WriteCommand<ModelingCommandSequenceTest> {
+
+       private AddModule module;
+       private int expected;
+       
+       public AssertIssueCount(AddModule module, int expected) {
+               this.module = module;
+               this.expected = expected;
+       }
+       
+       @Override
+       protected void run(WriteGraph graph, ModelingCommandSequenceTest environment) throws DatabaseException {
+               
+        Resource element = module.getResource();
+        Resource component = graph.getSingleObject(element, ModelingResources.getInstance(graph).ElementToComponent);
+        Set<Variable> issues = graph.sync(new IssuesWithContext(graph, component));
+
+        Assert.assertEquals(expected, issues.size());
+        
+       }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertMappedComponent.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertMappedComponent.java
new file mode 100644 (file)
index 0000000..a17c2b3
--- /dev/null
@@ -0,0 +1,30 @@
+package org.simantics.modeling.tests.commands;
+
+import junit.framework.Assert;
+
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.testing.common.WriteCommand;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.modeling.tests.cases.ModelingCommandSequenceTest;
+
+
+public class AssertMappedComponent extends WriteCommand<ModelingCommandSequenceTest> {
+
+       private AddModule module;
+       
+       public AssertMappedComponent(AddModule module) {
+               this.module = module;
+       }
+       
+       @Override
+       protected void run(WriteGraph graph, ModelingCommandSequenceTest environment) throws DatabaseException {
+               
+        Resource element = module.getResource();
+        Resource component = graph.getPossibleObject(element, ModelingResources.getInstance(graph).ElementToComponent);
+        Assert.assertNotNull(component);
+        
+       }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertMappedConnection.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertMappedConnection.java
new file mode 100644 (file)
index 0000000..2efb937
--- /dev/null
@@ -0,0 +1,30 @@
+package org.simantics.modeling.tests.commands;
+
+import junit.framework.Assert;
+
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.testing.common.WriteCommand;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.modeling.tests.cases.ModelingCommandSequenceTest;
+
+
+public class AssertMappedConnection extends WriteCommand<ModelingCommandSequenceTest> {
+
+       private Connect connect;
+       
+       public AssertMappedConnection(Connect connect) {
+               this.connect = connect;
+       }
+       
+       @Override
+       protected void run(WriteGraph graph, ModelingCommandSequenceTest environment) throws DatabaseException {
+               
+        Resource element = connect.getResource();
+        Resource component = graph.getPossibleObject(element, ModelingResources.getInstance(graph).ElementToComponent);
+        Assert.assertNotNull(component);
+        
+       }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertMemoryConsumption.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertMemoryConsumption.java
new file mode 100644 (file)
index 0000000..07f3091
--- /dev/null
@@ -0,0 +1,31 @@
+package org.simantics.modeling.tests.commands;
+
+import junit.framework.Assert;
+
+import org.simantics.db.testing.common.WriteCommand;
+import org.simantics.modeling.tests.cases.ModelingCommandSequenceTest;
+
+public class AssertMemoryConsumption extends WriteCommand<ModelingCommandSequenceTest> {
+
+       private int expected;
+       
+       public AssertMemoryConsumption(int expected) {
+               this.expected = expected;
+       }
+
+       @Override
+       public void run(ModelingCommandSequenceTest environment) throws Exception {
+               Assert.assertTrue(getUsedMemory() < expected);
+       }
+       
+       private long getUsedMemory() {
+               
+       System.gc();
+       System.gc();
+       System.gc();
+       Runtime runtime = Runtime.getRuntime();
+       return runtime.totalMemory() - runtime.freeMemory();
+               
+       }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertModelIssueCount.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertModelIssueCount.java
new file mode 100644 (file)
index 0000000..752e990
--- /dev/null
@@ -0,0 +1,33 @@
+package org.simantics.modeling.tests.commands;
+
+import java.util.Set;
+
+import junit.framework.Assert;
+
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.testing.common.WriteCommand;
+import org.simantics.issues.common.AllModelIssues;
+import org.simantics.modeling.tests.cases.ModelingCommandSequenceTest;
+import org.simantics.modeling.tests.traits.SingleModelTrait;
+
+public class AssertModelIssueCount extends WriteCommand<ModelingCommandSequenceTest> {
+
+       private SingleModelTrait model;
+       private int expected;
+       
+       public AssertModelIssueCount(SingleModelTrait model, int expected) {
+               this.model = model;
+               this.expected = expected;
+       }
+       
+       @Override
+       protected void run(WriteGraph graph, ModelingCommandSequenceTest environment) throws DatabaseException {
+               
+               Set<Resource> issues = graph.sync(new AllModelIssues(model.getResource()));
+               Assert.assertEquals(expected, issues.size());
+        
+       }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertStateValue.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertStateValue.java
new file mode 100644 (file)
index 0000000..1fbabdf
--- /dev/null
@@ -0,0 +1,63 @@
+package org.simantics.modeling.tests.commands;
+
+import junit.framework.Assert;
+import junit.framework.AssertionFailedError;
+
+import org.simantics.db.layer0.util.EvaluatingListener;
+import org.simantics.db.layer0.util.EvaluatingListener.Criterion;
+import org.simantics.db.layer0.util.EvaluatingListener.Evaluation;
+import org.simantics.db.testing.common.Command;
+import org.simantics.modeling.tests.cases.ModelingCommandSequenceTest;
+import org.simantics.modeling.tests.traits.SingleResourceTrait;
+
+public class AssertStateValue extends Command<ModelingCommandSequenceTest> {
+
+       
+       private transient final SingleResourceTrait run;
+       private transient final String rvi;
+       private transient final Number expectedValue;
+       private transient final double tolerance;
+       
+       public AssertStateValue(SingleResourceTrait run, String rvi, Number expectedValue, double tolerance) {
+               this.run = run;
+               this.rvi = rvi;
+               this.expectedValue = expectedValue;
+               this.tolerance = tolerance;
+       }
+       
+       public void run(ModelingCommandSequenceTest environment) throws Exception {
+               
+               //final double tolerance = 0.0001;
+               
+               Criterion<Number> criterion = new EvaluatingListener.Criterion<Number>() {
+                       @Override
+                       public Evaluation evaluate(Number result) {
+                               if (result == null){
+                                       return Evaluation.IGNORE;
+                               }
+                               else{
+                                       double resultDouble = result.doubleValue();
+                                       double expectedDouble = expectedValue.doubleValue();
+                                       if (Math.abs(expectedDouble - resultDouble) <= tolerance){
+                                       return Evaluation.ACCEPT;
+                                       }
+                               }
+                               return Evaluation.IGNORE;
+                       }
+
+               };
+               
+               Number result = Utils.readValue(run, rvi, criterion);
+               if (result != null){
+                       double resultDouble = result.doubleValue();
+                       double expectedDouble = expectedValue.doubleValue();
+                       
+                       Assert.assertEquals(expectedDouble, resultDouble, tolerance);
+               }
+               else
+                       throw new AssertionFailedError();
+
+
+       }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/CollectMemory.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/CollectMemory.java
new file mode 100644 (file)
index 0000000..9df02d6
--- /dev/null
@@ -0,0 +1,16 @@
+package org.simantics.modeling.tests.commands;
+
+import org.simantics.Simantics;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.util.SessionGarbageCollection;
+import org.simantics.db.testing.common.CommandSequenceEnvironment;
+import org.simantics.db.testing.common.WriteCommand;
+
+public class CollectMemory extends WriteCommand<CommandSequenceEnvironment> {
+       
+       @Override
+       public void run(CommandSequenceEnvironment environment) throws DatabaseException {
+               SessionGarbageCollection.gc(null, Simantics.getSession(), true, null, 0, 0);
+       }
+       
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/Connect.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/Connect.java
new file mode 100644 (file)
index 0000000..4a5f614
--- /dev/null
@@ -0,0 +1,95 @@
+package org.simantics.modeling.tests.commands;
+
+import java.awt.geom.Point2D;
+import java.util.Arrays;
+import java.util.Collections;
+
+import junit.framework.Assert;
+
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.utils.OrderedSetUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.diagram.content.ConnectionUtil;
+import org.simantics.diagram.query.DiagramRequests;
+import org.simantics.diagram.synchronization.graph.AddElement;
+import org.simantics.layer0.Layer0;
+import org.simantics.modeling.tests.cases.ModelingCommandSequenceTest;
+import org.simantics.modeling.tests.traits.SingleResourceTrait;
+import org.simantics.modeling.tests.traits.SingleResourceTraitImpl;
+import org.simantics.structural.stubs.StructuralResource2;
+import org.simantics.structural2.modelingRules.CPTerminal;
+import org.simantics.structural2.modelingRules.ConnectionJudgement;
+import org.simantics.structural2.modelingRules.IConnectionPoint;
+import org.simantics.structural2.modelingRules.IModelingRules;
+
+
+public class Connect extends ResourceWriteCommand<ModelingCommandSequenceTest> implements SingleResourceTrait {
+
+       private SingleResourceTrait diagram;
+       private SingleResourceTrait m1;
+       private SingleResourceTrait m2;
+       private SingleResourceTrait c1;
+       private SingleResourceTrait c2;
+       
+       public Connect(SingleResourceTrait diagram, SingleResourceTrait m1, SingleResourceTrait c1, SingleResourceTrait m2, SingleResourceTrait c2) {
+               this.diagram = diagram;
+               this.m1 = m1;
+               this.c1 = c1;
+               this.m2 = m2;
+               this.c2 = c2;
+       }
+       
+       public Connect(SingleResourceTrait diagram, SingleResourceTrait m1, SingleResourceTrait c1, SingleResourceTrait m2, Resource c2) {
+               this.diagram = diagram;
+               this.m1 = m1;
+               this.c1 = c1;
+               this.m2 = m2;
+               this.c2 = new SingleResourceTraitImpl(c2);
+       }
+
+       public Connect(SingleResourceTrait diagram, SingleResourceTrait m1, Resource c1, SingleResourceTrait m2, SingleResourceTrait c2) {
+               this.diagram = diagram;
+               this.m1 = m1;
+               this.c1 = new SingleResourceTraitImpl(c1);
+               this.m2 = m2;
+               this.c2 = c2;
+       }
+       
+       public Connect(SingleResourceTrait diagram, SingleResourceTrait m1, Resource c1, SingleResourceTrait m2, Resource c2) {
+               this.diagram = diagram;
+               this.m1 = m1;
+               this.c1 = new SingleResourceTraitImpl(c1);
+               this.m2 = m2;
+               this.c2 = new SingleResourceTraitImpl(c2);
+       }
+
+       @Override
+       protected Resource run(WriteGraph graph, ModelingCommandSequenceTest environment) throws DatabaseException {
+       
+               ConnectionUtil cu = new ConnectionUtil(graph);
+               Resource conn = cu.createConnectionWithCorners(graph, m1.getResource(graph), c1.getResource(graph), m2.getResource(graph), c2.getResource(graph), Collections.<Point2D>emptyList());
+               
+               Layer0 L0 = Layer0.getInstance(graph);
+               StructuralResource2 STR = StructuralResource2.getInstance(graph);
+        graph.claim(conn, L0.PartOf, diagram.getResource());
+
+               AddElement.claimFreshElementName(graph, diagram.getResource(), conn);
+        OrderedSetUtils.addFirst(graph, diagram.getResource(), conn);
+
+        IModelingRules modelingRules = graph.syncRequest(DiagramRequests.getModelingRules(diagram.getResource(), null));
+
+        IConnectionPoint cp1 = new CPTerminal(m1.getResource(graph), c1.getResource(graph));
+        IConnectionPoint cp2 = new CPTerminal(m2.getResource(graph), c2.getResource(graph));
+       
+        ConnectionJudgement judgement = modelingRules.judgeConnection(graph, Arrays.asList(cp1, cp2));
+        
+        Assert.assertNotNull(judgement.connectionType);
+        
+        graph.claim(conn, STR.HasConnectionType, null, judgement.connectionType);
+        
+        return conn;
+        
+       }
+       
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/FailingWrite.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/FailingWrite.java
new file mode 100644 (file)
index 0000000..26e6b45
--- /dev/null
@@ -0,0 +1,23 @@
+package org.simantics.modeling.tests.commands;
+
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.testing.base.AllowedThrowable;
+import org.simantics.db.testing.common.WriteCommand;
+import org.simantics.modeling.tests.cases.ModelingCommandSequenceTest;
+
+
+public class FailingWrite extends WriteCommand<ModelingCommandSequenceTest> {
+
+       class AllowedError extends AssertionError implements AllowedThrowable {
+
+               private static final long serialVersionUID = -2278331008287437312L;
+               
+       }
+       
+       @Override
+       protected void run(WriteGraph graph, ModelingCommandSequenceTest environment) throws DatabaseException {
+               throw new AllowedError();
+       }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/ForAllDiagrams.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/ForAllDiagrams.java
new file mode 100644 (file)
index 0000000..343ad03
--- /dev/null
@@ -0,0 +1,36 @@
+package org.simantics.modeling.tests.commands;
+
+import org.simantics.Simantics;
+import org.simantics.db.testing.common.Command;
+import org.simantics.db.testing.common.CommandInvoker;
+import org.simantics.modeling.requests.CollectionRequest;
+import org.simantics.modeling.requests.CollectionResult;
+import org.simantics.modeling.requests.Node;
+import org.simantics.modeling.tests.cases.ModelingCommandSequenceTest;
+import org.simantics.modeling.tests.traits.SingleModelTrait;
+import org.simantics.modeling.tests.traits.SingleResourceTrait;
+import org.simantics.modeling.tests.traits.SingleResourceTraitImpl;
+import org.simantics.utils.page.PageDesc;
+
+public class ForAllDiagrams extends Command<ModelingCommandSequenceTest> {
+
+       transient private SingleModelTrait model;
+       transient private CommandInvoker<SingleResourceTrait>[] invokers;
+       
+       public ForAllDiagrams(SingleModelTrait model, CommandInvoker<SingleResourceTrait> ... invokers) {
+               this.model = model;
+               this.invokers = invokers;
+       }
+       
+       @Override
+       public void run(ModelingCommandSequenceTest environment) throws Exception {
+       
+               final CollectionResult result = Simantics.getSession().syncRequest(new CollectionRequest(null, PageDesc.DEFAULT, model.getResource()));
+               for(Node diagramNode : result.diagramList) {
+                       for(CommandInvoker<SingleResourceTrait> invoker : invokers)
+                               invoker.invoke(environment, new SingleResourceTraitImpl(diagramNode.getDiagramResource()));
+               }
+               
+       }
+
+}
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/LoadDiagram.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/LoadDiagram.java
new file mode 100644 (file)
index 0000000..2884c40
--- /dev/null
@@ -0,0 +1,99 @@
+package org.simantics.modeling.tests.commands;
+
+import org.simantics.Simantics;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.request.Model;
+import org.simantics.db.testing.common.CommandSequenceEnvironment;
+import org.simantics.diagram.elements.DiagramNodeUtil;
+import org.simantics.g2d.canvas.impl.CanvasContext;
+import org.simantics.g2d.diagram.DiagramHints;
+import org.simantics.g2d.diagram.IDiagram;
+import org.simantics.g2d.scenegraph.ICanvasSceneGraphProvider;
+import org.simantics.layer0.Layer0;
+import org.simantics.layer0.utils.triggers.IActivation;
+import org.simantics.layer0.utils.triggers.IActivationManager;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.modeling.tests.traits.SingleResourceTrait;
+import org.simantics.modeling.tests.traits.SingleResourceTraitImpl;
+import org.simantics.utils.threads.WorkerThread;
+
+public class LoadDiagram extends ResourceWriteCommand<CommandSequenceEnvironment> implements SingleResourceTrait {
+    private static final boolean DEBUG = true;
+       private SingleResourceTrait diagram;
+
+       transient private ICanvasSceneGraphProvider provider;
+       transient private CanvasContext ctx;
+       transient private IActivation activation;
+       transient private WorkerThread workerThread;
+       
+       public LoadDiagram(SingleResourceTrait diagram) {
+               this.diagram = diagram;
+       }
+       
+       public LoadDiagram(Resource diagram) {
+               this(new SingleResourceTraitImpl(diagram));
+       }
+       
+       @Override
+       public Resource runResource(CommandSequenceEnvironment environment) throws DatabaseException {
+               
+        try {
+               
+               Resource model = Simantics.sync(new Model(diagram.getResource()));
+               String diagramName = Simantics.sync(new ResourceRead<String>(diagram.getResource()) {
+
+                               @Override
+                               public String perform(ReadGraph graph) throws DatabaseException {
+                                       Layer0 L0 = Layer0.getInstance(graph);
+                                       ModelingResources MOD = ModelingResources.getInstance(graph);
+                                       Resource composite = graph.getPossibleObject(resource, MOD.DiagramToComposite);
+                                       return graph.getPossibleRelatedValue(composite, L0.HasName, Bindings.STRING);
+                               }
+                       
+               });
+               if (DEBUG)
+                   System.out.println("DEBUG: load " + diagramName);
+            workerThread = new WorkerThread("Load diagram");
+            workerThread.start();
+               // Load diagram
+            ctx = new CanvasContext(workerThread);
+                       provider = DiagramNodeUtil.loadSceneGraphProvider(ctx, model, diagram.getResource(), "/" + diagramName);
+                       // Activate mapping
+               IActivationManager activationManager = Simantics.getSession().peekService(IActivationManager.class);
+               if (activationManager != null) {
+                   activation = activationManager.activate(diagram.getResource());
+               }
+
+               } catch (InterruptedException e) {
+                       throw new DatabaseException(e);
+               }
+        
+        return diagram.getResource();
+        
+       }
+       
+       public ICanvasSceneGraphProvider getProvider() {
+               return provider;
+       }
+       
+       public IActivation getActivation() {
+               return activation;
+       }
+       
+       public CanvasContext getContext() {
+               return ctx;
+       }
+       
+       public WorkerThread getWorkerThread() {
+               return workerThread;
+       }
+       
+       public IDiagram getDiagram() {
+               return ctx.getDefaultHintContext().getHint(DiagramHints.KEY_DIAGRAM);
+       }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/MergeFlags.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/MergeFlags.java
new file mode 100644 (file)
index 0000000..92c98e3
--- /dev/null
@@ -0,0 +1,52 @@
+package org.simantics.modeling.tests.commands;
+
+import java.util.ArrayList;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.testing.common.CommandSequenceEnvironment;
+import org.simantics.db.testing.common.WriteCommand;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.modeling.tests.traits.SingleResourceTrait;
+import org.simantics.modeling.tests.traits.SingleResourceTraitImpl;
+import org.simantics.structural.stubs.StructuralResource2;
+
+public class MergeFlags extends WriteCommand<CommandSequenceEnvironment> {
+
+       private SingleResourceTrait diagram;
+       
+       public MergeFlags(SingleResourceTrait diagram) {
+               this.diagram = diagram;
+       }
+       
+       public MergeFlags(Resource diagram) {
+               this(new SingleResourceTraitImpl(diagram));
+       }
+
+       public Resource getComposite(ReadGraph graph) throws DatabaseException {
+               DiagramResource DIA = DiagramResource.getInstance(graph);
+               ModelingResources MOD = ModelingResources.getInstance(graph);
+               StructuralResource2 STR = StructuralResource2.getInstance(graph);
+               Resource resource = diagram.getResource();
+               if(graph.isInstanceOf(resource, DIA.Diagram)) return graph.getSingleObject(resource, MOD.DiagramToComposite);
+               else if (graph.isInstanceOf(resource, STR.Composite)) return resource;
+               else throw new DatabaseException("Expected diagram or composite, got " + NameUtils.getSafeName(graph, resource));
+       }
+       
+       @Override
+       protected void run(WriteGraph graph, CommandSequenceEnvironment environment) throws DatabaseException {
+               
+               System.err.println("Merging flags in: " + NameUtils.getSafeName(graph, getComposite(graph)));
+       ArrayList<ArrayList<Resource>> groups = new ArrayList<ArrayList<Resource>>();
+       org.simantics.modeling.flags.MergeFlags.collectFlagGroupsInComposite(graph, getComposite(graph), groups);
+        for(ArrayList<Resource> group : groups) {
+               org.simantics.modeling.flags.MergeFlags.merge(graph, group);
+        }
+        
+       }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/MergeFlagsInvoker.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/MergeFlagsInvoker.java
new file mode 100644 (file)
index 0000000..648e23a
--- /dev/null
@@ -0,0 +1,14 @@
+package org.simantics.modeling.tests.commands;
+
+import org.simantics.db.testing.common.CommandInvoker;
+import org.simantics.db.testing.common.CommandSequenceEnvironment;
+import org.simantics.modeling.tests.traits.SingleResourceTrait;
+
+public class MergeFlagsInvoker implements CommandInvoker<SingleResourceTrait> {
+
+       @Override
+       public void invoke(CommandSequenceEnvironment environment, SingleResourceTrait parameter) throws Exception {
+               environment.invoke(environment, new MergeFlags(parameter.getResource()));
+       }
+
+}
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/ModificationEvents.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/ModificationEvents.java
new file mode 100644 (file)
index 0000000..7494523
--- /dev/null
@@ -0,0 +1,34 @@
+package org.simantics.modeling.tests.commands;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.DevelopmentKeys;
+import org.simantics.db.testing.common.CommandSequenceEnvironment;
+import org.simantics.db.testing.common.WriteCommand;
+import org.simantics.utils.Development;
+
+public class ModificationEvents extends WriteCommand<CommandSequenceEnvironment> {
+
+       transient private boolean enable;
+       
+       public ModificationEvents(boolean enable) {
+               this.enable = enable;
+       }
+       
+       @Override
+       public void run(CommandSequenceEnvironment environment) throws Exception {
+
+               if(enable) {
+                       Development.setProperty(DevelopmentKeys.WRITEGRAPH_DEBUG, true, Bindings.BOOLEAN);
+                       Development.setProperty(DevelopmentKeys.WRITEGRAPH_DEBUG_NAMES, true, Bindings.BOOLEAN);
+                       Development.setProperty(DevelopmentKeys.PRINT, false, Bindings.BOOLEAN);
+                       Development.setProperty(DevelopmentKeys.LOGGER_ECHO, false, Bindings.BOOLEAN);
+               } else {
+                       Development.setProperty(DevelopmentKeys.WRITEGRAPH_DEBUG, false, Bindings.BOOLEAN);
+                       Development.setProperty(DevelopmentKeys.WRITEGRAPH_DEBUG_NAMES, false, Bindings.BOOLEAN);
+                       Development.setProperty(DevelopmentKeys.PRINT, true, Bindings.BOOLEAN);
+                       Development.setProperty(DevelopmentKeys.LOGGER_ECHO, true, Bindings.BOOLEAN);
+               }
+               
+       }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/OpenAndCloseDiagram.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/OpenAndCloseDiagram.java
new file mode 100644 (file)
index 0000000..901cea8
--- /dev/null
@@ -0,0 +1,20 @@
+package org.simantics.modeling.tests.commands;
+
+import org.simantics.db.testing.common.CommandInvoker;
+import org.simantics.db.testing.common.CommandSequenceEnvironment;
+import org.simantics.modeling.tests.traits.SingleResourceTrait;
+
+public class OpenAndCloseDiagram implements CommandInvoker<SingleResourceTrait> {
+
+       @Override
+       public void invoke(CommandSequenceEnvironment environment, SingleResourceTrait parameter) throws Exception {
+               
+               LoadDiagram load = new LoadDiagram(parameter.getResource());
+               UnloadDiagram unload = new UnloadDiagram(load);
+               environment.invoke(environment, load);
+               environment.invoke(environment, unload);
+               environment.invoke(environment, new CollectMemory());
+               
+       }
+
+}
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/PrintListeners.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/PrintListeners.java
new file mode 100644 (file)
index 0000000..4476a14
--- /dev/null
@@ -0,0 +1,26 @@
+package org.simantics.modeling.tests.commands;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+import org.simantics.db.debug.ListenerReport;
+import org.simantics.db.service.DebugSupport;
+import org.simantics.db.testing.common.CommandSequenceEnvironment;
+import org.simantics.db.testing.common.WriteCommand;
+
+public class PrintListeners extends WriteCommand<CommandSequenceEnvironment> {
+
+       @Override
+       public void run(CommandSequenceEnvironment environment) throws Exception {
+
+               DebugSupport ds = environment.getSession().getService(DebugSupport.class);
+               ListenerReport report = ds.query(environment.getSession(), "get listeners");
+               
+               ByteArrayOutputStream bo = new ByteArrayOutputStream();
+               PrintStream ps = new PrintStream(bo);
+               report.print(ps);
+               System.err.println("listeners: " + bo.toString());
+               
+       }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/ResourceWriteCommand.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/ResourceWriteCommand.java
new file mode 100644 (file)
index 0000000..bc21a31
--- /dev/null
@@ -0,0 +1,68 @@
+package org.simantics.modeling.tests.commands;
+
+import org.simantics.Simantics;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteResultRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.testing.common.Command;
+import org.simantics.db.testing.common.CommandSequenceEnvironment;
+import org.simantics.modeling.tests.traits.SingleResourceTrait;
+import org.simantics.modeling.tests.traits.UriResourceTrait;
+
+abstract public class ResourceWriteCommand<T extends CommandSequenceEnvironment> extends Command<T> implements SingleResourceTrait {
+
+       private Resource resource;
+       
+       @Override
+       final public void run(final T environment) throws Exception {
+               resource = runResource(environment); 
+               afterRun(environment);
+       }
+       
+       public Resource runResource(final T environment) throws Exception {
+               return Simantics.getSession().sync(new WriteResultRequest() {
+
+                       @Override
+                       public Resource perform(WriteGraph graph) throws DatabaseException {
+                               return ResourceWriteCommand.this.run(graph, environment);
+                       }
+                       
+                       @Override
+                       public String toString() {
+                               return ResourceWriteCommand.this.toString();
+                       }
+                       
+               });
+       }
+       
+       protected Resource run(WriteGraph graph, T environment) throws DatabaseException {
+               throw new IllegalStateException();
+       }
+       
+       protected void afterRun(T environment) throws Exception {
+               
+       }
+
+       @Override
+       public String toString() {
+               return "ResourceWriteCommand " + getClass().getSimpleName();
+       }
+       
+       @Override
+       public Resource getResource() throws DatabaseException {
+               return resource;
+       }
+       
+       @Override
+       public Resource getResource(ReadGraph graph) throws DatabaseException {
+               return resource;
+       }
+       
+       @Override
+       public SingleResourceTrait child(String path) {
+               return new UriResourceTrait(this, path);
+       }
+       
+}
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/RunAllBatchValidations.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/RunAllBatchValidations.java
new file mode 100644 (file)
index 0000000..6f7b60d
--- /dev/null
@@ -0,0 +1,23 @@
+package org.simantics.modeling.tests.commands;
+
+import org.simantics.db.testing.common.Command;
+import org.simantics.modeling.tests.cases.ModelingCommandSequenceTest;
+import org.simantics.modeling.tests.traits.SingleModelTrait;
+import org.simantics.modeling.utils.BatchValidations;
+
+public class RunAllBatchValidations extends Command<ModelingCommandSequenceTest> {
+
+       transient private SingleModelTrait model; 
+       
+       public RunAllBatchValidations(SingleModelTrait model) {
+               this.model = model;
+       }
+       
+       @Override
+       public void run(ModelingCommandSequenceTest environment) throws Exception {
+               
+        BatchValidations.runAll(null, model.getResource());
+               
+       }
+
+}
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/SetDevelopmentProperty.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/SetDevelopmentProperty.java
new file mode 100644 (file)
index 0000000..aa117f1
--- /dev/null
@@ -0,0 +1,27 @@
+package org.simantics.modeling.tests.commands;
+
+import org.simantics.databoard.binding.Binding;
+import org.simantics.db.testing.common.CommandSequenceEnvironment;
+import org.simantics.db.testing.common.WriteCommand;
+import org.simantics.utils.Development;
+
+public class SetDevelopmentProperty extends WriteCommand<CommandSequenceEnvironment> {
+
+       transient private String key;
+       transient private Object value;
+       transient private Binding binding;
+       
+       public SetDevelopmentProperty(String key, Object value, Binding binding) {
+               this.key = key;
+               this.value = value;
+               this.binding = binding;
+       }
+       
+       @Override
+       public void run(CommandSequenceEnvironment environment) throws Exception {
+
+               Development.setProperty(key, value, binding);
+               
+       }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/UnloadDiagram.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/UnloadDiagram.java
new file mode 100644 (file)
index 0000000..791a84e
--- /dev/null
@@ -0,0 +1,25 @@
+package org.simantics.modeling.tests.commands;
+
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.testing.common.CommandSequenceEnvironment;
+import org.simantics.db.testing.common.WriteCommand;
+
+public class UnloadDiagram extends WriteCommand<CommandSequenceEnvironment> {
+
+       private LoadDiagram diagram;
+       
+       public UnloadDiagram(LoadDiagram diagram) {
+               this.diagram = diagram;
+       }
+       
+       @Override
+       public void run(CommandSequenceEnvironment environment) throws DatabaseException {
+               
+               diagram.getProvider().dispose();
+               diagram.getContext().dispose();
+               diagram.getActivation().deactivate();
+               diagram.getWorkerThread().stopDispatchingEvents(true);
+               
+       }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/Utils.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/Utils.java
new file mode 100644 (file)
index 0000000..29046cf
--- /dev/null
@@ -0,0 +1,105 @@
+package org.simantics.modeling.tests.commands;
+
+import java.util.concurrent.TimeUnit;
+
+import org.simantics.Simantics;
+import org.simantics.databoard.binding.Binding;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.ReadRequest;
+import org.simantics.db.common.request.UniqueRead;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.util.EvaluatingListener;
+import org.simantics.db.layer0.util.EvaluatingListener.Criterion;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.layer0.variable.Variables;
+import org.simantics.modeling.tests.traits.SingleResourceTrait;
+
+
+
+public class Utils {
+
+
+       public static void waitMapping() throws DatabaseException {
+               
+               sync();
+               
+       }
+
+       public static void sync() throws DatabaseException {
+
+       // Multiple bugs here:
+       // -Model performs activation in separate write transactions because API does not support changing the virtual graph
+       //  => activation & activation listener is delayed beyond this point
+       // -This should be fixed by the following code 
+        //     TransactionSupport ts = session.getService(TransactionSupport.class);
+       //     ts.waitCompletion();
+       //  but unfortunately this does not work either...
+       // so we synchronize by a familiar write transaction
+
+               
+        // And then wait still some more
+               for(int i=0;i<3;i++) {
+              Simantics.getSession().syncRequest(new WriteRequest() {
+                   
+                   @Override
+                   public void perform(WriteGraph graph) throws DatabaseException {
+                       
+                   }
+                       
+                       @Override
+                       public String toString() {
+                               return "Utils sync";
+                       }
+                   
+              });
+              
+              // And then wait still some more
+              Simantics.getSession().syncRequest(new ReadRequest() {
+                  
+                  @Override
+                  public void run(ReadGraph graph) throws DatabaseException {
+                      
+                  }
+                  
+             });
+               }
+       
+    }
+       
+       public static void writeConfiguration(final Resource model, final String rvi, final Object value, final Binding binding) throws DatabaseException {
+           
+           class WriteConfiguration extends WriteRequest {
+
+                       @Override
+                       public void perform(WriteGraph graph) throws DatabaseException {
+                   Variable state = Variables.getVariable(graph, graph.getURI(model) + rvi);
+                   state.setValue(graph, value, binding);
+                       }
+               
+           }
+           
+           Simantics.getSession().syncRequest(new WriteConfiguration());
+           
+       }
+       
+       public static <T>T readValue(final SingleResourceTrait run, final String rvi, final Criterion<T> criterion) throws DatabaseException, InterruptedException {
+
+               return EvaluatingListener.<T>trySyncRequest(Simantics.getSession(), 
+                               new UniqueRead<T>(){
+                                       @SuppressWarnings("unchecked")
+                                       @Override
+                                       public T perform(ReadGraph graph) throws DatabaseException{
+                                               Variable state = Variables.getPossibleVariable(graph, graph.getURI(run.getResource(graph)) + rvi);
+                                               return (T) (state != null ? state.getValue(graph) : null);
+                                       }
+                                       
+                               }, 
+                               criterion,
+                               15, TimeUnit.SECONDS);
+       }
+
+}
+
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/WaitActiveExperiment.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/WaitActiveExperiment.java
new file mode 100644 (file)
index 0000000..efb2faf
--- /dev/null
@@ -0,0 +1,50 @@
+package org.simantics.modeling.tests.commands;
+
+import org.simantics.Simantics;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.testing.base.CommandSequenceTest;
+import org.simantics.db.testing.common.WriteCommand;
+import org.simantics.project.IProject;
+import org.simantics.simulation.experiment.IExperiment;
+import org.simantics.simulation.project.IExperimentManager;
+import org.simantics.simulation.project.IExperimentManagerListener;
+
+public class WaitActiveExperiment extends WriteCommand<CommandSequenceTest> implements IExperimentManagerListener {
+
+       boolean done = false;
+       
+       @Override
+       public void run(CommandSequenceTest environment) throws DatabaseException {
+               try {
+                       IProject project = Simantics.getProject(); 
+            final IExperimentManager experimentManager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
+            if (experimentManager != null) {
+               IExperiment experiment = experimentManager.getActiveExperiment();
+               if(experiment == null) {
+                       experimentManager.addListener(this);
+                       while(!done) {
+                               Thread.sleep(50);
+                       }
+                       // Cannot because of bean comparison
+                       //experimentManager.removeListener(this);
+               }
+            }
+               } catch (Exception e) {
+                       throw new DatabaseException(e);
+               }
+       }
+
+       @Override
+       public void activeExperimentLoaded(IExperiment experiment) {
+               done = true;
+       }
+
+       @Override
+       public void activeExperimentUnloaded() {
+       }
+
+       @Override
+       public void managerDisposed() {
+       }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/WaitMapping.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/WaitMapping.java
new file mode 100644 (file)
index 0000000..768fc4e
--- /dev/null
@@ -0,0 +1,14 @@
+package org.simantics.modeling.tests.commands;
+
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.testing.common.WriteCommand;
+import org.simantics.modeling.tests.cases.ModelingCommandSequenceTest;
+
+public class WaitMapping extends WriteCommand<ModelingCommandSequenceTest> {
+       
+       @Override
+       public void run(ModelingCommandSequenceTest environment) throws DatabaseException {
+               Utils.waitMapping();
+       }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/WriteConfiguration.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/WriteConfiguration.java
new file mode 100644 (file)
index 0000000..21249ad
--- /dev/null
@@ -0,0 +1,30 @@
+package org.simantics.modeling.tests.commands;
+
+import org.simantics.databoard.binding.Binding;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.testing.common.CommandSequenceEnvironment;
+import org.simantics.db.testing.common.WriteCommand;
+import org.simantics.modeling.tests.traits.SingleResourceTrait;
+
+public class WriteConfiguration extends WriteCommand<CommandSequenceEnvironment> {
+
+       transient public SingleResourceTrait model;
+       transient public String rvi;
+       transient public Object value;
+       transient public Binding binding;
+       
+       public WriteConfiguration(SingleResourceTrait model, String rvi, Object value, Binding binding) {
+               this.model = model;
+               this.rvi = rvi;
+               this.value = value;
+               this.binding = binding;
+       }
+       
+       @Override
+       public void run(CommandSequenceEnvironment environment) throws DatabaseException {
+                               
+               Utils.writeConfiguration(model.getResource(), rvi, value, binding);
+               
+       }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/WriteHeapDump.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/WriteHeapDump.java
new file mode 100644 (file)
index 0000000..18ab13a
--- /dev/null
@@ -0,0 +1,69 @@
+package org.simantics.modeling.tests.commands;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.simantics.db.testing.common.CommandSequenceEnvironment;
+import org.simantics.db.testing.common.WriteCommand;
+
+public class WriteHeapDump extends WriteCommand<CommandSequenceEnvironment> {
+
+       private String fileName;
+       
+       public WriteHeapDump(String fileName) {
+               this.fileName = fileName;
+       }
+       
+       @Override
+       public void run(CommandSequenceEnvironment environment) throws Exception {
+               
+               final File dumpFile = new File(fileName);
+               if (dumpFile.exists() && !dumpFile.delete()) {
+                       return;
+               }
+               try {
+                       Object bean = getBean();
+                       if (bean == null)
+                               return;
+
+                       Method m = bean.getClass().getMethod("dumpHeap", String.class, boolean.class);
+                       m.invoke(bean, dumpFile.getAbsolutePath(), true);
+               } catch (IllegalArgumentException e) {
+                       throw new InvocationTargetException(e);
+               } catch (IllegalAccessException e) {
+                       throw new InvocationTargetException(e);
+               } catch (SecurityException e) {
+                       throw new InvocationTargetException(e);
+               } catch (NoSuchMethodException e) {
+                       throw new InvocationTargetException(e);
+               }
+               
+       }
+
+    private static Object getBean() {
+        Class<?> beanClass = getBeanClass();
+        if (beanClass == null)
+            return null;
+        try {
+            Object bean = ManagementFactory.newPlatformMXBeanProxy(
+                    ManagementFactory.getPlatformMBeanServer(),
+                    "com.sun.management:type=HotSpotDiagnostic",
+                    beanClass);
+            return bean;
+        } catch (IOException e) {
+            return null;
+        }
+    }
+
+    private static Class<?> getBeanClass() {
+        try {
+            Class<?> clazz = Class.forName("com.sun.management.HotSpotDiagnosticMXBean");
+            return clazz;
+        } catch (ClassNotFoundException e) {
+            return null;
+        }
+    }  
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/WriteState.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/WriteState.java
new file mode 100644 (file)
index 0000000..3924c44
--- /dev/null
@@ -0,0 +1,86 @@
+package org.simantics.modeling.tests.commands;
+
+import org.simantics.databoard.binding.Binding;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.CommentMetadata;
+import org.simantics.db.common.request.WriteResultRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.request.PossibleURIVariable;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.testing.common.CommandSequenceEnvironment;
+import org.simantics.db.testing.common.WriteCommand;
+import org.simantics.diagram.adapter.DisposableListener;
+import org.simantics.diagram.adapter.DisposableListenerAdapter;
+import org.simantics.modeling.tests.traits.SingleResourceTrait;
+
+public class WriteState extends WriteCommand<CommandSequenceEnvironment> {
+       
+       private static final long TIMEOUT = 5000000000L;
+       
+       transient public SingleResourceTrait run;
+       transient public String rvi;
+       transient public Object value;
+       transient public Binding binding;
+       
+       public WriteState(SingleResourceTrait run, String rvi, Object value, Binding binding) {
+               this.run = run;
+               this.rvi = rvi;
+               this.value = value;
+               this.binding = binding;
+       }
+       
+       @Override
+       public void run(CommandSequenceEnvironment environment) throws DatabaseException {
+
+               long start = System.nanoTime();
+               long current = System.nanoTime();
+               
+               final DisposableListener<Variable> listener = new DisposableListenerAdapter<Variable>();
+
+               try {
+
+                       while((current-start) < TIMEOUT) {
+
+                               boolean success = environment.getSession().sync(new WriteResultRequest<Boolean>() {
+
+                                       @Override
+                                       public Boolean perform(WriteGraph graph) throws DatabaseException {
+
+                                               Variable state = graph.syncRequest(new PossibleURIVariable(graph.getURI(run.getResource(graph)) + rvi), listener);
+                                               if(state == null) return false;
+
+                                               state.setValue(graph, value, binding);
+
+                                               CommentMetadata cm = graph.getMetadata(CommentMetadata.class);
+                                               // Add comment to change set.
+                                               graph.addMetadata(cm.add("Set value"));
+
+                                               return true;
+
+                                       }
+
+                               });
+
+                               if(success) return;
+
+                               try {
+                                       Thread.sleep(1);
+                               } catch (InterruptedException e1) {
+                                       throw new DatabaseException(e1);
+                               }
+
+                               current = System.nanoTime();
+
+                       }
+
+                       throw new DatabaseException("Timeout writing " + rvi);
+                       
+               } finally {
+
+                       listener.disposeListener();
+
+               }
+               
+       }
+
+}
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/AbstractSingleResourceTrait.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/AbstractSingleResourceTrait.java
new file mode 100644 (file)
index 0000000..1f3b446
--- /dev/null
@@ -0,0 +1,28 @@
+package org.simantics.modeling.tests.traits;
+
+import org.simantics.Simantics;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.UniqueRead;
+import org.simantics.db.exception.DatabaseException;
+
+abstract public class AbstractSingleResourceTrait implements SingleResourceTrait {
+       
+       @Override
+       public Resource getResource() throws DatabaseException {
+               return Simantics.sync(new UniqueRead<Resource>() {
+
+                       @Override
+                       public Resource perform(ReadGraph graph) throws DatabaseException {
+                               return getResource(graph);
+                       }
+                       
+               });
+       }
+       
+       @Override
+       public SingleResourceTrait child(String path) {
+               return new UriResourceTrait(this, path);
+       }
+       
+}
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/ActiveExperimentRunTrait.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/ActiveExperimentRunTrait.java
new file mode 100644 (file)
index 0000000..9daf11e
--- /dev/null
@@ -0,0 +1,21 @@
+package org.simantics.modeling.tests.traits;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.request.PossibleActiveExperiment;
+
+public class ActiveExperimentRunTrait extends AbstractSingleResourceTrait {
+       
+       public SingleResourceTrait model;
+       
+       public ActiveExperimentRunTrait(SingleResourceTrait model) {
+               this.model = model;
+       }
+       
+       @Override
+       public Resource getResource(ReadGraph graph) throws DatabaseException {
+               return graph.sync(new PossibleActiveExperiment(model.getResource()));
+       }
+       
+}
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/DiagramElementTrait.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/DiagramElementTrait.java
new file mode 100644 (file)
index 0000000..134572a
--- /dev/null
@@ -0,0 +1,29 @@
+package org.simantics.modeling.tests.traits;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.uri.UnescapedChildMapOfResource;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.modeling.ModelingResources;
+
+public class DiagramElementTrait extends AbstractSingleResourceTrait {
+       
+       public SingleResourceTrait diagram;
+       public String name;
+       
+       public DiagramElementTrait(SingleResourceTrait diagram, String name) {
+               this.diagram = diagram;
+               this.name = name;
+       }
+       
+       @Override
+       public Resource getResource(ReadGraph graph) throws DatabaseException {
+               ModelingResources MOD = ModelingResources.getInstance(graph);
+               Resource composite = graph.getSingleObject(diagram.getResource(), MOD.DiagramToComposite);
+               Resource child = graph.sync(new UnescapedChildMapOfResource(composite)).get(name);
+               if(child == null) throw new DatabaseException("No child " + child + " for " + NameUtils.getSafeName(graph, composite));
+               return graph.getSingleObject(child, MOD.ComponentToElement);
+       }
+       
+}
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/SingleModelTrait.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/SingleModelTrait.java
new file mode 100644 (file)
index 0000000..1ae9a35
--- /dev/null
@@ -0,0 +1,6 @@
+package org.simantics.modeling.tests.traits;
+
+
+public interface SingleModelTrait extends SingleResourceTrait {
+       
+}
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/SingleResourceTrait.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/SingleResourceTrait.java
new file mode 100644 (file)
index 0000000..f35cfd1
--- /dev/null
@@ -0,0 +1,14 @@
+package org.simantics.modeling.tests.traits;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+
+public interface SingleResourceTrait {
+
+       Resource getResource() throws DatabaseException;
+       Resource getResource(ReadGraph graph) throws DatabaseException;
+       
+       SingleResourceTrait child(String path);
+       
+}
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/SingleResourceTraitImpl.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/SingleResourceTraitImpl.java
new file mode 100644 (file)
index 0000000..6deed91
--- /dev/null
@@ -0,0 +1,25 @@
+package org.simantics.modeling.tests.traits;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+
+public class SingleResourceTraitImpl extends AbstractSingleResourceTrait {
+
+       private Resource resource;
+       
+       public SingleResourceTraitImpl(Resource resource) {
+               this.resource = resource;
+       }
+       
+       @Override
+       public Resource getResource() {
+               return resource;
+       }
+       
+       @Override
+       public Resource getResource(ReadGraph graph) throws DatabaseException {
+               return resource;
+       }
+       
+}
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/UriResourceTrait.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/traits/UriResourceTrait.java
new file mode 100644 (file)
index 0000000..d5b2097
--- /dev/null
@@ -0,0 +1,22 @@
+package org.simantics.modeling.tests.traits;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+
+public class UriResourceTrait extends AbstractSingleResourceTrait {
+       
+       public SingleResourceTrait base;
+       public String suffix;
+       
+       public UriResourceTrait(SingleResourceTrait base, String suffix) {
+               this.base = base;
+               this.suffix = suffix;
+       }
+       
+       @Override
+       public Resource getResource(ReadGraph graph) throws DatabaseException {
+               return graph.getResource(graph.getURI(base.getResource()) + suffix);
+       }
+       
+}