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 graph.forObjectSet(graph.getRootLibrary(), relation, new AsyncSetListener<Resource>() {
51 public void add(AsyncReadGraph graph, Resource result) {
58 public void remove(AsyncReadGraph graph, Resource result) {
65 public void exception(AsyncReadGraph graph, Throwable t) {
70 public boolean isDisposed() {
79 session.syncRequest(new WriteRequest() {
82 public void perform(WriteGraph g) throws DatabaseException {
84 Layer0 b = Layer0.getInstance(g);
86 g.claim(g.getRootLibrary(), relation, b.Abstract);
92 assert(adds == 1 && removes == 0);
94 session.syncRequest(new WriteRequest() {
97 public void perform(WriteGraph g) throws DatabaseException {
99 Layer0 b = Layer0.getInstance(g);
101 g.claim(g.getRootLibrary(), relation, b.Abstract);
107 assert(adds == 1 && removes == 0);
109 session.syncRequest(new WriteRequest() {
112 public void perform(WriteGraph g) throws DatabaseException {
114 Layer0 b = Layer0.getInstance(g);
116 g.deny(g.getRootLibrary(), relation, b.Abstract);
122 assert(adds == 1 && removes == 1);
124 session.syncRequest(new WriteRequest() {
127 public void perform(WriteGraph g) throws DatabaseException {
129 Layer0 b = Layer0.getInstance(g);
131 g.deny(g.getRootLibrary(), relation, b.Abstract);
137 assert(adds == 1 && removes == 1);
139 session.syncRequest(new WriteRequest() {
142 public void perform(WriteGraph g) throws DatabaseException {
144 Layer0 b = Layer0.getInstance(g);
146 g.claim(g.getRootLibrary(), relation, b.Abstract);
147 g.deny(g.getRootLibrary(), relation, b.Abstract);
153 assert(adds == 1 && removes == 1);
155 if(exception != null) {
156 fail("Write transaction threw and exception (" + exception.getMessage() + ") which was not passed through ");