]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/CachedQueryDependencies.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / request / misc / CachedQueryDependencies.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.tests.api.request.misc;
13
14 import java.util.ArrayList;
15 import java.util.Arrays;
16
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;
27
28 public class CachedQueryDependencies extends ExistingDatabaseTest {
29         
30         @Test
31         public void test() throws Exception {
32                 
33                 final ArrayList<String> result = new ArrayList<String>();
34                 
35                 final Layer0 L0 = Layer0.getInstance(getSession());
36
37                 final Resource root = getSession().syncRequest(new WriteResultRequest<Resource>() {
38
39                         @Override
40                         public Resource perform(WriteGraph graph) throws DatabaseException {
41                                 return graph.newResource();
42                         }
43                         
44                 });
45                 
46                 getSession().syncRequest(new HasStatement(root, L0.ConsistsOf));                
47                 getSession().syncRequest(new HasStatement(root, L0.ConsistsOf), new Listener<Boolean>() {
48
49                         @Override
50                         public void execute(Boolean value) {
51                                 if(value) result.add("true");
52                                 else result.add("false");
53                         }
54
55                         @Override
56                         public void exception(Throwable t) {
57                         }
58
59                         @Override
60                         public boolean isDisposed() {
61                                 return false;
62                         }
63                         
64                 });             
65                 
66                 getSession().syncRequest(new WriteRequest() {
67
68                         @Override
69                         public void perform(WriteGraph graph) throws DatabaseException {
70                                 graph.claim(root, L0.ConsistsOf, root);
71                         }
72                         
73                 });
74                 
75                 if(!Arrays.equals(result.toArray(new String[0]), new String[] { "false", "true" })) fail("incorrect result " + result);
76
77         }
78
79 }