]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest3_bak.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / readGraph / getSingleObject / GetSingleObjectTest3_bak.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.readGraph.getSingleObject;
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.procedure.adapter.ListenerAdapter;
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.request.Read;
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 /**
30  * Tests cases where a non-functional relation uses
31  * {@link ReadGraph#getSingleObject(org.simantics.db.Resource, org.simantics.db.Resource)}
32  * with > 1 objects.
33  * 
34  * <p>
35  * Should throw {@link NoSingleResultException}, at the time of writing this
36  * test, AsyncBarrierImpl refcounting is trashed and DB client is stuck.
37  */
38 public class GetSingleObjectTest3_bak extends ExistingDatabaseTest {
39
40         @Test
41     public void testSingleObject() throws Exception {
42         Session session = getSession();
43
44         final DataContainer<Resource> nonfunctionalRelation = new DataContainer<Resource>();
45         final DataContainer<Resource> subject = new DataContainer<Resource>();
46         try {
47             session.syncRequest(new WriteRequest() {
48                 @Override
49                 public void perform(WriteGraph graph) throws DatabaseException {
50                     // Use any non-functional relation
51                     Layer0 b = Layer0.getInstance(graph);
52
53                     Resource rel = graph.newResource();
54                     graph.claim(rel, b.SubrelationOf, b.IsRelatedTo);
55
56                     Resource rel2 = graph.newResource();
57                     graph.claim(rel2, b.SubrelationOf, rel);
58
59                     Resource s = graph.newResource();
60                     graph.claim(s, b.InstanceOf, b.Entity);
61
62                     Resource o1 = graph.newResource();
63 //                    Resource o2 = graph.newResource();
64
65                     graph.claim(s, rel, o1);
66 //                    graph.claim(s, rel, o2);
67
68                     nonfunctionalRelation.set(rel);
69                     subject.set(s);
70                 }
71             });
72         } catch (Throwable e) {
73             fail("Write transaction threw an unknown exception " + e);
74         }
75
76         try {
77             session.syncRequest(new Read<Resource>() {
78                 @Override
79                 public Resource perform(ReadGraph graph) throws DatabaseException {
80                     return graph.getSingleObject(subject.get(), nonfunctionalRelation.get());
81                 }
82             }, new ListenerAdapter<Resource>() {
83
84                                 @Override
85                                 public boolean isDisposed() {
86                                         return false;
87                                 }
88                 
89             });
90         } catch (NoSingleResultException e) {
91             System.out.println("Read transaction threw an expected exception " + e);
92         } catch (Throwable e) {
93             fail("Read transaction threw an unexpected exception " + e);
94         }
95         
96         if (DEBUG)
97             System.out.println("################################################");
98         
99         try {
100             session.syncRequest(new WriteRequest() {
101                 @Override
102                 public void perform(WriteGraph graph) throws DatabaseException {
103                     graph.claim(subject.get(), nonfunctionalRelation.get(), nonfunctionalRelation.get());
104                 }
105             });
106         } catch (Throwable e) {
107             fail("Write transaction threw an unknown exception " + e);
108         }
109         
110     }
111
112 }