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.ArrayList;
15 import java.util.List;
17 import org.junit.Test;
18 import org.simantics.db.Resource;
19 import org.simantics.db.Session;
20 import org.simantics.db.WriteGraph;
21 import org.simantics.db.common.request.WriteRequest;
22 import org.simantics.db.common.utils.OrderedSetUtils;
23 import org.simantics.db.exception.DatabaseException;
24 import org.simantics.db.service.UndoRedoSupport;
25 import org.simantics.db.testing.base.ExistingDatabaseTest;
28 * Test case description missing!
30 public class UndoTest11 extends ExistingDatabaseTest {
33 public void testUndo11() throws Exception {
35 Session session = getSession();
36 final UndoRedoSupport support = session.getService(UndoRedoSupport.class);
38 UndoTestOrderedSet11 c1 = new UndoTestOrderedSet11(session, support);
39 List<Resource> elements = new ArrayList<Resource>();
40 Resource list = c1.create(elements);
41 List<Resource> elements2 = new ArrayList<Resource>();
42 elements2.addAll(elements);
43 c1.modify(list, elements2);
44 c1.check(list, elements2);
46 c1.check(list, elements);
47 } catch (Throwable t) {
48 fail("Test failed with exception ", t);
51 class UndoTestOrderedSet11 extends UndoTestOrderedSet {
52 UndoTestOrderedSet11(Session session, UndoRedoSupport support) {
53 super(session, support);
55 void modify(final Resource list, final List<Resource> els)
56 throws DatabaseException {
57 session.syncRequest(new WriteRequest() {
59 public void perform(WriteGraph g) throws DatabaseException {
61 FirstLast fl = getFirstLast(g, list, els);
64 Resource el = g.newResource();
65 OrderedSetUtils.add(g, list, el);
66 OrderedSetUtils.remove(g, list, el);