]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest10.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / support / undoRedoSupport / UndoTest10.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.tests.api.support.undoRedoSupport;
13
14 import java.util.ArrayList;
15 import java.util.List;
16
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;
26
27 /**
28  * Test case description missing!
29  */
30 public class UndoTest10 extends ExistingDatabaseTest {
31     
32         @Test
33     public void testUndo10() throws Exception {
34
35         Session session = getSession();
36         final UndoRedoSupport support = session.getService(UndoRedoSupport.class);
37         try {
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);
53             c1.undo();
54             c1.undo();
55             c1.undo();
56             c1.undo();
57             c1.check(list, elements);
58             c1.add(list, elements);
59             elements2.clear();
60         } catch (Throwable t) {
61             fail("Test failed with exception " + t);
62         }
63     }
64     class UndoTestOrderedSet10 extends UndoTestOrderedSet {
65         UndoTestOrderedSet10(Session session, UndoRedoSupport support) {
66             super(session, support);
67         }
68         void front2(final Resource list, final List<Resource> els)
69         throws DatabaseException {
70             session.syncRequest(new WriteRequest() {
71                 @Override
72                 public void perform(WriteGraph g) throws DatabaseException {
73                     g.markUndoPoint();
74                     FirstLast fl = getFirstLast(g, list, els);
75                     if (null == fl.first)
76                         return;
77                     Resource n = OrderedSetUtils.next(g, list, fl.first);
78                     if (n.getResourceId() == fl.first.getResourceId())
79                         return;
80                     OrderedSetUtils.remove(g, list, n);
81                     OrderedSetUtils.addFirst(g, list, n);
82                     els.add(0, els.remove(1));
83                 }
84             });
85         }
86     }
87 }