X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fapi%2Fsupport%2FclusterBuilder%2FWriteOrderTest.java;fp=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fapi%2Fsupport%2FclusterBuilder%2FWriteOrderTest.java;h=3cb6fae3e6eb297d78e03b1117b4326904fe57f3;hb=67fd62f9c742337ec80eef658192db198a0efaac;hp=0000000000000000000000000000000000000000;hpb=cde82ba81327d5515fdca362f7f4c70f5103ae80;p=simantics%2Fplatform.git 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 index 000000000..3cb6fae3e --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterBuilder/WriteOrderTest.java @@ -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() { + + @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() { + + @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); + + } +}