KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > looks > LookSwitcherLookLookupTest


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.looks;
21
22 import org.openide.nodes.*;
23 import org.netbeans.junit.*;
24 import org.netbeans.spi.looks.*;
25
26 /** The LookSwitcherLook should allow access to the LookNode in all Looks
27  * which are plugged into the same CompositeLook. The access should be
28  * provided using Lookup. This class tests this feature.
29  */

30 public class LookSwitcherLookLookupTest extends NbTestCase {
31
32     private GoldenValue[] gvLeaf1, gvLeaf2, gvLeaf3, gvMid1, gvMid2, gvTop;
33     private SampleRepObject srLeaf1, srLeaf2, srLeaf3, srMid1, srMid2, srTop;
34     private Node node, nodeNonSwitch;
35     /* private MySampleLook sampleLook; */
36     
37     // Methods of testCase -----------------------------------------------------
38

39     public LookSwitcherLookLookupTest(java.lang.String JavaDoc testName) {
40         super(testName);
41     }
42     
43     public static void main(java.lang.String JavaDoc[] args) {
44         junit.textui.TestRunner.run(suite());
45     }
46     
47     public static NbTest suite() {
48         NbTestSuite suite = new NbTestSuite( LookSwitcherLookLookupTest.class );
49         return suite;
50     }
51     
52     protected void setUp() throws Exception JavaDoc {
53         
54         super.setUp();
55         /*
56         // 1. Create hierarchy of SampleRepObjects
57         
58         // LEAF LEVEL
59         gvLeaf1 = new GoldenValue[] {
60             new GoldenValue( Look.GET_NAME, "LEAF_1" )
61         };
62         srLeaf1 = new SampleRepObject( gvLeaf1 );
63         
64         gvLeaf2 = new GoldenValue[] {
65             new GoldenValue( Look.GET_NAME, "LEAF_2" )
66         };
67         srLeaf2 = new SampleRepObject( gvLeaf2 );
68         
69         gvLeaf3 = new GoldenValue[] {
70             new GoldenValue( Look.GET_NAME, "LEAF_3" )
71         };
72         srLeaf3 = new SampleRepObject( gvLeaf3 );
73         
74         // MID LEVEL
75         gvMid1 = new GoldenValue[] {
76             new GoldenValue( Look.GET_NAME, "MID_1" ),
77             new GoldenValue( Look.GET_CHILD_OBJECTS,
78                 Arrays.asList( new Object[] { srLeaf1, srLeaf2 } ) )
79         };
80         srMid1 = new SampleRepObject( gvMid1 );
81         
82         gvMid2 = new GoldenValue[] {
83             new GoldenValue( Look.GET_NAME, "MID_2" ),
84             new GoldenValue( Look.GET_CHILD_OBJECTS,
85                 Arrays.asList( new Object[] { srLeaf3 } ) )
86         };
87         srMid2 = new SampleRepObject( gvMid2 );
88         
89         // TOP LEVEL
90         gvTop = new GoldenValue[] {
91             new GoldenValue( Look.GET_NAME, "TOP" ),
92             new GoldenValue( Look.GET_CHILD_OBJECTS,
93                 Arrays.asList( new Object[] { srMid1, srMid2 } ) )
94         };
95         srTop = new SampleRepObject( gvTop );
96                 
97         
98         // Create composite look and look node for testing
99         //
100         sampleLook = new MySampleLook( "MySample" );
101         Look composite = Looks.composite( "TestComposite",
102             new Look[] { Looks.lookSwitcherLook(), sampleLook } );
103         LookSelector selector = new SampleSelector( composite );
104         node = Looks.node( srTop, composite, selector );
105
106         LookSelector selectorNonSwitch = new SampleSelector( sampleLook );
107         nodeNonSwitch = Looks.node( srTop, sampleLook, selectorNonSwitch );
108          */

109     }
110     
111     protected void tearDown() throws Exception JavaDoc {
112         super.tearDown();
113     }
114     
115     
116     // Test methods ------------------------------------------------------------
117

118     public void testLookup() {
119         fail( "Needs to be modified for the new version" );
120         /*
121         testTree( node );
122          */

123     }
124
125     public void testNonSwitchLookup() {
126         fail( "Needs to be modified for the new version" );
127         /*
128         assertNull ("LookNode isn't found in Lookup if LookNode don't contain LookSwitcherLook.",
129                 nodeNonSwitch.getLookup ().lookup (org.netbeans.modules.looks.LookNode.class));
130
131         // Test children
132         Node children[] = nodeNonSwitch.getChildren().getNodes();
133         
134         for( int i = 0; i < children.length; i++ ) {
135             assertNull ("LookNode isn't found in Lookup if LookNode don't contain LookSwitcherLook.",
136                     children[i].getLookup ().lookup (org.netbeans.modules.looks.LookNode.class));
137         }
138         */

139     }
140         
141     // Innerclasses ------------------------------------------------------------
142

143     private void testTree( Node node ) {
144         fail( "Needs to be modified for the new version" );
145         /*
146         // Test the node
147         String name = node.getName();
148         Lookup.Result result = sampleLook.getResult();
149         Collection c = result.allInstances();
150         assertTrue( "Bad number of instances.", c.size() == 1 );
151         Node n = (Node)c.iterator().next();
152         assertTrue( "Bad Node.", node == n );
153         assertNotNull ("LookNode is found Lookup if LookNode contains LookSwitcherLook",
154                 node.getLookup ().lookup (org.netbeans.modules.looks.LookNode.class));
155
156         // Test children
157         Node children[] = node.getChildren().getNodes();
158         
159         for( int i = 0; i < children.length; i++ ) {
160             testTree( children[i] );
161         }
162         */

163     }
164     
165     /*
166     class MySampleLook extends SampleLook {
167         
168         private Lookup.Result result;
169         
170         MySampleLook( String name ) {
171             super( name );
172         }
173                 
174         public String getName( Look.NodeSubstitute subst ) {
175             result = subst.getLookup().lookup( new Lookup.Template( org.netbeans.modules.looks.LookNode.class ) );
176             return super.getName( subst );
177         }
178         
179         Lookup.Result getResult() {
180             Lookup.Result lastResult = result;
181             result = null;
182             return lastResult;
183         }
184         
185     }
186     */

187     
188 }
189
190
191
Popular Tags