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.WriteGraph;
20 import org.simantics.db.common.request.ReadRequest;
21 import org.simantics.db.common.request.WriteRequest;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.db.exception.NoSingleResultException;
24 import org.simantics.db.service.UndoRedoSupport;
25 import org.simantics.db.testing.base.ExistingDatabaseTest;
28 * Tests cases where a non-functional relation uses
29 * {@link ReadGraph#getSingleObject(org.simantics.db.Resource, org.simantics.db.Resource)}
33 * Should throw {@link NoSingleResultException}, at the time of writing this
34 * test, AsyncBarrierImpl refcounting is trashed and DB client is stuck.
36 public class RedoTest2 extends ExistingDatabaseTest {
39 public void testRedo2() throws DatabaseException {
41 Session session = getSession();
42 final UndoRedoSupport support = session.getService(UndoRedoSupport.class);
43 final Resource[] r = new Resource[2];
45 session.syncRequest(new WriteRequest() {
47 public void perform(WriteGraph g) throws DatabaseException {
48 r[0] = g.newResource();
49 g.claimValue(r[0], "One", Bindings.STRING);
50 g.claimValue(r[0], "Two", Bindings.STRING);
53 } catch (Throwable e) {
54 fail("Write transaction threw an unknown exception " + e);
57 session.syncRequest(new ReadRequest() {
59 public void run(ReadGraph g) throws DatabaseException {
60 String v = g.getValue(r[0], Bindings.STRING);
62 fail("ClaimValue did not work as expected.");
66 support.undo(session, 1);
67 support.redo(session, 1);
69 session.syncRequest(new ReadRequest() {
71 public void run(ReadGraph g) throws DatabaseException {
72 String v = g.getValue(r[0], Bindings.STRING);
74 fail("ClaimValue did not work as expected.");