]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/TicketTest646.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / regression / bugs / TicketTest646.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.regression.bugs;
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.service.UndoRedoSupport;
24 import org.simantics.db.testing.annotation.Fails;
25 import org.simantics.db.testing.base.ExistingDatabaseTest;
26 import org.simantics.layer0.Layer0;
27 import org.simantics.utils.DataContainer;
28
29 public class TicketTest646 extends ExistingDatabaseTest {
30     
31     @Test
32     @Fails
33     public void testTicket646() throws Exception {
34
35         Session session = getSession();
36         final UndoRedoSupport support = session.getService(UndoRedoSupport.class);
37         final DataContainer<Resource> subject = new DataContainer<Resource>();
38         final String value = "value";
39         final String newValue = "new value";
40         final String newValue2 = "new value 2";
41         final String newValue3 = "new value 3";
42         try {
43             session.syncRequest(new WriteRequest() {
44                 @Override
45                 public void perform(WriteGraph graph) throws DatabaseException {
46                     // Use any non-functional relation
47                     Layer0 b = Layer0.getInstance(graph);
48                     Resource s = graph.newResource();
49                     graph.claim(s, b.InstanceOf, b.Entity);
50                     graph.claimValue(s, value);
51                     subject.set(s);
52                 }
53             });
54         } catch (Throwable e) {
55             fail("Write transaction threw an unknown exception " + e);
56         }
57         try {
58             session.syncRequest(new ReadRequest() {
59                 @Override
60                 public void run(ReadGraph graph) throws DatabaseException {
61                     Resource s = subject.get();
62                     if (!graph.hasStatement(s))
63                         fail("Failed to verify modifications (stm).");
64                     String t = graph.getValue(s, Bindings.STRING);
65                     if (!t.equals(value))
66                         fail("Failed to verify modifications (value).");
67                 }
68             });
69         } catch (Throwable e) {
70             fail("Read transaction threw an unexpected exception " + e);
71         }
72
73         try {
74             session.syncRequest(new WriteRequest() {
75                 @Override
76                 public void perform(WriteGraph graph) throws DatabaseException {
77                     Resource s = subject.get();
78                     graph.claimValue(s, newValue);
79                     graph.claimValue(s, newValue2);
80                     graph.claimValue(s, newValue3);
81                 }
82             });
83         } catch (Throwable e) {
84             fail("Write transaction threw an unknown exception " + e);
85         }
86
87         support.undo(session, 1);
88
89         try {
90             session.syncRequest(new ReadRequest() {
91                 @Override
92                 public void run(ReadGraph graph) throws DatabaseException {
93                     Resource s = subject.get();
94                     String t = graph.getPossibleValue(s, Bindings.STRING);
95                     if (null != t)
96                         fail("Failed to verify modifications (value).");
97                 }
98             });
99         } catch (Throwable e) {
100             fail("Read transaction threw an unexpected exception " + e);
101         }
102
103         support.redo(session, 1);
104         
105         try {
106             session.syncRequest(new ReadRequest() {
107                 @Override
108                 public void run(ReadGraph graph) throws DatabaseException {
109                     Resource s = subject.get();
110                     String t = graph.getPossibleValue(s, Bindings.STRING);
111                     if (null == t)
112                         fail("Failed to verify modifications (value).");
113                     if (!t.equals(newValue3))
114                         fail("Failed to verify modifications " + t + " != " + newValue3 + ".");
115                 }
116             });
117         } catch (Throwable e) {
118             e.printStackTrace();
119             fail("Read transaction threw an unexpected exception " + e);
120         }
121
122     }
123 }