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.forObjectSet;
14 import org.junit.Test;
15 import org.simantics.db.AsyncReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.Session;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.common.request.WriteRequest;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.procedure.AsyncSetListener;
22 import org.simantics.db.testing.base.ExistingDatabaseTest;
23 import org.simantics.layer0.Layer0;
25 public class ForObjectSetTest1 extends ExistingDatabaseTest {
27 private Throwable exception;
28 private Resource relation;
30 private int removes = 0;
33 public void testObjectSet() throws Exception {
35 Session session = getSession();
37 session.syncRequest(new WriteRequest() {
40 public void perform(WriteGraph graph) throws DatabaseException {
42 Layer0 b = Layer0.getInstance(graph);
44 relation = graph.newResource();
45 graph.claim(relation, b.SubrelationOf, b.IsRelatedTo);
46 graph.claim(relation, b.InverseOf, relation);
48 session.syncRequest(new TestAsyncReadRequest() {
51 public void run(AsyncReadGraph graph) throws Throwable {
53 graph.forObjectSet(graph.getRootLibrary(), relation, new AsyncSetListener<Resource>() {
56 public void add(AsyncReadGraph graph, Resource result) {
63 public void remove(AsyncReadGraph graph, Resource result) {
70 public void exception(AsyncReadGraph graph, Throwable t) {
75 public boolean isDisposed() {
89 session.syncRequest(new WriteRequest() {
92 public void perform(WriteGraph g) throws DatabaseException {
94 Layer0 b = Layer0.getInstance(g);
96 g.claim(g.getRootLibrary(), relation, b.Abstract);
102 assert(adds == 1 && removes == 0);
104 session.syncRequest(new WriteRequest() {
107 public void perform(WriteGraph g) throws DatabaseException {
109 Layer0 b = Layer0.getInstance(g);
111 g.claim(g.getRootLibrary(), relation, b.Abstract);
117 assert(adds == 1 && removes == 0);
119 session.syncRequest(new WriteRequest() {
122 public void perform(WriteGraph g) throws DatabaseException {
124 Layer0 b = Layer0.getInstance(g);
126 g.deny(g.getRootLibrary(), relation, b.Abstract);
132 assert(adds == 1 && removes == 1);
134 session.syncRequest(new WriteRequest() {
137 public void perform(WriteGraph g) throws DatabaseException {
139 Layer0 b = Layer0.getInstance(g);
141 g.deny(g.getRootLibrary(), relation, b.Abstract);
147 assert(adds == 1 && removes == 1);
149 session.syncRequest(new WriteRequest() {
152 public void perform(WriteGraph g) throws DatabaseException {
154 Layer0 b = Layer0.getInstance(g);
156 g.claim(g.getRootLibrary(), relation, b.Abstract);
157 g.deny(g.getRootLibrary(), relation, b.Abstract);
163 assert(adds == 1 && removes == 1);
165 if(exception != null) {
166 fail("Write transaction threw and exception (" + exception.getMessage() + ") which was not passed through ");