]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/regression/bugs/Issue3288Test2.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / regression / bugs / Issue3288Test2.java
1 package org.simantics.db.tests.regression.bugs;
2 /*******************************************************************************
3  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4  * in Industry THTH ry.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  *     VTT Technical Research Centre of Finland - initial API and implementation
12  *******************************************************************************/
13
14
15 import java.util.Collection;
16 import java.util.HashSet;
17 import java.util.Set;
18
19 import org.junit.Test;
20 import org.simantics.db.ReadGraph;
21 import org.simantics.db.Resource;
22 import org.simantics.db.common.request.ReadRequest;
23 import org.simantics.db.exception.DatabaseException;
24 import org.simantics.db.testing.base.ExistingDatabaseTest;
25 import org.simantics.layer0.Layer0;
26 /**
27  * See Issue3288Test1.
28  *
29  */
30 public class Issue3288Test2 extends ExistingDatabaseTest {
31     @Test
32     public void test() throws DatabaseException {
33         getSession().syncRequest(new Read());
34     }
35     private static class Read extends ReadRequest {
36         @Override
37         public void run(ReadGraph graph) throws DatabaseException {
38             Layer0 l0 = Layer0.getInstance(graph);
39             Resource rl = graph.getRootLibrary();
40             Collection<Resource> rs = graph.getObjects(rl, l0.IsRelatedTo);
41             Set<Resource> done = new HashSet<Resource>();
42             Set<Resource> todo = new HashSet<Resource>();
43             for (Resource r : rs)
44                 todo.add(r);
45             while (!todo.isEmpty()) {
46                 Resource r = todo.iterator().next();
47                 todo.remove(r);
48                 done.add(r);
49                 Collection<Resource> rs2 = graph.getObjects(r, l0.IsRelatedTo);
50                 for (Resource rr : rs2)
51                     if (!done.contains(rr))
52                         todo.add(rr);
53             }
54             System.out.println("" + done.size());
55         }
56     }
57 }