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;
26 import org.simantics.layer0.Layer0;
27 import org.simantics.utils.DataContainer;
30 * Tests cases where a non-functional relation uses
31 * {@link ReadGraph#getSingleObject(org.simantics.db.Resource, org.simantics.db.Resource)}
35 * Should throw {@link NoSingleResultException}, at the time of writing this
36 * test, AsyncBarrierImpl refcounting is trashed and DB client is stuck.
38 public class UndoTest05 extends ExistingDatabaseTest {
41 public void testUndo5() throws Exception {
43 Session session = getSession();
44 final UndoRedoSupport support = session.getService(UndoRedoSupport.class);
46 final DataContainer<Resource> subject = new DataContainer<Resource>();
47 final String value = "value";
48 final String newValue = "new value";
50 session.syncRequest(new WriteRequest() {
52 public void perform(WriteGraph graph) throws DatabaseException {
53 graph.markUndoPoint();
54 Layer0 b = Layer0.getInstance(graph);
55 Resource s = graph.newResource();
56 graph.claim(s, b.InstanceOf, b.Entity);
57 graph.claimValue(s, value);
61 } catch (Throwable e) {
62 fail("Write transaction threw an unknown exception " + e);
65 session.syncRequest(new ReadRequest() {
67 public void run(ReadGraph graph) throws DatabaseException {
68 Resource s = subject.get();
69 if (!graph.hasStatement(s))
70 fail("Failed to verify modifications (stm).");
71 String t = graph.getValue(s, Bindings.STRING);
73 fail("Failed to verify modifications (value).");
76 } catch (Throwable e) {
77 fail("Read transaction threw an unexpected exception " + e);
81 session.syncRequest(new WriteRequest() {
83 public void perform(WriteGraph graph) throws DatabaseException {
84 graph.markUndoPoint();
85 Resource s = subject.get();
86 graph.claimValue(s, newValue);
89 } catch (Throwable e) {
90 fail("Write transaction threw an unknown exception " + e);
93 support.undo(session, 2);
96 session.syncRequest(new ReadRequest() {
98 public void run(ReadGraph graph) throws DatabaseException {
99 Resource s = subject.get();
100 String t = graph.getPossibleValue(s, Bindings.STRING);
102 fail("Failed to verify modifications (value).");
105 } catch (Throwable e) {
106 fail("Read transaction threw an unexpected exception " + e);