KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > registry > instanceconv > InstanceConvertorTest


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.core.registry.instanceconv;
21
22 import junit.textui.TestRunner;
23 import org.netbeans.api.registry.Context;
24 import org.netbeans.api.registry.fs.FileSystemContextFactory;
25 import org.netbeans.core.registry.TestMFS;
26 import org.netbeans.junit.NbTestCase;
27 import org.netbeans.junit.NbTestSuite;
28 import org.netbeans.spi.registry.BasicContext;
29 import org.netbeans.spi.registry.SpiUtils;
30 import org.openide.filesystems.FileSystem;
31 import org.openide.filesystems.LocalFileSystem;
32 import org.openide.filesystems.XMLFileSystem;
33 import org.openide.modules.ModuleInfo;
34 import org.openide.util.Lookup;
35
36 import java.net.URL JavaDoc;
37
38 /**
39  *
40  * @author David Konecny
41  */

42 public class InstanceConvertorTest extends NbTestCase {
43     
44     public InstanceConvertorTest(String JavaDoc name) {
45         super (name);
46     }
47     
48     public static void main(String JavaDoc[] args) {
49         TestRunner.run(new NbTestSuite(InstanceConvertorTest.class));
50     }
51     
52     protected void setUp () throws Exception JavaDoc {
53         Lookup.getDefault().lookup(ModuleInfo.class);
54     }
55
56     public void testConvertor() throws Exception JavaDoc {
57         LocalFileSystem lfs = new LocalFileSystem();
58         lfs.setRootDirectory(getWorkDir());
59         
60         URL JavaDoc u1 = getClass().getResource("data/layer.xml");
61                
62         FileSystem xfs1 = new XMLFileSystem( u1 );
63         FileSystem mfs = new TestMFS( new FileSystem[] { lfs, xfs1 } );
64     
65         BasicContext rootCtx = FileSystemContextFactory.createContext(mfs.getRoot());
66         Context ctx = SpiUtils.createContext(rootCtx).getSubcontext("folder3");
67         
68         CD c = (CD)ctx.getObject("org-netbeans-core-registry-instanceconv-CD", null);
69         assertNotNull(c);
70         assertEquals(c, new CD());
71         
72         c = (CD)ctx.getObject("cd2", null);
73         assertNotNull(c);
74         assertEquals(c, new CD());
75         
76         c = (CD)ctx.getObject("cd3", null);
77         assertNotNull(c);
78         assertEquals(c, CD.createDefault());
79         
80         c = (CD)ctx.getObject("cd4", null);
81         assertNotNull(c);
82         assertEquals(c, new CD("The Hafler Trio", "Cleave: 9 Great Openings"));
83         
84     }
85     
86 }
87
Popular Tags