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.exception.NoSingleResultException;
23 import org.simantics.db.service.UndoRedoSupport;
24 import org.simantics.db.testing.base.ExistingDatabaseTest;
27 * Tests cases where a non-functional relation uses
28 * {@link ReadGraph#getSingleObject(org.simantics.db.Resource, org.simantics.db.Resource)}
32 * Should throw {@link NoSingleResultException}, at the time of writing this
33 * test, AsyncBarrierImpl refcounting is trashed and DB client is stuck.
35 public class UndoTest15 extends ExistingDatabaseTest {
38 public void testUndo15() throws DatabaseException {
40 Session session = getSession();
41 final UndoRedoSupport support = session.getService(UndoRedoSupport.class);
42 final Resource[] r = new Resource[2];
44 session.syncRequest(new WriteRequest() {
46 public void perform(WriteGraph g) throws DatabaseException {
48 r[0] = g.newResource();
49 g.claim(r[0], r[0], r[0]);
52 } catch (Throwable e) {
53 fail("Write transaction threw an unknown exception " + e);
56 session.syncRequest(new WriteRequest() {
58 public void perform(WriteGraph g) throws DatabaseException {
60 r[1] = g.newResource();
61 g.deny(r[0], r[0], r[0]);
62 g.claim(r[0], r[0], r[1]);
66 session.syncRequest(new ReadRequest() {
68 public void run(ReadGraph g) throws DatabaseException {
69 if (g.hasStatement(r[0], r[0], r[0]))
70 fail("Deny did not work as expected.");
71 if (!g.hasStatement(r[0], r[0], r[1]))
72 fail("Claim did not work as expected.");
75 // Note that the implementation and interpretation of this operation has changed.
76 // This used to be undoRevisions but now this is undoOperations.
77 // Works as expected only for single operations.
78 support.undo(session, 2);
80 session.syncRequest(new ReadRequest() {
82 public void run(ReadGraph g) throws DatabaseException {
83 if (g.hasStatement(r[0], r[0], r[0]))
84 fail("Undo did not work as expected.");
85 if (g.hasStatement(r[0], r[0], r[1]))
86 fail("Undo did not work as expected.");
89 // Note that the implementation and interpretation of this operation has changed.
90 // Works as expected only for count one.
91 support.redo(session, 1);
93 session.syncRequest(new ReadRequest() {
95 public void run(ReadGraph g) throws DatabaseException {
96 if (g.hasStatement(r[0], r[0], r[0]))
97 fail("Undo did not work as expected.");
98 if (!g.hasStatement(r[0], r[0], r[1]))
99 fail("Undo did not work as expected.");