]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/SimanticsFeature4007Test1.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 / SimanticsFeature4007Test1.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.VirtualGraph;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.common.request.WriteRequest;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.service.ManagementSupport;
22 import org.simantics.db.service.VirtualGraphSupport;
23 import org.simantics.db.testing.base.ExistingDatabaseTest;
24 import org.simantics.layer0.Layer0;
25
26 /**
27  * Tests that using virtual graph during write request does not interfere with
28  * generation of core change sets.
29  * 
30  * See https://www.simulationsite.net/redmine/issues/4007.   
31  */
32 public class SimanticsFeature4007Test1 extends ExistingDatabaseTest {
33     @Test
34     public void testSimanticsFeature4007() throws Exception {
35         final Session session = getSession();
36         final VirtualGraphSupport vgSupport = session.getService(VirtualGraphSupport.class);
37         final ManagementSupport mg =  session.getService(ManagementSupport.class);
38         long id1 = mg.getHeadRevisionId();
39         try {
40             session.syncRequest(new WriteRequest() {
41                 @Override
42                 public void perform(WriteGraph graph) throws DatabaseException {
43                     Layer0 L0 = Layer0.getInstance(graph);
44
45                     Resource r1 = graph.newResource();
46                     graph.claim(r1, L0.InstanceOf, null, L0.Library);
47                     graph.claimLiteral(r1, L0.HasName, "r1");
48
49                     VirtualGraph vg = vgSupport.getWorkspacePersistent("vg");
50                     graph.syncRequest(new WriteRequest(vg) {
51                         @Override
52                         public void perform(WriteGraph graph) throws DatabaseException {
53                             Layer0 L0 = Layer0.getInstance(graph);
54                             Resource r = graph.newResource();
55                             graph.claim(r, L0.InstanceOf, null, L0.Library);
56                             graph.claimLiteral(r, L0.HasName, "rv");
57                         }
58                     });
59
60                     Resource r2 = graph.newResource();
61                     graph.claim(r2, L0.InstanceOf, null, L0.Library);
62                     graph.claimLiteral(r2, L0.HasName, "r2");
63                 }
64             });
65             long id2 = mg.getHeadRevisionId();
66             assertTrue(getName() + " failed!", id2 == id1 + 1);
67         } catch (Throwable e) {
68             fail("Write transaction threw an unknown exception " + e);
69         }
70     }
71 }