]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 package org.simantics.db.tests.api.support.managementSupport;
2
3 import java.util.Collection;
4
5 import org.junit.Test;
6 import org.simantics.db.ChangeSet;
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.WriteGraph;
9 import org.simantics.db.common.request.ReadRequest;
10 import org.simantics.db.common.request.WriteRequest;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.db.service.ManagementSupport;
13 import org.simantics.db.testing.base.ExistingDatabaseTest;
14
15 public class FetchChangeSetsTest extends ExistingDatabaseTest {
16 //  static final boolean DEBUG = true;
17     static final boolean VERBOSE = false;
18     @Test
19     public void test() throws DatabaseException {
20         final ManagementSupport ms = getSession().getService(ManagementSupport.class);
21         final long startId = 1;
22         getSession().syncRequest(new WriteRequest() {
23             @Override
24             public void perform(WriteGraph g) throws DatabaseException {
25                 g.newResource();
26             }
27         });
28         final long endId = ms.getHeadRevisionId();
29         assertTrue(endId > 0);
30         getSession().syncRequest(new ReadRequest() {
31             @Override
32             public void run(ReadGraph g) throws DatabaseException {
33                 long id = ms.getHeadRevisionId();
34                 assertTrue(endId == id);
35                 Collection<ChangeSet> css = ms.fetchChangeSets(g, endId, endId);
36                 int size = 1;
37                 assertEquals("Failed to get change sets.", size, css.size());
38                 if (DEBUG)
39                     printDebug(css, endId);
40             }
41         });
42         getSession().syncRequest(new ReadRequest() {
43             @Override
44             public void run(ReadGraph g) throws DatabaseException {
45                 long id = ms.getHeadRevisionId();
46                 assertTrue(endId == id);
47                 Collection<ChangeSet> css = ms.fetchChangeSets(g, startId, endId);
48                 // Can't be sure that old change sets are preserved.
49                 assertTrue("Failed to get change sets.", css.size() >= 1);
50                 if (DEBUG)
51                     printDebug(css, startId);
52             }
53         });
54     }
55     static void printDebug(Collection<ChangeSet> css, long startId) {
56         if (!DEBUG)
57             return;
58         long id = startId;
59         for (ChangeSet cs: css) {
60             System.out.println("cs=" + id);
61             if (VERBOSE)
62                 System.out.println(cs.toString());
63             ++id;
64         }
65     }
66 }