KickJava   Java API By Example, From Geeks To Geeks.

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


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.netbeans.junit.*;
23
24 import java.io.IOException JavaDoc;
25 import javax.swing.Action JavaDoc;
26 import org.openide.nodes.Node;
27 import org.openide.util.HelpCtx;
28
29 import org.openide.util.Lookup;
30
31 import org.netbeans.spi.looks.*;
32 import org.openide.filesystems.FileUtil;
33 import org.openide.filesystems.FileObject;
34 import org.openide.filesystems.Repository;
35 import org.openide.util.actions.NodeAction;
36
37
38 /** Tests whether the DefaultLook returns proper values
39  */

40 public class DefaultLookValuesTest extends TestBaseValues {
41
42     // Methods of testCase -----------------------------------------------------
43

44     public DefaultLookValuesTest(java.lang.String JavaDoc testName) {
45         super(testName);
46     }
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(DefaultLookValuesTest.class);
54         return suite;
55     }
56     
57     protected void setUp() throws Exception JavaDoc {
58         
59         Look look = createLook();
60         setTarget( look, new SampleRepObject(), 1 );
61         setGoldenValues( createGoldenValues() );
62
63         super.setUp();
64     }
65     
66     protected void tearDown() throws Exception JavaDoc {
67         super.tearDown();
68     }
69     
70     
71     // Test methods ------------------------------------------------------------
72

73     /////////////////////////////////////////////////////////////////
74
// //
75
// All methods except one are inherited from: TestBaseValues //
76
// //
77
/////////////////////////////////////////////////////////////////
78

79     public static final class MyAction extends NodeAction {
80         protected void performAction(Node[] activatedNodes) {
81         }
82
83         protected boolean enable(Node[] activatedNodes) {
84             return false;
85         }
86
87         public String JavaDoc getName() {
88             return getClass().getName();
89         }
90
91         public HelpCtx getHelpCtx() {
92             return HelpCtx.DEFAULT_HELP;
93         }
94
95     }
96       
97     public void testGetActions() throws Exception JavaDoc {
98
99         Action JavaDoc[] actions = look.getActions( representedObject, NO_LOOKUP );
100         
101         if ( actions != null ) {
102             fail( MSSG_UNEXPECTED_VALUE_RETURNED + actions );
103         }
104         
105         String JavaDoc folderName = "Looks/Actions/" + look.getClass().getName().replace( '.', '/' ) +
106             "/" + MyAction.class.getName().replace('.', '-') + ".instance";
107         
108         FileObject fo = FileUtil.createData (
109             Repository.getDefault ().getDefaultFileSystem().getRoot(),
110             folderName
111         );
112         
113         actions = look.getActions ( representedObject, NO_LOOKUP );
114         
115         assertNotNull ("Not null", actions);
116         assertEquals ("One action", actions.length, 1);
117         assertTrue ("NewAction", actions[0] instanceof MyAction);
118         
119         fo.delete ();
120     }
121     
122     public void testIconBase() throws Exception JavaDoc {
123         fail( "The test case empty" );
124     }
125     
126     public void testActionBase() throws Exception JavaDoc {
127         fail( "The test case empty" );
128     }
129     
130     // Private helper methods --------------------------------------------------
131

132     private static GoldenValue[] createGoldenValues() {
133         return new GoldenValue[] {
134             new GoldenValue( ProxyLook.GET_DISPLAY_NAME, null ),
135             new GoldenValue( ProxyLook.GET_NAME, null ),
136             // new GoldenValue( ProxyLook.RENAME )
137
new GoldenValue( ProxyLook.GET_SHORT_DESCRIPTION, null ),
138             new GoldenValue( ProxyLook.GET_ICON, null ),
139             new GoldenValue( ProxyLook.GET_OPENED_ICON, null ),
140             new GoldenValue( ProxyLook.GET_HELP_CTX, null ),
141             new GoldenValue( ProxyLook.GET_CHILD_OBJECTS, null ),
142             new GoldenValue( ProxyLook.GET_NEW_TYPES, null ),
143             new GoldenValue( ProxyLook.GET_ACTIONS, null ),
144             new GoldenValue( ProxyLook.GET_CONTEXT_ACTIONS, null ),
145             new GoldenValue( ProxyLook.GET_DEFAULT_ACTION, null ),
146             new GoldenValue( ProxyLook.GET_PROPERTY_SETS, null ),
147             new GoldenValue( ProxyLook.GET_CUSTOMIZER, null ),
148             new GoldenValue( ProxyLook.HAS_CUSTOMIZER, Boolean.FALSE ),
149             new GoldenValue( ProxyLook.CAN_RENAME, Boolean.FALSE ),
150             new GoldenValue( ProxyLook.CAN_DESTROY, Boolean.FALSE ),
151             new GoldenValue( ProxyLook.CAN_COPY, Boolean.FALSE ),
152             new GoldenValue( ProxyLook.CAN_CUT, Boolean.FALSE ),
153             new GoldenValue( ProxyLook.GET_PASTE_TYPES, null ),
154             new GoldenValue( ProxyLook.GET_DROP_TYPE, null ),
155             new GoldenValue( ProxyLook.CLIPBOARD_COPY, null ),
156             new GoldenValue( ProxyLook.CLIPBOARD_CUT, null ),
157             new GoldenValue( ProxyLook.DRAG, null ),
158             new GoldenValue( ProxyLook.GET_LOOKUP_ITEMS, null )
159             // new GoldenValue( ProxyLook.DESTROY )
160
};
161     }
162     
163     private static Look createLook() {
164         return new DefaultLook( "DefaultLookTest" ) {
165                         
166             public void attachTo( Object JavaDoc representedObject ) {
167                 super.attachTo( representedObject );
168                 
169                 if ( representedObject instanceof SampleRepObject ) {
170                     ((SampleRepObject)representedObject).attach();
171                 }
172                 // return new Look.NodeSubstitute( representedObject, this, null / PENDING / );
173

174             }
175             
176             public void rename(Object JavaDoc representedObject, String JavaDoc newName, Lookup env ) {
177                 if ( representedObject instanceof SampleRepObject ) {
178                     ((SampleRepObject)representedObject).setName();
179                 }
180             }
181                         
182             public void destroy(Object JavaDoc representedObject, Lookup env ) throws IOException JavaDoc {
183                if ( representedObject instanceof SampleRepObject ) {
184                     ((SampleRepObject)representedObject).destroy();
185                 }
186             }
187         };
188     }
189 }
190
Popular Tags