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