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.databoard.Bindings;
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.Resource;
18 import org.simantics.db.Session;
19 import org.simantics.db.UndoContext;
20 import org.simantics.db.WriteGraph;
21 import org.simantics.db.common.UndoContextEx;
22 import org.simantics.db.common.request.ReadRequest;
23 import org.simantics.db.common.request.WriteRequest;
24 import org.simantics.db.exception.DatabaseException;
25 import org.simantics.db.service.UndoRedoSupport;
26 import org.simantics.db.testing.base.ExistingDatabaseTest;
27 import org.simantics.layer0.Layer0;
30 * Test case description missing!
32 public class UndoTest06 extends ExistingDatabaseTest {
35 public void testUndo6() throws Exception {
37 Session session = getSession();
38 final UndoRedoSupport support = session.getService(UndoRedoSupport.class);
40 Context c1 = new Context(session, support);
58 Context c2 = new Context(session, support);
75 } catch (Throwable t) {
76 fail("Test failed with exception " + t);
81 private final Session session;
82 private final UndoRedoSupport support;
83 final UndoContext uctx = new UndoContextEx();
86 Context(Session session, UndoRedoSupport support) {
87 this.session = session;
88 this.support = support;
90 void create() throws DatabaseException {
91 session.syncRequest(new WriteRequest() {
93 public void perform(WriteGraph graph) throws DatabaseException {
94 graph.markUndoPoint();
95 Layer0 b = Layer0.getInstance(graph);
96 r = graph.newResource();
97 graph.claim(r, b.InstanceOf, b.Entity);
101 void add() throws DatabaseException {
103 session.syncRequest(new WriteRequest() {
105 public void perform(WriteGraph graph) throws DatabaseException {
106 graph.markUndoPoint();
107 graph.claimValue(r, ++value, Bindings.INTEGER);
110 } catch (Throwable e) {
111 fail("Write transaction threw an unknown exception " + e);
114 void check() throws DatabaseException {
115 session.syncRequest(new ReadRequest() {
117 public void run(ReadGraph graph) throws DatabaseException {
118 Integer i = graph.getPossibleValue(r, Bindings.INTEGER);
121 fail("Failed to verify value.");
122 } else if (value != i)
123 fail("Failed to verify value expected " + value + " got " + i);
127 void undo() throws DatabaseException {
128 support.undo(session, 1);