KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > project > ui > support > NodeFactorySupportTest


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.netbeans.spi.project.ui.support;
21
22 import com.sun.org.apache.bcel.internal.generic.LOOKUPSWITCH;
23 import junit.framework.TestCase;
24 import junit.framework.*;
25 import java.io.IOException JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Arrays JavaDoc;
28 import java.util.Collections JavaDoc;
29 import java.util.Enumeration JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.Map JavaDoc;
34 import javax.swing.event.ChangeEvent JavaDoc;
35 import javax.swing.event.ChangeListener JavaDoc;
36 import org.netbeans.api.project.Project;
37 import org.netbeans.junit.MockServices;
38 import org.openide.ErrorManager;
39 import org.openide.cookies.InstanceCookie;
40 import org.openide.filesystems.FileAttributeEvent;
41 import org.openide.filesystems.FileChangeListener;
42 import org.openide.filesystems.FileEvent;
43 import org.openide.filesystems.FileObject;
44 import org.openide.filesystems.FileRenameEvent;
45 import org.openide.filesystems.Repository;
46 import org.openide.loaders.DataFolder;
47 import org.openide.loaders.DataObject;
48 import org.openide.loaders.DataObjectNotFoundException;
49 import org.openide.loaders.FolderLookup;
50 import org.openide.loaders.InstanceDataObject;
51 import org.openide.nodes.AbstractNode;
52 import org.openide.nodes.Children;
53 import org.openide.nodes.Node;
54 import org.openide.util.Lookup;
55 import org.openide.util.LookupEvent;
56 import org.openide.util.LookupListener;
57 import org.openide.util.lookup.AbstractLookup;
58 import org.openide.util.lookup.InstanceContent;
59
60 /**
61  *
62  * @author mkleint
63  */

64 public class NodeFactorySupportTest extends TestCase {
65     
66     public NodeFactorySupportTest(String JavaDoc testName) {
67         super(testName);
68     }
69
70     protected void setUp() throws Exception JavaDoc {
71     }
72
73     protected void tearDown() throws Exception JavaDoc {
74     }
75
76     /**
77      * Test of createCompositeChildren method, of class org.netbeans.spi.project.ui.support.NodeFactorySupport.
78      */

79     public void testCreateCompositeChildren() {
80         System.out.println("createCompositeChildren");
81         InstanceContent ic = new InstanceContent();
82         TestDelegates dels = new TestDelegates(ic);
83         Node node1 = new AbstractNode(Children.LEAF);
84         Node node2 = new AbstractNode(Children.LEAF);
85         Node node3 = new AbstractNode(Children.LEAF);
86         Node node4 = new AbstractNode(Children.LEAF);
87         node1.setName("node1");
88         node2.setName("node2");
89         node3.setName("node3");
90         node4.setName("node4");
91         NodeFactory fact1 = new TestNodeFactory(node1);
92         NodeFactory fact2 = new TestNodeFactory(node2);
93         NodeFactory fact3 = new TestNodeFactory(node3);
94         NodeFactory fact4 = new TestNodeFactory(node4);
95         List JavaDoc col = new ArrayList JavaDoc();
96         col.add(fact1);
97         col.add(fact2);
98         ic.set(col, null);
99         
100         Node[] nds = dels.getNodes();
101         assertEquals(nds[0], node1);
102         assertEquals(nds[1], node2);
103         
104         col.add(0, fact4);
105         col.add(fact3);
106         col.remove(fact2);
107         ic.set(col, null);
108         nds = dels.getNodes();
109         assertEquals(nds[0], node4);
110         assertEquals(nds[1], node1);
111         assertEquals(nds[2], node3);
112         
113     }
114
115    private class TestNodeFactory implements NodeFactory {
116        
117        Node node;
118        public TestNodeFactory(Node node) {
119            this.node = node;
120        }
121         public NodeList createNodes(Project p) {
122             return NodeFactorySupport.fixedNodeList(new Node[] {node});
123         }
124    }
125    
126    private class TestDelegates extends NodeFactorySupport.DelegateChildren {
127        public AbstractLookup.Content content;
128        TestDelegates(AbstractLookup.Content cont) {
129            super(null, null);
130            content = cont;
131        }
132        
133        protected Lookup createLookup() {
134            return new AbstractLookup(content);
135        }
136        
137        public void addNotify() {
138            super.addNotify();
139        }
140        
141        public void removeNotify() {
142            super.removeNotify();
143        }
144    }
145     
146 }
147
Popular Tags