1 /* 2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package test.javafx.scene; 27 28 import static org.junit.Assert.assertEquals; 29 import static org.junit.Assert.assertSame; 30 import static org.junit.Assert.assertTrue; 31 32 import java.util.Set; 33 import javafx.scene.Group; 34 import javafx.scene.Node; 35 import javafx.scene.ParentShim; 36 37 import org.junit.Before; 38 import org.junit.Test; 39 40 public class Node_lookup_Test { 41 // Group & #root 42 // / \ 43 // #a .b.c 44 // / \ \ 45 // .d #e .d 46 private Group root, a, bc, d, e, d2; 47 48 @Before public void setup() { 49 root = new Group(); 50 root.setId("root"); 51 a = new Group(); 52 a.setId("a"); 53 d = new Group(); 54 d.getStyleClass().add("d"); 55 e = new Group(); 56 e.setId("e"); 57 bc = new Group(); 58 bc.getStyleClass().addAll("b", "c"); 59 d2 = new Group(); 60 d2.getStyleClass().add("d"); 61 ParentShim.getChildren(root).addAll(a, bc); 62 ParentShim.getChildren(a).addAll(d, e); 63 ParentShim.getChildren(bc).addAll(d2); 64 } 65 66 @Test public void quickTest() { 67 Node found = root.lookup("Group"); 68 assertSame(root, found); 69 70 found = root.lookup("#a"); 71 assertSame(a, found); 72 73 found = root.lookup("#a > .d"); 74 assertSame(d, found); 75 76 found = root.lookup("#e"); 77 assertSame(e, found); 78 79 found = root.lookup(".b .d"); 80 assertSame(d2, found); 81 82 found = root.lookup(".c .d"); 83 assertSame(d2, found); 84 85 found = root.lookup(".b"); 86 assertSame(bc, found); 87 } 88 89 @Test public void lookupAllTest() { 90 Set<Node> nodes = root.lookupAll("#a"); 91 assertEquals(1, nodes.size()); 92 assertTrue(nodes.contains(a)); 93 94 nodes = root.lookupAll(".d"); 95 assertEquals(2, nodes.size()); 96 assertTrue(nodes.contains(d)); 97 assertTrue(nodes.contains(d2)); 98 } 99 }