]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/RedoTest2.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 / RedoTest2.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 org.junit.Test;
15 import org.simantics.databoard.Bindings;
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.Resource;
18 import org.simantics.db.Session;
19 import org.simantics.db.WriteGraph;
20 import org.simantics.db.common.request.ReadRequest;
21 import org.simantics.db.common.request.WriteRequest;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.db.exception.NoSingleResultException;
24 import org.simantics.db.service.UndoRedoSupport;
25 import org.simantics.db.testing.base.ExistingDatabaseTest;
26
27 /**
28  * Tests cases where a non-functional relation uses
29  * {@link ReadGraph#getSingleObject(org.simantics.db.Resource, org.simantics.db.Resource)}
30  * with > 1 objects.
31  * 
32  * <p>
33  * Should throw {@link NoSingleResultException}, at the time of writing this
34  * test, AsyncBarrierImpl refcounting is trashed and DB client is stuck.
35  */
36 public class RedoTest2 extends ExistingDatabaseTest {
37
38         @Test
39     public void testRedo2() throws DatabaseException {
40
41         Session session = getSession();
42         final UndoRedoSupport support = session.getService(UndoRedoSupport.class);
43         final Resource[] r = new Resource[2];
44         try {
45             session.syncRequest(new WriteRequest() {
46                 @Override
47                 public void perform(WriteGraph g) throws DatabaseException {
48                     r[0] = g.newResource();
49                     g.claimValue(r[0], "One", Bindings.STRING);
50                     g.claimValue(r[0], "Two", Bindings.STRING);
51                 }
52             });
53         } catch (Throwable e) {
54             fail("Write transaction threw an unknown exception " + e);
55         }
56
57         session.syncRequest(new ReadRequest() {
58             @Override
59             public void run(ReadGraph g) throws DatabaseException {
60                 String v = g.getValue(r[0], Bindings.STRING);
61                 if (!v.equals("Two"))
62                         fail("ClaimValue did not work as expected.");
63             }
64         });
65
66         support.undo(session, 1);
67         support.redo(session, 1);
68
69         session.syncRequest(new ReadRequest() {
70             @Override
71             public void run(ReadGraph g) throws DatabaseException {
72                 String v = g.getValue(r[0], Bindings.STRING);
73                 if (!v.equals("Two"))
74                         fail("ClaimValue did not work as expected.");
75             }
76         });
77     }
78 }