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 java.util.Arrays;
16 import org.junit.Test;
17 import org.simantics.databoard.Bindings;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.Session;
21 import org.simantics.db.WriteGraph;
22 import org.simantics.db.common.request.ReadRequest;
23 import org.simantics.db.common.request.WriteRequest;
24 import org.simantics.db.exception.DatabaseException;
25 import org.simantics.db.service.UndoRedoSupport;
26 import org.simantics.db.testing.base.ExistingDatabaseTest;
27 import org.simantics.layer0.Layer0;
28 import org.simantics.utils.DataContainer;
31 * Test case description missing!
33 public class UndoTest16 extends ExistingDatabaseTest {
34 private void initValue(byte[] value) {
35 for (int i=0; i<value.length; ++i)
39 public void testUndo16() throws Exception {
41 Session session = getSession();
42 final UndoRedoSupport support = session.getService(UndoRedoSupport.class);
43 final DataContainer<Resource> subject = new DataContainer<Resource>();
44 final byte[] value = new byte[100000];
45 final byte[] newValue = new byte[200000];
50 session.syncRequest(new WriteRequest() {
52 public void perform(WriteGraph graph) throws DatabaseException {
53 graph.markUndoPoint();
54 // Use any non-functional relation
55 Layer0 b = Layer0.getInstance(graph);
56 Resource s = graph.newResource();
57 graph.claim(s, b.InstanceOf, b.Entity);
58 graph.claimValue(s, value);
62 } catch (Throwable e) {
63 fail("Write transaction threw an unknown exception " + e);
67 session.syncRequest(new ReadRequest() {
69 public void run(ReadGraph graph) throws DatabaseException {
70 Resource s = subject.get();
71 if (!graph.hasStatement(s))
72 fail("Failed to verify modifications (stm).");
73 byte[] t = graph.getValue(s, Bindings.BYTE_ARRAY);
74 if (!Arrays.equals(t, value))
75 fail("Failed to verify modifications (value).");
78 } catch (Throwable e) {
79 fail("Read transaction threw an unexpected exception " + e);
83 session.syncRequest(new WriteRequest() {
85 public void perform(WriteGraph graph) throws DatabaseException {
86 graph.markUndoPoint();
87 Resource s = subject.get();
88 graph.claimValue(s, newValue);
91 } catch (Throwable e) {
92 fail("Write transaction threw an unknown exception " + e);
95 support.undo(session, 1);
98 session.syncRequest(new ReadRequest() {
100 public void run(ReadGraph graph) throws DatabaseException {
101 Resource s = subject.get();
102 byte[] t = graph.getValue(s, Bindings.BYTE_ARRAY);
103 if (!Arrays.equals(t, value))
104 fail("Failed to verify modifications (value).");
107 } catch (Throwable e) {
108 fail("Read transaction threw an unexpected exception " + e);
111 support.undo(session, 1);
114 session.syncRequest(new ReadRequest() {
116 public void run(ReadGraph graph) throws DatabaseException {
117 Resource s = subject.get();
118 byte[] t = graph.getPossibleValue(s, Bindings.BYTE_ARRAY);
120 fail("Failed to verify modifications (value).");
123 } catch (Throwable e) {
124 fail("Read transaction threw an unexpected exception " + e);