]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest11.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 / UndoTest11.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 UndoTest11 extends ExistingDatabaseTest {
31     
32         @Test
33     public void testUndo11() throws Exception {
34
35         Session session = getSession();
36         final UndoRedoSupport support = session.getService(UndoRedoSupport.class);
37         try {
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);
45             c1.undo();
46             c1.check(list, elements);
47         } catch (Throwable t) {
48             fail("Test failed with exception ", t);
49         }
50     }
51     class UndoTestOrderedSet11 extends UndoTestOrderedSet {
52         UndoTestOrderedSet11(Session session, UndoRedoSupport support) {
53             super(session, support);
54         }
55         void modify(final Resource list, final List<Resource> els)
56         throws DatabaseException {
57             session.syncRequest(new WriteRequest() {
58                 @Override
59                 public void perform(WriteGraph g) throws DatabaseException {
60                     g.markUndoPoint();
61                     FirstLast fl = getFirstLast(g, list, els);
62                     if (null == fl.first)
63                         return;
64                     Resource el = g.newResource();
65                     OrderedSetUtils.add(g, list, el);
66                     OrderedSetUtils.remove(g, list, el);
67                 }
68             });
69         }
70     }
71 }