1 package org.simantics.db.tests.api.support.managementSupport;
3 import java.util.Collection;
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.WriteGraph;
8 import org.simantics.db.common.CommentMetadata;
9 import org.simantics.db.common.UndoMetadata;
10 import org.simantics.db.common.request.ReadRequest;
11 import org.simantics.db.common.request.WriteRequest;
12 import org.simantics.db.exception.DatabaseException;
13 import org.simantics.db.service.ManagementSupport;
14 import org.simantics.db.testing.base.ExistingDatabaseTest;
16 public class GetMetadataTest extends ExistingDatabaseTest {
17 // Behavior of commit has been changed. Commits with only CommentMetadata are dropped.
18 private void addMetadata(WriteGraph wg, String s) throws DatabaseException {
19 CommentMetadata cm = wg.getMetadata(CommentMetadata.class);
20 wg.addMetadata(cm.add(s));
21 wg.addMetadata(new UndoMetadata(null, false, 0, 0));
24 public void test() throws DatabaseException {
25 final ManagementSupport ms = getSession().getService(ManagementSupport.class);
26 WriteRequest nop0 = new WriteRequest() {
28 public void perform(WriteGraph graph) throws DatabaseException {
29 addMetadata(graph, "NOP0");
32 getSession().sync(nop0);
33 final long endId = ms.getHeadRevisionId();
35 assertTrue(endId > 0);
36 WriteRequest nop1 = new WriteRequest() {
38 public void perform(WriteGraph graph) throws DatabaseException {
39 addMetadata(graph, "NOP1");
42 getSession().sync(nop1);
43 WriteRequest nop2 = new WriteRequest() {
45 public void perform(WriteGraph graph) throws DatabaseException {
46 addMetadata(graph, "NOP2");
49 getSession().sync(nop2);
50 final long newId = ms.getHeadRevisionId();
52 assertTrue(endId == newId - 2);
53 getSession().syncRequest(new ReadRequest() {
55 public void run(ReadGraph g) throws DatabaseException {
56 long id = ms.getHeadRevisionId();
57 assertTrue(newId == id);
58 Collection<CommentMetadata> comments = ms.getMetadata(newId-1, newId, CommentMetadata.class);
59 assertTrue(comments.size() == 2);
60 CommentMetadata cm = comments.iterator().next();
61 String s = cm.toString();
62 // The line feed is added by the add operation.
63 assertTrue(s.matches("NOP1\n"));
64 // gitexitOld interface.
65 Collection<CommentMetadata> comments2 = ms.getMetadata(newId-1, newId, CommentMetadata.class);
66 assertTrue(comments.size() == 2);
67 CommentMetadata cm2 = comments2.iterator().next();
68 String s2 = cm2.toString();
69 // The line feed is added by the add operation.
70 assertTrue(s2.matches("NOP1\n"));
73 getSession().syncRequest(new ReadRequest() {
75 public void run(ReadGraph g) throws DatabaseException {
76 long id = ms.getHeadRevisionId();
77 assertTrue(newId == id);
78 Collection<CommentMetadata> comments = ms.getMetadata(1, newId, CommentMetadata.class);
79 assertTrue(comments.size() > 2);