1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.tests.regression.bugs;
14 import java.util.Collection;
17 import org.junit.Test;
18 import org.simantics.db.ChangeSetIdentifier;
19 import org.simantics.db.ReadGraph;
20 import org.simantics.db.Session;
21 import org.simantics.db.WriteGraph;
22 import org.simantics.db.common.CommentMetadata;
23 import org.simantics.db.common.UndoMetadata;
24 import org.simantics.db.common.request.ReadRequest;
25 import org.simantics.db.common.request.WriteRequest;
26 import org.simantics.db.exception.DatabaseException;
27 import org.simantics.db.service.ManagementSupport;
28 import org.simantics.db.service.XSupport;
29 import org.simantics.db.testing.base.ExistingDatabaseTest;
32 * Tests that commit which changes only meta data will create revision.
34 public class Issue3072Test1 extends ExistingDatabaseTest {
35 final boolean DEBUG = true;
36 final String resourceName = "Issue3072Test1";
37 // Behavior of commit has been changed. Commits with only CommentMetadata are dropped.
38 private void addMetadata(WriteGraph wg, String s) throws DatabaseException {
39 CommentMetadata cm = wg.getMetadata(CommentMetadata.class);
40 wg.addMetadata(cm.add(s));
41 wg.addMetadata(new UndoMetadata(null, false, 0, 0));
44 public void testIssue3072Test1() throws Exception {
45 final Session session = getSession();
46 final ManagementSupport ms = session.getService(ManagementSupport.class);
47 final long revision1 = ms.getHeadRevisionId();
48 session.syncRequest(new WriteRequest() {
50 public void perform(WriteGraph graph) throws DatabaseException {
51 addMetadata(graph, "New comment.");
54 final long revision2 = ms.getHeadRevisionId();
55 assertTrue("Failed to create metadata only revision.", revision1 + 1 == revision2);
56 session.syncRequest(new ReadRequest() {
58 public void run(ReadGraph graph) throws DatabaseException {
59 Collection<ChangeSetIdentifier> cids = ms.getChangeSetIdentifiers(revision2, revision2);
60 assertTrue("Failed to get empty change set.", cids.size() == 1);
61 Map<String, byte[]> metadata = cids.iterator().next().getMetadata();
62 assertTrue("Failed to get metadata.", metadata.size() > 0);
63 XSupport xs = (XSupport)graph.getService(XSupport.class);
64 xs.clearMetadataCache();
65 Collection<ChangeSetIdentifier> cids2 = ms.getChangeSetIdentifiers(revision2, revision2);
66 assertTrue("Failed to get empty change set.", cids2.size() == 1);
67 Map<String, byte[]> metadata2 = cids2.iterator().next().getMetadata();
68 assertTrue("Fail ed to get metadata.", metadata2.size() > 0);