]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/managementSupport/FetchChangeSetsTest.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 / managementSupport / FetchChangeSetsTest.java
diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/managementSupport/FetchChangeSetsTest.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/managementSupport/FetchChangeSetsTest.java
new file mode 100644 (file)
index 0000000..e29c669
--- /dev/null
@@ -0,0 +1,66 @@
+package org.simantics.db.tests.api.support.managementSupport;
+
+import java.util.Collection;
+
+import org.junit.Test;
+import org.simantics.db.ChangeSet;
+import org.simantics.db.ReadGraph;
+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.service.ManagementSupport;
+import org.simantics.db.testing.base.ExistingDatabaseTest;
+
+public class FetchChangeSetsTest extends ExistingDatabaseTest {
+//  static final boolean DEBUG = true;
+    static final boolean VERBOSE = false;
+    @Test
+    public void test() throws DatabaseException {
+        final ManagementSupport ms = getSession().getService(ManagementSupport.class);
+        final long startId = 1;
+        getSession().syncRequest(new WriteRequest() {
+            @Override
+            public void perform(WriteGraph g) throws DatabaseException {
+                g.newResource();
+            }
+        });
+        final long endId = ms.getHeadRevisionId();
+        assertTrue(endId > 0);
+        getSession().syncRequest(new ReadRequest() {
+            @Override
+            public void run(ReadGraph g) throws DatabaseException {
+                long id = ms.getHeadRevisionId();
+                assertTrue(endId == id);
+                Collection<ChangeSet> css = ms.fetchChangeSets(g, endId, endId);
+                int size = 1;
+                assertEquals("Failed to get change sets.", size, css.size());
+                if (DEBUG)
+                    printDebug(css, endId);
+            }
+        });
+        getSession().syncRequest(new ReadRequest() {
+            @Override
+            public void run(ReadGraph g) throws DatabaseException {
+                long id = ms.getHeadRevisionId();
+                assertTrue(endId == id);
+                Collection<ChangeSet> css = ms.fetchChangeSets(g, startId, endId);
+                // Can't be sure that old change sets are preserved.
+                assertTrue("Failed to get change sets.", css.size() >= 1);
+                if (DEBUG)
+                    printDebug(css, startId);
+            }
+        });
+    }
+    static void printDebug(Collection<ChangeSet> css, long startId) {
+        if (!DEBUG)
+            return;
+        long id = startId;
+        for (ChangeSet cs: css) {
+            System.out.println("cs=" + id);
+            if (VERBOSE)
+                System.out.println(cs.toString());
+            ++id;
+        }
+    }
+}