KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > module > nodes > AntProjectChildrenTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.apache.tools.ant.module.nodes;
21
22 import java.util.Arrays JavaDoc;
23 import java.util.List JavaDoc;
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 /**
33  * Test children of an Ant project.
34  * @author Jesse Glick
35  */

36 public class AntProjectChildrenTest extends NbTestCase {
37
38     public AntProjectChildrenTest(String JavaDoc name) {
39         super(name);
40     }
41     
42     private FileObject testdir;
43     
44     @Override JavaDoc
45     protected void setUp() throws Exception JavaDoc {
46         super.setUp();
47         testdir = FileUtil.toFileObject(this.getDataDir());
48         assertNotNull("testdir unit/data exists", testdir);
49     }
50     
51     public void testBasicChildren() throws Exception JavaDoc {
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 JavaDoc[] {"described", "-internal", "-internal-described", "main", "undescribed"}),
56             displayNamesForChildrenOf(simple));
57     }
58     
59     public void testImportedChildren() throws Exception JavaDoc {
60         // #44491 caused this to fail.
61
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 JavaDoc[] {"main", "subtarget1", "subtarget2", "subtarget3", "whatever"}),
65             displayNamesForChildrenOf(importing));
66     }
67     
68     private static List JavaDoc<String JavaDoc> 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 JavaDoc<String JavaDoc> displayNamesFor(Node[] nodes) {
75         String JavaDoc[] names = new String JavaDoc[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