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 UndoTest13 extends ExistingDatabaseTest {
38 public void testUndo13() throws DatabaseException {
40 Session session = getSession();
41 final UndoRedoSupport support = session.getService(UndoRedoSupport.class);
42 final Resource[] r = new Resource[3];
44 session.syncRequest(new WriteRequest() {
46 public void perform(WriteGraph g) throws DatabaseException {
47 r[0] = g.newResource();
48 r[1] = g.newResource();
49 r[2] = g.newResource();
50 g.claim(r[0], r[0], r[0]);
51 g.deny(r[0], r[0], r[0]);
52 g.claim(r[0], r[0], r[1]);
53 g.deny(r[0], r[0], r[1]);
54 g.claim(r[0], r[0], r[2]);
57 } catch (Throwable e) {
58 fail("Write transaction threw an unknown exception " + e);
61 session.syncRequest(new ReadRequest() {
63 public void run(ReadGraph g) throws DatabaseException {
64 if (g.hasStatement(r[0], r[0], r[0]))
65 fail("Deny did not work as expected.");
66 if (g.hasStatement(r[0], r[0], r[1]))
67 fail("Deny did not work as expected.");
68 if (!g.hasStatement(r[0], r[0], r[2]))
69 fail("Add did not work as expected.");
73 support.undo(session, 1);
75 session.syncRequest(new ReadRequest() {
77 public void run(ReadGraph g) throws DatabaseException {
78 if (g.hasStatement(r[0], r[0], r[0]))
79 fail("What did not work as expected.");
80 if (g.hasStatement(r[0], r[0], r[1]))
81 fail("Deny did not work as expected.");
82 if (g.hasStatement(r[0], r[0], r[2]))
83 fail("Add did not work as expected.");