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;
25 import org.simantics.utils.DataContainer;
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 UndoTest12 extends ExistingDatabaseTest {
39 public void testUndo12() throws DatabaseException {
41 Session session = getSession();
42 final UndoRedoSupport support = session.getService(UndoRedoSupport.class);
43 final DataContainer<Resource> r1 = new DataContainer<Resource>();
44 final DataContainer<Resource> r2 = new DataContainer<Resource>();
46 session.syncRequest(new WriteRequest() {
48 public void perform(WriteGraph g) throws DatabaseException {
49 Resource a = g.newResource();
50 Resource b = g.newResource();
58 } catch (Throwable e) {
59 fail("Write transaction threw an unknown exception " + e);
62 check(session, r1.get(), r2.get());
64 support.undo(session, 1);
65 support.redo(session, 1);
67 check(session, r1.get(), r2.get());
70 void check(Session session, final Resource a, final Resource b) {
72 session.syncRequest(new ReadRequest() {
74 public void run(ReadGraph g) throws DatabaseException {
75 if (g.hasStatement(a, a, a))
76 fail("Deny did not work as expected.");
77 if (!g.hasStatement(a, a, b))
78 fail("Add did not work as expected.");
81 } catch (Throwable e) {
82 fail("Read transaction threw an unexpected exception " + e);