]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsBug3114Test.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / regression / bugs / SimanticsBug3114Test.java
diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsBug3114Test.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsBug3114Test.java
new file mode 100644 (file)
index 0000000..c400952
--- /dev/null
@@ -0,0 +1,71 @@
+package org.simantics.db.tests.regression.bugs;
+
+import org.junit.Test;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.WriteOnlyGraph;
+import org.simantics.db.common.request.UniqueRead;
+import org.simantics.db.common.request.WriteOnlyRequest;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.event.ChangeEvent;
+import org.simantics.db.event.ChangeListener;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.service.GraphChangeListenerSupport;
+import org.simantics.db.service.VirtualGraphSupport;
+import org.simantics.db.testing.base.ExistingDatabaseTest;
+
+public class SimanticsBug3114Test extends ExistingDatabaseTest {
+
+       private Resource newResource;
+       
+    @Test
+    public void test() throws Exception {
+       
+       Session session = getSession();
+       GraphChangeListenerSupport support = session.getService(GraphChangeListenerSupport.class);
+
+       // This listener writes 2 versions of a functional property into the same resource. The resulting model is broken if queries are not updated correctly.
+       support.addMetadataListener(new ChangeListener() {
+
+                       @Override
+                       public void graphChanged(ChangeEvent e) throws DatabaseException {
+                               WriteGraph graph = (WriteGraph)e.getGraph();
+                       graph.sync(new WriteRequest(graph.getService(VirtualGraphSupport.class).getMemoryPersistent("mem")) {
+
+                                       @Override
+                                       public void perform(WriteGraph graph) throws DatabaseException {
+                                               graph.claimLiteral(newResource, L0.HasName, "name", Bindings.STRING);
+                                               graph.claimLiteral(newResource, L0.HasName, "name2", Bindings.STRING);
+                                       }
+
+                               });             
+                               
+                       }
+                       
+               });
+
+       // Perform host request as write only.
+       session.sync(new WriteOnlyRequest() {
+                       
+                       @Override
+                       public void perform(WriteOnlyGraph graph) throws DatabaseException {
+                               newResource = graph.newResource();
+                               graph.claim(newResource, L0.InstanceOf, null, L0.Entity);
+                       }
+                       
+               });
+       
+       // Ensure correct results
+        assertEquals("name2", getSession().sync(new UniqueRead<String>() {
+            @Override
+            public String perform(ReadGraph graph) throws DatabaseException {
+               return graph.getRelatedValue(newResource, L0.HasName, Bindings.STRING);
+            }
+        }));
+        
+    }
+
+}