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 UndoTest10 extends ExistingDatabaseTest {
33 public void testUndo10() throws Exception {
35 Session session = getSession();
36 final UndoRedoSupport support = session.getService(UndoRedoSupport.class);
38 UndoTestOrderedSet10 c1 = new UndoTestOrderedSet10(session, support);
39 List<Resource> elements = new ArrayList<Resource>();
40 Resource list = c1.create(elements);
41 c1.check(list, elements);
42 c1.add(list, elements);
43 List<Resource> elements2 = new ArrayList<Resource>();
44 elements2.addAll(elements);
45 c1.front2(list, elements2);
46 c1.check(list, elements2);
47 c1.back(list, elements2);
48 c1.check(list, elements2);
49 c1.front(list, elements2);
50 c1.check(list, elements2);
51 c1.back(list, elements2);
52 c1.check(list, elements2);
57 c1.check(list, elements);
58 c1.add(list, elements);
60 } catch (Throwable t) {
61 fail("Test failed with exception " + t);
64 class UndoTestOrderedSet10 extends UndoTestOrderedSet {
65 UndoTestOrderedSet10(Session session, UndoRedoSupport support) {
66 super(session, support);
68 void front2(final Resource list, final List<Resource> els)
69 throws DatabaseException {
70 session.syncRequest(new WriteRequest() {
72 public void perform(WriteGraph g) throws DatabaseException {
74 FirstLast fl = getFirstLast(g, list, els);
77 Resource n = OrderedSetUtils.next(g, list, fl.first);
78 if (n.getResourceId() == fl.first.getResourceId())
80 OrderedSetUtils.remove(g, list, n);
81 OrderedSetUtils.addFirst(g, list, n);
82 els.add(0, els.remove(1));