]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/managementSupport/GetMetadataTest.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 / GetMetadataTest.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.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;
15
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));
22     }
23     @Test
24     public void test() throws DatabaseException {
25         final ManagementSupport ms = getSession().getService(ManagementSupport.class);
26         WriteRequest nop0 = new WriteRequest() {
27             @Override
28             public void perform(WriteGraph graph) throws DatabaseException {
29                 addMetadata(graph, "NOP0");
30             }
31         };
32         getSession().sync(nop0);
33         final long endId = ms.getHeadRevisionId();
34
35         assertTrue(endId > 0);
36         WriteRequest nop1 = new WriteRequest() {
37             @Override
38             public void perform(WriteGraph graph) throws DatabaseException {
39                 addMetadata(graph, "NOP1");
40             }
41         };
42         getSession().sync(nop1);
43         WriteRequest nop2 = new WriteRequest() {
44             @Override
45             public void perform(WriteGraph graph) throws DatabaseException {
46                 addMetadata(graph, "NOP2");
47             }
48         };
49         getSession().sync(nop2);
50         final long newId = ms.getHeadRevisionId();
51
52         assertTrue(endId == newId - 2);
53         getSession().syncRequest(new ReadRequest() {
54             @Override
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"));
71             }
72         });
73         getSession().syncRequest(new ReadRequest() {
74             @Override
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);
80             }
81         });
82     }
83 }