]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest14.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 / undoRedoSupport / UndoTest14.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.api.support.undoRedoSupport;
13
14 import org.junit.Test;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.Session;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.common.request.ReadRequest;
20 import org.simantics.db.common.request.WriteRequest;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.service.UndoRedoSupport;
23 import org.simantics.db.testing.base.ExistingDatabaseTest;
24
25 /**
26  * Tests case where combined operation belongs to two contexts.
27  */
28 public class UndoTest14 extends ExistingDatabaseTest {
29
30         @Test
31     public void testUndo14() throws DatabaseException {
32
33         Session session = getSession();
34         final UndoRedoSupport support = session.getService(UndoRedoSupport.class);
35         final Resource[] r = new Resource[2];
36         try {
37             session.syncRequest(new WriteRequest() {
38                 @Override
39                 public void perform(WriteGraph g) throws DatabaseException {
40                     g.markUndoPoint();
41                     r[0] = g.newResource();
42                     g.claim(r[0], r[0], r[0]);
43                 }
44             });
45         } catch (Throwable e) {
46             fail("Write transaction threw an unknown exception " + e);
47         }
48
49         session.syncRequest(new WriteRequest() {
50             @Override
51             public void perform(WriteGraph g) throws DatabaseException {
52                 g.markUndoPoint();
53                 r[1] = g.newResource();
54                 g.claim(r[1], r[1], r[1]);
55             }
56         });
57
58         session.syncRequest(new ReadRequest() {
59             @Override
60             public void run(ReadGraph g) throws DatabaseException {
61                 if (!g.hasStatement(r[0], r[0], r[0]))
62                     fail("Claim did not work as expected.");
63                 if (!g.hasStatement(r[1], r[1], r[1]))
64                     fail("Claim did not work as expected.");
65             }
66         });
67
68         support.undo(session, 1);
69
70         session.syncRequest(new ReadRequest() {
71             @Override
72             public void run(ReadGraph g) throws DatabaseException {
73                 if (!g.hasStatement(r[0], r[0], r[0]))
74                     fail("Undo did not work as expected.");
75                 if (g.hasStatement(r[1], r[1], r[1]))
76                     fail("Undo did not work as expected.");
77             }
78         });
79
80     }
81 }