1 19 20 package org.apache.tools.ant.module.nodes; 21 22 import java.util.Arrays ; 23 import java.util.List ; 24 import org.apache.tools.ant.module.nodes.AntProjectChildren; 25 import org.apache.tools.ant.module.xml.AntProjectSupport; 26 import org.netbeans.junit.NbTestCase; 27 import org.openide.filesystems.FileObject; 28 import org.openide.filesystems.FileUtil; 29 import org.openide.nodes.Children; 30 import org.openide.nodes.Node; 31 32 36 public class AntProjectChildrenTest extends NbTestCase { 37 38 public AntProjectChildrenTest(String name) { 39 super(name); 40 } 41 42 private FileObject testdir; 43 44 @Override 45 protected void setUp() throws Exception { 46 super.setUp(); 47 testdir = FileUtil.toFileObject(this.getDataDir()); 48 assertNotNull("testdir unit/data exists", testdir); 49 } 50 51 public void testBasicChildren() throws Exception { 52 FileObject simple = testdir.getFileObject("targetlister/simple.xml"); 53 assertNotNull("simple.xml found", simple); 54 assertEquals("correct children of simple.xml", 55 Arrays.asList(new String [] {"described", "-internal", "-internal-described", "main", "undescribed"}), 56 displayNamesForChildrenOf(simple)); 57 } 58 59 public void testImportedChildren() throws Exception { 60 FileObject importing = testdir.getFileObject("targetlister/importing.xml"); 62 assertNotNull("importing.xml found", importing); 63 assertEquals("correct children of importing.xml", 64 Arrays.asList(new String [] {"main", "subtarget1", "subtarget2", "subtarget3", "whatever"}), 65 displayNamesForChildrenOf(importing)); 66 } 67 68 private static List <String > displayNamesForChildrenOf(FileObject fo) { 69 Children ch = new AntProjectChildren(new AntProjectSupport(fo)); 70 Node[] nodes = ch.getNodes(true); 71 return displayNamesFor(nodes); 72 } 73 74 private static List <String > displayNamesFor(Node[] nodes) { 75 String [] names = new String [nodes.length]; 76 for (int i = 0; i < nodes.length; i++) { 77 names[i] = nodes[i].getDisplayName(); 78 } 79 return Arrays.asList(names); 80 } 81 82 } 83 | Popular Tags |