1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.tests.api.readGraph.getSingleObject;
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;
30 * Tests cases where a non-functional relation uses
31 * {@link ReadGraph#getSingleObject(org.simantics.db.Resource, org.simantics.db.Resource)}
35 * Should throw {@link NoSingleResultException}, at the time of writing this
36 * test, AsyncBarrierImpl refcounting is trashed and DB client is stuck.
38 public class GetSingleObjectTest3_bak extends ExistingDatabaseTest {
41 public void testSingleObject() throws Exception {
42 Session session = getSession();
44 final DataContainer<Resource> nonfunctionalRelation = new DataContainer<Resource>();
45 final DataContainer<Resource> subject = new DataContainer<Resource>();
47 session.syncRequest(new WriteRequest() {
49 public void perform(WriteGraph graph) throws DatabaseException {
50 // Use any non-functional relation
51 Layer0 b = Layer0.getInstance(graph);
53 Resource rel = graph.newResource();
54 graph.claim(rel, b.SubrelationOf, b.IsRelatedTo);
56 Resource rel2 = graph.newResource();
57 graph.claim(rel2, b.SubrelationOf, rel);
59 Resource s = graph.newResource();
60 graph.claim(s, b.InstanceOf, b.Entity);
62 Resource o1 = graph.newResource();
63 // Resource o2 = graph.newResource();
65 graph.claim(s, rel, o1);
66 // graph.claim(s, rel, o2);
68 nonfunctionalRelation.set(rel);
72 } catch (Throwable e) {
73 fail("Write transaction threw an unknown exception " + e);
77 session.syncRequest(new Read<Resource>() {
79 public Resource perform(ReadGraph graph) throws DatabaseException {
80 return graph.getSingleObject(subject.get(), nonfunctionalRelation.get());
82 }, new ListenerAdapter<Resource>() {
85 public boolean isDisposed() {
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);
97 System.out.println("################################################");
100 session.syncRequest(new WriteRequest() {
102 public void perform(WriteGraph graph) throws DatabaseException {
103 graph.claim(subject.get(), nonfunctionalRelation.get(), nonfunctionalRelation.get());
106 } catch (Throwable e) {
107 fail("Write transaction threw an unknown exception " + e);