KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.beans.BeanInfo JavaDoc;
23
24 import org.openide.util.Lookup;
25 import org.netbeans.spi.looks.*;
26
27 import org.netbeans.junit.*;
28
29 public class FilterLookMaskTest extends NbTestCase {
30
31     private static final String JavaDoc MSSG_UNEXPECTED_EXCEPTION = "Unexpected exception caught : ";
32
33     // Filter look to test on
34
private Look filterLook;
35
36     // Look which will be filtered
37
private SampleLook sampleLook;
38
39     // Represented object
40
private SampleRepObject representedObject;
41
42     // Golden values
43
private GoldenValue[] goldenValues;
44     
45     // Results
46
private GoldenValue[] results;
47     
48     public static void main(java.lang.String JavaDoc[] args) {
49         junit.textui.TestRunner.run(suite());
50     }
51     
52     public static NbTest suite() {
53         NbTestSuite suite = new NbTestSuite(FilterLookMaskTest.class);
54         
55         return suite;
56     }
57     
58     // Methods of testCase -----------------------------------------------------
59

60     public FilterLookMaskTest( String JavaDoc name ) {
61         super( name );
62     }
63     
64     protected void setUp() throws Exception JavaDoc {
65         super.setUp();
66
67         sampleLook = new SampleLook( "FilterLookTest" );
68         //filter = Looks.filter( sampleLook, ProxyLook.ALL_METHODS );
69
goldenValues = GoldenValue.createGoldenValues();
70         representedObject = new SampleRepObject( goldenValues );
71         
72         
73         // LookNode n = new LookNode (new Object (), sampleLook);
74
}
75     
76     protected void tearDown() throws Exception JavaDoc {
77
78         filterLook = null;
79         sampleLook = null;
80         
81         super.tearDown();
82     }
83       
84     // Test methods ------------------------------------------------------------
85

86     // Tests whether the constants defined in the right order and whether
87
// there is no owerflow.
88
/*
89     public void testMaskOrder() {
90         System.out.println("testMaskOrder");
91         
92         // Add your test code below by replacing the default call to fail.
93         
94         for ( int i = 0, j = 1; i < testingItems.length; i++ ) {
95             if ( testingItems[i].mask != j ) {
96                 fail("Ordering failed : " + i );
97             }
98             j *= 2;
99         }
100     }
101      */

102 /*
103     public void test_ATTACH_TO() {
104         System.out.println("test_ATTACH_TO");
105         
106         // Add your test code below by replacing the default call to fail.
107         int failIndex = doTestingWithMask( ProxyLook.ATTACH_TO );
108         if ( failIndex > -1 ) {
109             fail( getFailMessage( failIndex) );
110         }
111     }
112 */

113
114     public void test_GET_DISPLAY_NAME() {
115         String JavaDoc message = doTestingWithMask( ProxyLook.GET_DISPLAY_NAME );
116         assertTrue( message == null ? "" : message, message == null );
117     }
118     
119     public void test_GET_NAME() {
120         String JavaDoc message = doTestingWithMask( ProxyLook.GET_NAME );
121         assertTrue( message == null ? "" : message, message == null );
122     }
123     
124     public void test_RENAME() {
125         String JavaDoc message = doTestingWithMask( ProxyLook.RENAME );
126         assertTrue( message == null ? "" : message, message == null );
127     }
128     
129     public void test_GET_SHORT_DESCRIPTION () {
130         String JavaDoc message = doTestingWithMask( ProxyLook.GET_SHORT_DESCRIPTION );
131         assertTrue( message == null ? "" : message, message == null );
132     }
133     
134     public void test_GET_ICON() {
135         String JavaDoc message = doTestingWithMask( ProxyLook.GET_ICON );
136         assertTrue( message == null ? "" : message, message == null );
137     }
138     
139     public void test_GET_OPENED_ICON () {
140         String JavaDoc message = doTestingWithMask( ProxyLook.GET_OPENED_ICON );
141         assertTrue( message == null ? "" : message, message == null );
142     }
143     
144     public void test_GET_HELP_CTX () {
145         String JavaDoc message = doTestingWithMask( ProxyLook.GET_HELP_CTX );
146         assertTrue( message == null ? "" : message, message == null );
147     }
148     
149     public void test_GET_CHILD_OBJECTS () {
150         String JavaDoc message = doTestingWithMask( ProxyLook.GET_CHILD_OBJECTS );
151         assertTrue( message == null ? "" : message, message == null );
152     }
153     
154     public void test_GET_NEW_TYPES () {
155         String JavaDoc message = doTestingWithMask( ProxyLook.GET_NEW_TYPES );
156         assertTrue( message == null ? "" : message, message == null );
157     }
158     
159     public void test_GET_ACTIONS () {
160         String JavaDoc message = doTestingWithMask( ProxyLook.GET_ACTIONS );
161         assertTrue( message == null ? "" : message, message == null );
162     }
163     
164     public void test_GET_CONTEXT_ACTIONS () {
165         String JavaDoc message = doTestingWithMask( ProxyLook.GET_CONTEXT_ACTIONS );
166         assertTrue( message == null ? "" : message, message == null );
167     }
168     
169     public void test_GET_DEFAULT_ACTION () {
170         String JavaDoc message = doTestingWithMask( ProxyLook.GET_DEFAULT_ACTION );
171         assertTrue( message == null ? "" : message, message == null );
172     }
173     
174     public void test_GET_PROPERTY_SETS () {
175         String JavaDoc message = doTestingWithMask( ProxyLook.GET_PROPERTY_SETS );
176         assertTrue( message == null ? "" : message, message == null );
177     }
178     
179     public void test_GET_CUSTOMIZER () {
180         String JavaDoc message = doTestingWithMask( ProxyLook.GET_CUSTOMIZER );
181         assertTrue( message == null ? "" : message, message == null );
182     }
183     
184     public void test_CAN_RENAME () {
185         String JavaDoc message = doTestingWithMask( ProxyLook.CAN_RENAME );
186         assertTrue( message == null ? "" : message, message == null );
187     }
188     
189     public void test_CAN_DESTROY () {
190         String JavaDoc message = doTestingWithMask( ProxyLook.CAN_DESTROY );
191         assertTrue( message == null ? "" : message, message == null );
192     }
193     
194     public void test_CAN_COPY () {
195         String JavaDoc message = doTestingWithMask( ProxyLook.CAN_COPY );
196         assertTrue( message == null ? "" : message, message == null );
197     }
198     
199     public void test_CAN_CUT () {
200         String JavaDoc message = doTestingWithMask( ProxyLook.CAN_CUT );
201         assertTrue( message == null ? "" : message, message == null );
202     }
203     
204     public void test_GET_PASTE_TYPES () {
205         String JavaDoc message = doTestingWithMask( ProxyLook.GET_PASTE_TYPES );
206         assertTrue( message == null ? "" : message, message == null );
207     }
208     
209     public void test_GET_DROP_TYPE () {
210         String JavaDoc message = doTestingWithMask( ProxyLook.GET_DROP_TYPE );
211         assertTrue( message == null ? "" : message, message == null );
212     }
213     
214     public void test_CLIPBOARD_COPY () {
215         String JavaDoc message = doTestingWithMask( ProxyLook.CLIPBOARD_COPY );
216         assertTrue( message == null ? "" : message, message == null );
217     }
218     
219     public void test_CLIPBOARD_CUT () {
220         String JavaDoc message = doTestingWithMask( ProxyLook.CLIPBOARD_CUT );
221         assertTrue( message == null ? "" : message, message == null );
222     }
223     
224     public void test_DRAG () {
225         String JavaDoc message = doTestingWithMask( ProxyLook.DRAG );
226         assertTrue( message == null ? "" : message, message == null );
227     }
228     
229     public void test_DESTROY () {
230         String JavaDoc message = doTestingWithMask( ProxyLook.DESTROY );
231         assertTrue( message == null ? "" : message, message == null );
232     }
233     
234     // Private methods ---------------------------------------------------------
235

236     private String JavaDoc doTestingWithMask( long mask ) {
237         filterLook = Looks.filter( "TestFilter", sampleLook, mask );
238         
239         try {
240             results = readResults();
241         }
242         catch ( Exception JavaDoc e ) {
243             return MSSG_UNEXPECTED_EXCEPTION;
244         }
245         
246         for( int i = 0; i < goldenValues.length; i ++ ) {
247             
248             if ( goldenValues[i].key == ProxyLook.GET_LOOKUP_ITEMS ) {
249                 continue;
250             }
251             
252             Object JavaDoc result = GoldenValue.get( goldenValues[i].key, results );
253             
254             // Wee need to replace Boolean.FALSE with null
255
// to test properly. Notice that because of this the golden
256
// values in SampleRepObject should return true from all
257
// methods of return type boolean
258
if ( result instanceof Boolean JavaDoc && Boolean.FALSE.equals( result ) ) {
259                 result = null;
260             }
261             
262             if ( ( ( goldenValues[i].key & mask ) > 0 && result == null ) ||
263                  ( ( goldenValues[i].key & mask ) == 0 && result != null )) {
264                 return getFailMessage( i );
265             }
266         }
267         
268         return null;
269     }
270
271     private static final Lookup NO_LOOKUP = null; // PENDING
272

273     private GoldenValue[] readResults() throws Exception JavaDoc {
274          
275         return new GoldenValue[] {
276
277             new GoldenValue(
278                 ProxyLook.GET_DISPLAY_NAME,
279                 filterLook.getDisplayName( representedObject, NO_LOOKUP ) ),
280
281             new GoldenValue(
282                 ProxyLook.GET_NAME,
283                 filterLook.getName( representedObject, NO_LOOKUP ) ),
284
285             // Set name
286

287             new GoldenValue(
288                 ProxyLook.GET_SHORT_DESCRIPTION,
289                 filterLook.getShortDescription( representedObject, NO_LOOKUP ) ),
290
291             new GoldenValue(
292                 ProxyLook.GET_ICON,
293                 filterLook.getIcon( representedObject, BeanInfo.ICON_COLOR_16x16, NO_LOOKUP ) ),
294
295             new GoldenValue(
296                 ProxyLook.GET_OPENED_ICON,
297                 filterLook.getOpenedIcon( representedObject, BeanInfo.ICON_COLOR_16x16, NO_LOOKUP ) ),
298
299             new GoldenValue(
300                 ProxyLook.GET_HELP_CTX,
301                 filterLook.getHelpCtx( representedObject, NO_LOOKUP ) ),
302
303             new GoldenValue(
304                 ProxyLook.GET_CHILD_OBJECTS,
305                 filterLook.getChildObjects( representedObject, NO_LOOKUP ) ),
306
307             new GoldenValue(
308                 ProxyLook.GET_NEW_TYPES,
309                 filterLook.getNewTypes( representedObject, NO_LOOKUP ) ),
310
311             new GoldenValue(
312                 ProxyLook.GET_ACTIONS,
313                 filterLook.getActions( representedObject, NO_LOOKUP ) ),
314
315             new GoldenValue(
316                 ProxyLook.GET_CONTEXT_ACTIONS,
317                 filterLook.getContextActions( representedObject, NO_LOOKUP ) ),
318
319             new GoldenValue(
320                 ProxyLook.GET_DEFAULT_ACTION,
321                 filterLook.getDefaultAction( representedObject, NO_LOOKUP ) ),
322
323             new GoldenValue(
324                 ProxyLook.GET_PROPERTY_SETS,
325                 filterLook.getPropertySets( representedObject, NO_LOOKUP ) ),
326
327             new GoldenValue(
328                 ProxyLook.GET_CUSTOMIZER,
329                 filterLook.getCustomizer( representedObject, NO_LOOKUP ) ),
330
331             new GoldenValue(
332                 ProxyLook.HAS_CUSTOMIZER,
333                 new Boolean JavaDoc( filterLook.hasCustomizer( representedObject, NO_LOOKUP ) ) ),
334
335             new GoldenValue(
336                 ProxyLook.CAN_RENAME,
337                 new Boolean JavaDoc( filterLook.canRename( representedObject, NO_LOOKUP ) ) ),
338
339             new GoldenValue(
340                 ProxyLook.CAN_DESTROY,
341                 new Boolean JavaDoc( filterLook.canDestroy( representedObject, NO_LOOKUP ) ) ),
342
343             new GoldenValue(
344                 ProxyLook.CAN_COPY,
345                 new Boolean JavaDoc( filterLook.canCopy( representedObject, NO_LOOKUP ) ) ),
346
347             new GoldenValue(
348                 ProxyLook.CAN_CUT,
349                 new Boolean JavaDoc( filterLook.canCut( representedObject, NO_LOOKUP ) ) ),
350
351             new GoldenValue(
352                 ProxyLook.GET_PASTE_TYPES,
353                 filterLook.getPasteTypes( representedObject, null, NO_LOOKUP ) ),
354
355             new GoldenValue(
356                 ProxyLook.GET_DROP_TYPE,
357                 filterLook.getDropType( representedObject, null, 0, 0, NO_LOOKUP ) ),
358
359             new GoldenValue(
360                 ProxyLook.CLIPBOARD_COPY,
361                 filterLook.clipboardCopy( representedObject, NO_LOOKUP ) ),
362
363             new GoldenValue(
364                 ProxyLook.CLIPBOARD_CUT,
365                 filterLook.clipboardCut( representedObject, NO_LOOKUP ) ),
366
367             new GoldenValue(
368                 ProxyLook.DRAG,
369                 filterLook.drag( representedObject, NO_LOOKUP ) )
370
371              // destroy
372
};
373     }
374     
375     private String JavaDoc getFailMessage( int failIndex ) {
376         return "Failed on method index : " + failIndex + " : " +
377             results[ failIndex ].key + " = " +
378             results[ failIndex ].result;
379     }
380            
381 }
382
Popular Tags