]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue3422Test1.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / regression / bugs / Issue3422Test1.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.tests.regression.bugs;
13
14 import org.junit.Test;
15 import org.simantics.db.Resource;
16 import org.simantics.db.Session;
17 import org.simantics.db.WriteGraph;
18 import org.simantics.db.common.request.WriteRequest;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.db.exception.ImmutableException;
21 import org.simantics.db.service.ClusterControl;
22 import org.simantics.db.service.XSupport;
23 import org.simantics.db.testing.cases.FreshDatabaseTest;
24 import org.simantics.db.testing.common.TestBase;
25 import org.simantics.layer0.Layer0;
26
27 /**
28  * Tests that commit which changes only meta data will create revision.  
29  */
30 public class Issue3422Test1 extends FreshDatabaseTest {
31     private Resource testRoot;
32         @Test
33     public void test() throws DatabaseException {
34         Session session = getSession();
35         session.syncRequest(new Init());
36         session.syncRequest(new Modify());
37     }
38     class Init extends WriteRequest {
39         @Override
40         public void perform(WriteGraph g) throws DatabaseException {
41             ClusterControl cc = (ClusterControl)g.getService(ClusterControl.class);
42             cc.collectClusters(Integer.MAX_VALUE);
43             int nClusters = cc.flushClusters(); 
44             Layer0 l0 = Layer0.getInstance(g);
45             g.flushCluster(); // Starts new cluster.
46             Resource rl = g.getResource(TestBase.ROOT_LIBRARY_URI);
47             testRoot = g.newResource();
48             g.claim(testRoot, l0.InstanceOf, l0.Library);
49             g.claim(rl, l0.ConsistsOf, testRoot);
50             XSupport xs = (XSupport)g.getService(XSupport.class);
51             assertFalse("GetImmutable did not work.", xs.getImmutable(testRoot));
52             xs.setImmutable(testRoot, true);
53             assertTrue("SetImmutable did not work.", xs.getImmutable(testRoot));
54             cc.collectClusters(Integer.MAX_VALUE);
55             int nClusters2 = cc.flushClusters(); 
56             assertTrue("Could not relase clusters.", nClusters + 1 == nClusters2);
57         }
58     }
59     class Modify extends WriteRequest {
60         @Override
61         public void perform(WriteGraph g) throws DatabaseException {
62             ClusterControl cc = (ClusterControl)g.getService(ClusterControl.class);
63             cc.collectClusters(Integer.MAX_VALUE);
64             int nClusters = cc.flushClusters();
65             System.out.println("clusters count=" + nClusters);
66             Layer0 l0 = Layer0.getInstance(getSession());
67             XSupport xs = (XSupport)g.getService(XSupport.class);
68             assertTrue("SetImmutable did not work.", xs.getImmutable(testRoot));
69             try { 
70                 g.claim(testRoot, l0.InstanceOf, l0.Relation);
71             } catch (ImmutableException e) { 
72                 return;
73             }
74             fail("Immutable check did not work.");
75         }
76     }
77 }