]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/hasStatement/HasStatementTest2.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / readGraph / hasStatement / HasStatementTest2.java
diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/hasStatement/HasStatementTest2.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/hasStatement/HasStatementTest2.java
new file mode 100644 (file)
index 0000000..859453a
--- /dev/null
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.tests.api.readGraph.hasStatement;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.junit.Test;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.ReadRequest;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.testing.annotation.Fails;
+import org.simantics.db.testing.base.ExistingDatabaseTest;
+import org.simantics.layer0.Layer0;
+
+public class HasStatementTest2 extends ExistingDatabaseTest {
+
+       @Test
+       @Fails
+    public void test() throws Exception {
+
+        Session session = getSession();
+
+        final AtomicReference<Resource> broken = new AtomicReference<Resource>();
+        final AtomicReference<Resource> brokenName1 = new AtomicReference<Resource>();
+
+        session.syncRequest(new WriteRequest() {
+            @Override
+            public void perform(WriteGraph graph) throws DatabaseException {
+                Layer0 L0 = Layer0.getInstance(graph);
+                Resource brokenName = graph.newResource();
+                graph.claim(brokenName, L0.InstanceOf, null, L0.Entity);
+
+                Resource name1 = graph.newResource();
+                Resource name2 = graph.newResource();
+                graph.claim(name1, L0.InstanceOf, null, L0.String);
+                graph.claim(name2, L0.InstanceOf, null, L0.String);
+                graph.claimValue(name1, "name1");
+                graph.claimValue(name1, "name2");
+                graph.claim(brokenName, L0.HasName, L0.NameOf, name1);
+                graph.claim(brokenName, L0.HasName, L0.NameOf, name2);
+
+                broken.set(brokenName);
+                brokenName1.set(name1);
+            }
+        });
+
+        try {
+
+            session.syncRequest(new ReadRequest() {
+                @Override
+                public void run(ReadGraph graph) throws DatabaseException {
+                    Layer0 L0 = Layer0.getInstance(graph);
+                    assertTrue( graph.hasStatement(broken.get()) );
+                    assertFalse( graph.hasStatement(broken.get(), L0.HasLabel, brokenName1.get()) );
+                    assertFalse( graph.hasStatement(broken.get(), L0.HasLabel) );
+                    assertTrue( graph.hasStatement(broken.get(), L0.IsWeaklyRelatedTo, brokenName1.get()) );
+                    assertTrue( graph.hasStatement(broken.get(), L0.IsWeaklyRelatedTo) );
+                    assertTrue( graph.hasStatement(broken.get(), L0.HasName, brokenName1.get()) );
+                    assertTrue( graph.hasStatement(broken.get(), L0.HasName) );
+                }
+            });
+
+        } catch (DatabaseException t) {
+
+            t.printStackTrace();
+            fail("syncRequest(Read) threw unexpected DatabaseException " + t);
+
+        } catch (Throwable t) {
+
+            t.printStackTrace();
+            fail("syncRequest(Read) threw unexpected throwable " + t);
+
+        }
+
+    }
+
+}