KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > settings > convertors > SerialDataNodeTest


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 2002 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.settings.convertors;
21
22 import org.netbeans.junit.NbTestCase;
23 import org.openide.cookies.InstanceCookie;
24 import org.openide.filesystems.FileObject;
25 import org.openide.filesystems.FileSystem;
26 import org.openide.loaders.DataObject;
27 import org.openide.modules.ModuleInfo;
28 import org.openide.nodes.Node;
29 import org.openide.util.Lookup;
30
31 /**
32  *
33  * @author Jan Pokorsky
34  */

35 public class SerialDataNodeTest extends NbTestCase {
36
37     private FileSystem sfs;
38
39     /** Creates a new instance of SerialDataNodeTest */
40     public SerialDataNodeTest(String JavaDoc name) {
41         super(name);
42     }
43     
44     protected void setUp() throws Exception JavaDoc {
45         super.setUp();
46         Lookup.getDefault().lookup(ModuleInfo.class);
47         sfs = org.openide.filesystems.Repository.getDefault().getDefaultFileSystem();
48     }
49     
50     public void testDisplayName() throws Exception JavaDoc {
51         String JavaDoc res = "Settings/org-netbeans-modules-settings-convertors-testDisplayName.settings";
52         FileObject fo = sfs.findResource(res);
53         assertNotNull(res, fo);
54         assertNull("name", fo.getAttribute("name"));
55         
56         DataObject dobj = DataObject.find (fo);
57         Node n = dobj.getNodeDelegate();
58         assertNotNull(n);
59         assertEquals("I18N", n.getDisplayName());
60         
61         // property sets have to be initialized otherwise the change name would be
62
// propagated to the node after some delay (~2s)
63
Object JavaDoc garbage = n.getPropertySets();
64         
65         InstanceCookie ic = (InstanceCookie) dobj.getCookie(InstanceCookie.class);
66         assertNotNull (dobj + " does not contain instance cookie", ic);
67         
68         FooSetting foo = (FooSetting) ic.instanceCreate();
69         String JavaDoc newName = "newName";
70         foo.setName(newName);
71         assertEquals(n.toString(), newName, n.getDisplayName());
72         
73         newName = "newNameViaNode";
74         n.setName(newName);
75         assertEquals(n.toString(), newName, n.getDisplayName());
76         assertEquals(n.toString(), newName, foo.getName());
77     }
78 }
79
Popular Tags