]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/getSingleObject/GetSingleObjectTest23.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 / GetSingleObjectTest23.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.simantics.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.WriteGraph;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.db.exception.NoSingleResultException;
19 import org.simantics.db.testing.base.WriteReadTest;
20
21 /**
22  * Tests cases where a non-functional relation uses
23  * {@link ReadGraph#getSingleObject(org.simantics.db.Resource, org.simantics.db.Resource)}
24  * with > 1 objects.
25  * 
26  * <p>
27  * Should throw {@link NoSingleResultException}, at the time of writing this
28  * test, AsyncBarrierImpl refcounting is trashed and DB client is stuck.
29  */
30 public class GetSingleObjectTest23 extends WriteReadTest {
31         private Resource subject1;
32         private Resource relation1;
33         private Resource object1;
34
35         @Override
36         protected void write(WriteGraph graph) throws DatabaseException {
37
38                 relation1 = graph.newResource();
39                 graph.claim(relation1, L0.SubrelationOf, L0.IsRelatedTo);
40
41                 //Resource rel2 = graph.newResource();
42                 //graph.claim(rel2, L0.SubrelationOf, relation1);
43
44                 subject1 = graph.newResource();
45                 graph.claim(subject1, L0.InstanceOf, L0.Entity);
46
47                 object1 = graph.newResource();
48                 Resource o2 = graph.newResource();
49
50                 graph.claim(subject1, relation1, object1);
51                 graph.claim(subject1, relation1, o2);
52         }
53
54         @Override
55         protected void read(ReadGraph graph) throws DatabaseException {
56                 try {
57
58                         Resource result = graph.getSingleObject(subject1, relation1);
59                         assertNotNull("Null not allowed", result);
60                         assertFalse("Wrong object was returned", (object1.equals(result)));
61
62                 } catch (NoSingleResultException e) {
63                         //System.out.println("Read transaction threw an expected exception "
64                         //              + e);
65                         return;
66                 } catch (Throwable e) {
67                         fail("Read transaction threw an unexpected exception " + e);
68                 }
69                 fail("Should throw");
70
71                 /*
72                  * try {
73                  * 
74                  * graph.claim(subject1, relation1, relation1);
75                  * 
76                  * } catch (Throwable e) {
77                  * fail("Write transaction threw an unknown exception " + e); }
78                  */
79         }
80
81 }