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.request.misc;
14 import java.util.ArrayList;
15 import java.util.Arrays;
17 import org.junit.Test;
18 import org.simantics.db.Resource;
19 import org.simantics.db.WriteGraph;
20 import org.simantics.db.common.primitiverequest.HasStatement;
21 import org.simantics.db.common.request.WriteRequest;
22 import org.simantics.db.common.request.WriteResultRequest;
23 import org.simantics.db.exception.DatabaseException;
24 import org.simantics.db.procedure.Listener;
25 import org.simantics.db.testing.base.ExistingDatabaseTest;
26 import org.simantics.layer0.Layer0;
28 public class CachedQueryDependencies extends ExistingDatabaseTest {
31 public void test() throws Exception {
33 final ArrayList<String> result = new ArrayList<String>();
35 final Layer0 L0 = Layer0.getInstance(getSession());
37 final Resource root = getSession().syncRequest(new WriteResultRequest<Resource>() {
40 public Resource perform(WriteGraph graph) throws DatabaseException {
41 return graph.newResource();
46 getSession().syncRequest(new HasStatement(root, L0.ConsistsOf));
47 getSession().syncRequest(new HasStatement(root, L0.ConsistsOf), new Listener<Boolean>() {
50 public void execute(Boolean value) {
51 if(value) result.add("true");
52 else result.add("false");
56 public void exception(Throwable t) {
60 public boolean isDisposed() {
66 getSession().syncRequest(new WriteRequest() {
69 public void perform(WriteGraph graph) throws DatabaseException {
70 graph.claim(root, L0.ConsistsOf, root);
75 if(!Arrays.equals(result.toArray(new String[0]), new String[] { "false", "true" })) fail("incorrect result " + result);