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.service.UndoRedoSupport;
24 import org.simantics.db.testing.base.ExistingDatabaseTest;
25 import org.simantics.layer0.Layer0;
26 import org.simantics.utils.DataContainer;
29 * Test case description missing!
31 public class UndoTest04 extends ExistingDatabaseTest {
34 public void testUndo4() throws Exception {
36 Session session = getSession();
37 final UndoRedoSupport support = session.getService(UndoRedoSupport.class);
38 final DataContainer<Resource> subject = new DataContainer<Resource>();
39 final String value = "value";
40 final String newValue = "new value";
42 session.syncRequest(new WriteRequest() {
44 public void perform(WriteGraph graph) throws DatabaseException {
45 // Use any non-functional relation
46 Layer0 b = Layer0.getInstance(graph);
47 Resource s = graph.newResource();
48 graph.claim(s, b.InstanceOf, b.Entity);
49 graph.claimValue(s, value);
53 } catch (Throwable e) {
54 fail("Write transaction threw an unknown exception " + e);
58 session.syncRequest(new ReadRequest() {
60 public void run(ReadGraph graph) throws DatabaseException {
61 Resource s = subject.get();
62 if (!graph.hasStatement(s))
63 fail("Failed to verify modifications (stm).");
64 String t = graph.getValue(s, Bindings.STRING);
66 fail("Failed to verify modifications (value).");
69 } catch (Throwable e) {
70 fail("Read transaction threw an unexpected exception " + e);
74 session.syncRequest(new WriteRequest() {
76 public void perform(WriteGraph graph) throws DatabaseException {
77 graph.markUndoPoint();
78 Resource s = subject.get();
79 graph.claimValue(s, newValue);
82 } catch (Throwable e) {
83 fail("Write transaction threw an unknown exception " + e);
86 support.undo(session, 1);
89 session.syncRequest(new ReadRequest() {
91 public void run(ReadGraph graph) throws DatabaseException {
92 Resource s = subject.get();
93 String t = graph.getValue(s, Bindings.STRING);
95 fail("Failed to verify modifications (value).");
98 } catch (Throwable e) {
99 fail("Read transaction threw an unexpected exception " + e);