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.regression.bugs;
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.exception.NoSingleResultException;
24 import org.simantics.db.testing.base.ExistingDatabaseTest;
25 import org.simantics.layer0.Layer0;
26 import org.simantics.utils.DataContainer;
29 * @author Tuukka Lehtonen
31 public class SimanticsBug639Test extends ExistingDatabaseTest {
33 public Resource createAssertion(WriteGraph graph, Resource subject, Resource relation, String object) throws DatabaseException {
34 Layer0 L0 = Layer0.getInstance(graph);
35 Resource assertion = graph.newResource();
36 graph.claim(assertion, L0.InstanceOf, null, L0.Assertion);
37 graph.claim(subject, L0.Asserts, assertion);
38 graph.claim(assertion, L0.HasPredicate, relation);
39 Resource value = graph.newResource();
40 graph.claim(value, L0.InstanceOf, null, L0.String);
41 graph.claimValue(value, object);
42 graph.claim(assertion, L0.HasObject, value);
47 public void testTicket646() throws Exception {
49 Session session = getSession();
50 final DataContainer<Resource> subject = new DataContainer<Resource>();
52 session.syncRequest(new WriteRequest() {
54 public void perform(WriteGraph graph) throws DatabaseException {
55 // Use any non-functional relation
56 Layer0 b = Layer0.getInstance(graph);
57 Resource s = graph.newResource();
58 graph.claim(s, b.InstanceOf, b.Entity);
60 createAssertion(graph, s, L0.HasName, "Foo1");
61 createAssertion(graph, s, L0.HasName, "Foo2");
62 createAssertion(graph, s, L0.HasComment, "Comment1");
63 createAssertion(graph, s, L0.HasComment, "Comment2");
68 } catch (Throwable e) {
69 fail("Write transaction threw an unknown exception " + e);
73 session.syncRequest(new ReadRequest() {
75 public void run(ReadGraph graph) throws DatabaseException {
76 Layer0 L0 = Layer0.getInstance(graph);
77 Resource s = subject.get();
78 // Just make sure that these don't crash.
79 assertEquals(graph.getObjects(s, L0.HasComment).size(), 0);
80 assertEquals(graph.getObjects(s, L0.HasName).size(), 0);
83 } catch (Throwable e) {
84 fail("Read transaction threw an unexpected exception " + e);
88 session.syncRequest(new ReadRequest() {
90 public void run(ReadGraph graph) throws DatabaseException {
91 Layer0 L0 = Layer0.getInstance(graph);
92 Resource s = subject.get();
93 graph.getRelatedValue(s, L0.HasName, Bindings.STRING);
96 } catch (NoSingleResultException e) {
98 } catch (Throwable e) {
99 fail("Read transaction threw an unexpected exception " + e);