]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getInverse/GetInverseTest4.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 / getInverse / GetInverseTest4.java
diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getInverse/GetInverseTest4.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getInverse/GetInverseTest4.java
new file mode 100644 (file)
index 0000000..6d7d241
--- /dev/null
@@ -0,0 +1,45 @@
+package org.simantics.db.tests.api.readGraph.getInverse;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.NoInverseException;
+import org.simantics.db.testing.base.WriteReadTest;
+
+/*
+ * When a resource does not specify L0.InverseOf, getInverse shall throw NoInverseException.
+ */
+public class GetInverseTest4 extends WriteReadTest {
+       private Resource relation1;
+       private Resource relation2;
+       private Resource relation3;
+
+       @Override
+       protected void write(WriteGraph graph) throws DatabaseException {
+
+        //Create first resource and give it a name
+        relation1 = graph.newResource();
+        graph.claim(relation1, L0.Inherits, L0.Relation);
+        relation2 = graph.newResource();
+        graph.claim(relation2, L0.Inherits, L0.Relation);
+        graph.claim(relation1, L0.InverseOf, relation2);
+
+        relation3 = graph.newResource();
+        graph.claim(relation3, L0.Inherits, L0.Relation);
+        graph.claim(relation1, L0.InverseOf, relation3);
+
+       }
+
+       @Override
+       protected void read(ReadGraph graph) throws DatabaseException {
+        try {
+               assertNotNull("Null not allowed", graph.getInverse(relation1));
+        } catch (NoInverseException e) {
+            return;
+        } catch(Throwable t) {
+            fail("Wrong exception was thrown " + t);
+        }
+        fail("No exception was thrown!");
+       }
+}