+package org.simantics.db.tests.api.support.managementSupport;
+
+import java.util.Collection;
+
+import org.junit.Test;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.CommentMetadata;
+import org.simantics.db.common.UndoMetadata;
+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 GetMetadataTest extends ExistingDatabaseTest {
+ // Behavior of commit has been changed. Commits with only CommentMetadata are dropped.
+ private void addMetadata(WriteGraph wg, String s) throws DatabaseException {
+ CommentMetadata cm = wg.getMetadata(CommentMetadata.class);
+ wg.addMetadata(cm.add(s));
+ wg.addMetadata(new UndoMetadata(null, false, 0, 0));
+ }
+ @Test
+ public void test() throws DatabaseException {
+ final ManagementSupport ms = getSession().getService(ManagementSupport.class);
+ WriteRequest nop0 = new WriteRequest() {
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ addMetadata(graph, "NOP0");
+ }
+ };
+ getSession().sync(nop0);
+ final long endId = ms.getHeadRevisionId();
+
+ assertTrue(endId > 0);
+ WriteRequest nop1 = new WriteRequest() {
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ addMetadata(graph, "NOP1");
+ }
+ };
+ getSession().sync(nop1);
+ WriteRequest nop2 = new WriteRequest() {
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ addMetadata(graph, "NOP2");
+ }
+ };
+ getSession().sync(nop2);
+ final long newId = ms.getHeadRevisionId();
+
+ assertTrue(endId == newId - 2);
+ getSession().syncRequest(new ReadRequest() {
+ @Override
+ public void run(ReadGraph g) throws DatabaseException {
+ long id = ms.getHeadRevisionId();
+ assertTrue(newId == id);
+ Collection<CommentMetadata> comments = ms.getMetadata(newId-1, newId, CommentMetadata.class);
+ assertTrue(comments.size() == 2);
+ CommentMetadata cm = comments.iterator().next();
+ String s = cm.toString();
+ // The line feed is added by the add operation.
+ assertTrue(s.matches("NOP1\n"));
+ // gitexitOld interface.
+ Collection<CommentMetadata> comments2 = ms.getMetadata(newId-1, newId, CommentMetadata.class);
+ assertTrue(comments.size() == 2);
+ CommentMetadata cm2 = comments2.iterator().next();
+ String s2 = cm2.toString();
+ // The line feed is added by the add operation.
+ assertTrue(s2.matches("NOP1\n"));
+ }
+ });
+ getSession().syncRequest(new ReadRequest() {
+ @Override
+ public void run(ReadGraph g) throws DatabaseException {
+ long id = ms.getHeadRevisionId();
+ assertTrue(newId == id);
+ Collection<CommentMetadata> comments = ms.getMetadata(1, newId, CommentMetadata.class);
+ assertTrue(comments.size() > 2);
+ }
+ });
+ }
+}