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.scenegraph.tests;
14 import static junit.framework.Assert.assertSame;
16 import java.util.ArrayList;
17 import java.util.List;
18 import java.util.UUID;
19 import java.util.concurrent.CyclicBarrier;
20 import java.util.concurrent.Semaphore;
21 import java.util.concurrent.atomic.AtomicBoolean;
23 import org.junit.Test;
24 import org.simantics.scenegraph.INode;
25 import org.simantics.scenegraph.ParentNode;
26 import org.simantics.scenegraph.g2d.G2DParentNode;
27 import org.simantics.scenegraph.g2d.G2DSceneGraph;
28 import org.simantics.scenegraph.g2d.nodes.DataNode;
29 import org.simantics.scenegraph.g2d.nodes.NavigationNode;
30 import org.simantics.scenegraph.utils.NodeUtil;
34 * @author Tuukka Lehtonen
36 public class LookupServiceTests {
38 AtomicBoolean endTest;
39 CyclicBarrier startBarrier;
42 G2DSceneGraph root = new G2DSceneGraph();
43 List<INode> nodes = new ArrayList<INode>();
44 List<String> nodeIds = new ArrayList<String>();
45 List<String> mappedIds = new ArrayList<String>();
47 List<Throwable> errors = new ArrayList<Throwable>();
50 <T extends INode> T addAndMapNode(ParentNode<?> parent, String id, Class<T> clazz) {
51 T node = parent.addNode(id, clazz);
54 NodeUtil.map(node, id);
58 <T extends INode> T addNode(ParentNode<?> parent, String id, Class<T> clazz) {
59 T node = parent.addNode(id, clazz);
65 <T extends INode> T addNode(ParentNode<?> parent, Class<T> clazz) {
66 return addNode(parent, UUID.randomUUID().toString(), clazz);
70 public void testLookup() throws Exception {
71 NavigationNode nav = addAndMapNode(root, "navigation", NavigationNode.class);
72 DataNode data = addAndMapNode(root, "data", DataNode.class);
73 G2DParentNode elements = addAndMapNode(nav, "elements", G2DParentNode.class);
74 @SuppressWarnings("unused")
75 G2DParentNode ghosts = addAndMapNode(nav, "ghosts", G2DParentNode.class);
78 assertSame(nav, root.lookupNode("navigation"));
79 assertSame(data, root.lookupNode("data"));
80 assertSame(nav, NodeUtil.lookup(nav, "navigation"));
81 assertSame(data, NodeUtil.lookup(data, "data"));
83 String id1 = UUID.randomUUID().toString();
84 String id2 = UUID.randomUUID().toString();
85 String id3_1 = UUID.randomUUID().toString();
86 String id3_2 = UUID.randomUUID().toString();
87 String id4 = UUID.randomUUID().toString();
88 G2DParentNode e1 = addAndMapNode(elements, id1, G2DParentNode.class);
89 G2DParentNode e2 = addAndMapNode(elements, id2, G2DParentNode.class);
90 G2DParentNode e3 = addNode(elements, G2DParentNode.class);
91 G2DParentNode e3_1 = addAndMapNode(e3, id3_1, G2DParentNode.class);
92 G2DParentNode e3_2 = addAndMapNode(e3, id3_2, G2DParentNode.class);
93 G2DParentNode e4 = addAndMapNode(elements, id4, G2DParentNode.class);
95 assertSame(e1, NodeUtil.lookup(e1, id1));
96 assertSame(e2, NodeUtil.lookup(e2, id2));
97 assertSame(e3_1, NodeUtil.lookup(e3_1, id3_1));
98 assertSame(e3_2, NodeUtil.lookup(e3_2, id3_2));
99 assertSame(e4, NodeUtil.lookup(e4, id4));