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.api.support.undoRedoSupport;
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;
26 * Tests case where combined operation belongs to two contexts.
28 public class UndoTest14 extends ExistingDatabaseTest {
31 public void testUndo14() throws DatabaseException {
33 Session session = getSession();
34 final UndoRedoSupport support = session.getService(UndoRedoSupport.class);
35 final Resource[] r = new Resource[2];
37 session.syncRequest(new WriteRequest() {
39 public void perform(WriteGraph g) throws DatabaseException {
41 r[0] = g.newResource();
42 g.claim(r[0], r[0], r[0]);
45 } catch (Throwable e) {
46 fail("Write transaction threw an unknown exception " + e);
49 session.syncRequest(new WriteRequest() {
51 public void perform(WriteGraph g) throws DatabaseException {
53 r[1] = g.newResource();
54 g.claim(r[1], r[1], r[1]);
58 session.syncRequest(new ReadRequest() {
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.");
68 support.undo(session, 1);
70 session.syncRequest(new ReadRequest() {
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.");