]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterBuilder/WriteOrderTest.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / support / clusterBuilder / WriteOrderTest.java
diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterBuilder/WriteOrderTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterBuilder/WriteOrderTest.java
new file mode 100644 (file)
index 0000000..3cb6fae
--- /dev/null
@@ -0,0 +1,122 @@
+package org.simantics.db.tests.api.support.clusterBuilder;
+
+import org.junit.Test;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.WriteOnlyGraph;
+import org.simantics.db.common.request.WriteOnlyResultRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.request.Read;
+import org.simantics.db.service.ClusterBuilder;
+import org.simantics.db.service.SerialisationSupport;
+import org.simantics.db.service.ClusterBuilder.ResourceHandle;
+import org.simantics.db.service.ClusterBuilder.StatementHandle;
+import org.simantics.db.testing.annotation.Fails;
+import org.simantics.db.testing.base.ExistingDatabaseTest;
+import org.simantics.layer0.Layer0;
+
+public class WriteOrderTest extends ExistingDatabaseTest {
+    
+    @Test
+    @Fails
+    public void test() throws DatabaseException {
+        
+       Session session = getSession();
+       
+        final Layer0 b = Layer0.getInstance(session);
+       
+        final Resource res = session.syncRequest(new WriteOnlyResultRequest<Resource>() {
+
+                       @Override
+                       public Resource perform(WriteOnlyGraph graph) throws DatabaseException {
+                               
+                               ClusterBuilder builder = graph.getService(ClusterBuilder.class);
+                               SerialisationSupport ss = graph.getService(SerialisationSupport.class);
+                               
+                               ResourceHandle hasNameR = builder.resource(b.HasName);
+                               ResourceHandle nameOfR = builder.resource(b.NameOf);
+                               if (DEBUG)
+                                   System.out.println("Name of resource is " + nameOfR);
+                               ResourceHandle instanceOfR = builder.resource(b.InstanceOf);
+                               ResourceHandle libraryR = builder.resource(b.Library);
+                               ResourceHandle stringR = builder.resource(b.String);
+                               ResourceHandle consistsOf = builder.resource(b.ConsistsOf);
+                if (DEBUG)
+                    System.out.println("ConsistsOf resource is " + consistsOf);
+                               ResourceHandle partOf = builder.resource(b.PartOf);
+                               
+                               StatementHandle instanceOf = builder.newStatement(instanceOfR, libraryR);
+                               StatementHandle instanceOfString = builder.newStatement(instanceOfR, stringR);
+                if (DEBUG)
+                    System.out.println("Instance of string is " + instanceOfString);
+                               
+//                             ResourceHandle root = builder.newResource();
+//                             root.addStatement(instanceOf);
+//                             
+//                             ResourceHandle rootLiteral = builder.newResource();
+//                             rootLiteral.addStatement(instanceOfString);
+//                             rootLiteral.addStatement(nameOf, root);
+//                             rootLiteral.addValue(name, binding);
+//                             root.addStatement(hasName, rootLiteral);
+                               
+//                             System.out.println("root: " + root.resource());
+//                             System.out.println("literal: " + rootLiteral.resource());
+                               
+//                             graph.addLiteral(root, b.HasName, b.NameOf, b.String, name, binding);
+//                             graph.claim(root, b.InstanceOf, null, b.Library);
+
+//                             StatementHandle rootPart = builder.newStatement(b.PartOf, root);
+
+                               ResourceHandle level1 = builder.newResource();
+                               level1.addStatement(instanceOf);
+                               level1.addStatement(partOf, level1);
+//                             root.addStatement(consistsOf, level1);
+//                             ResourceHandle level1Literal = builder.newResource();
+//                             level1Literal.addStatement(instanceOfString);
+//                             level1Literal.addStatement(nameOf, level1);
+//                             level1Literal.addValue(name, binding);
+                               level1.addStatement(hasNameR, level1);
+
+                               StatementHandle level1Part = builder.newStatement(partOf, level1);
+                if (DEBUG)
+                    System.out.println("Level1Part is " + level1Part);
+                               
+//                             System.out.println("root: " + root.resource());
+//                             System.out.println("literal: " + rootLiteral.resource());
+                               
+//                             graph.addLiteral(root, b.HasName, b.NameOf, b.String, name, binding);
+//                             graph.claim(root, b.InstanceOf, null, b.Library);
+
+                               return level1.resource(ss);
+                               
+//                             Resource parent = graph.newResource();
+//                             Resource res = graph.newResource();
+//                             Resource child = graph.newResource();
+//                             Resource literal = graph.newResource();
+//                             graph.claim(parent, L0.ConsistsOf, L0.PartOf, res);
+//                             graph.claim(res, L0.HasName, L0.NameOf, literal);
+//                             graph.claim(res, L0.ConsistsOf, L0.PartOf, child);
+//                             graph.claim(res, L0.InstanceOf, null, L0.Library);
+//                             graph.claim(literal, L0.InstanceOf, null, L0.String);
+//                             graph.claimValue(literal, "A", Bindings.STRING);
+//                             return res;
+                               
+                       }
+               
+        });
+        
+        Resource name = session.syncRequest(new Read<Resource>() {
+
+                       @Override
+                       public Resource perform(ReadGraph graph) throws DatabaseException {
+                               return graph.getSingleObject(res, L0.HasName); 
+//                             return graph.getRelatedValue(res, L0.HasName);
+                       }
+               
+        });
+        if (DEBUG)
+            System.err.println("name: " + name);
+               
+    }
+}