]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest8.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 / SyncAsyncSyncTest8.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.HashSet;
15 import java.util.Set;
16
17 import org.junit.Test;
18 import org.simantics.databoard.Bindings;
19 import org.simantics.db.ReadGraph;
20 import org.simantics.db.Resource;
21 import org.simantics.db.Session;
22 import org.simantics.db.common.primitiverequest.ForObjectSet;
23 import org.simantics.db.exception.DatabaseException;
24 import org.simantics.db.procedure.SyncSetListener;
25 import org.simantics.db.testing.base.ExistingDatabaseTest;
26 import org.simantics.layer0.Layer0;
27
28 public class SyncAsyncSyncTest8 extends ExistingDatabaseTest {
29         
30         @Test
31         public void test() throws Exception {
32                 
33                 Session session = getSession();
34                 
35                 final Set<String> expected = new HashSet<String>();
36                 
37         session.syncRequest(new TestReadRequest() {
38
39             @Override
40             public void run(ReadGraph g) throws DatabaseException {
41
42                 final Layer0 b = Layer0.getInstance(g);
43                 
44                 g.syncRequest(new ForObjectSet(g.getRootLibrary(), b.InstanceOf, new SyncSetListener<Resource>() {
45
46                     @Override
47                     public void add(ReadGraph graph, Resource type) throws DatabaseException {
48                         
49                         graph.syncRequest(new ForObjectSet(type, b.Inherits, new SyncSetListener<Resource>() {
50
51                             @Override
52                             public void add(ReadGraph graph, Resource result) throws DatabaseException {
53                                 
54                                 expected.remove(graph.getRelatedValue(result, b.HasName, Bindings.STRING));
55                                 
56                             }
57
58                             @Override
59                             public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException {
60                                 assert(false);
61                             }
62
63                             @Override
64                             public void remove(ReadGraph graph, Resource result) throws DatabaseException {
65                                 assert(false);
66                             }
67
68                             @Override
69                             public boolean isDisposed() {
70                                 return false;
71                             }
72                             
73                         }));
74                         
75                     }
76
77                     @Override
78                     public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException {
79                         assert(false);
80                     }
81
82                     @Override
83                     public void remove(ReadGraph graph, Resource result) throws DatabaseException {
84                         assert(false);
85                     }
86
87                     @Override
88                     public boolean isDisposed() {
89                         return false;
90                     }
91                     
92                 }));
93                 
94             }
95             
96         });
97         
98         assert(expected.isEmpty());
99         
100         }
101
102 }