KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > registry > cdconvertor > CDConvertorTest


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.cdconvertor;
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.SpiUtils;
29 import org.openide.filesystems.FileSystem;
30 import org.openide.filesystems.LocalFileSystem;
31 import org.openide.filesystems.XMLFileSystem;
32 import org.openide.modules.ModuleInfo;
33 import org.openide.util.Lookup;
34 import org.xml.sax.SAXException JavaDoc;
35
36 import java.beans.PropertyVetoException JavaDoc;
37 import java.io.IOException JavaDoc;
38 import java.net.URL JavaDoc;
39
40 /**
41  *
42  * @author David Konecny
43  */

44 public class CDConvertorTest extends NbTestCase {
45     
46     public CDConvertorTest(String JavaDoc name) {
47         super (name);
48     }
49     
50     public static void main(String JavaDoc[] args) {
51         TestRunner.run(new NbTestSuite(CDConvertorTest.class));
52     }
53     
54     protected void setUp () throws Exception JavaDoc {
55         Lookup.getDefault().lookup(ModuleInfo.class);
56     }
57
58     public void testConvertor() throws Exception JavaDoc {
59         Context ctx = getRootContext().getSubcontext("folder4");
60
61         CD c = (CD)ctx.getObject("cd1", null);
62         assertNotNull(c);
63         assertEquals(new CD("Philip Glass", "The Hours"), c);
64         
65         CD cd = new CD("Arvo Part", "Alina");
66         CD cd2 = new CD("Arvo Part", "Alina");
67
68         ctx.putObject("newcd", cd);
69         assertEquals(cd2, ctx.getObject("newcd", null));
70         cd = null;
71         System.gc();System.gc();System.gc();System.gc();System.gc();
72         assertEquals(cd2, ctx.getObject("newcd", null));
73     }
74
75     private Context getRootContext() throws PropertyVetoException JavaDoc, IOException JavaDoc, SAXException JavaDoc {
76         LocalFileSystem lfs = new LocalFileSystem();
77         lfs.setRootDirectory(getWorkDir());
78         
79         URL JavaDoc u1 = getClass().getResource("data/layer.xml");
80                
81         FileSystem xfs1 = new XMLFileSystem( u1 );
82         FileSystem mfs = new TestMFS( new FileSystem[] { lfs, xfs1 } );
83
84         return SpiUtils.createContext(FileSystemContextFactory.createContext(mfs.getRoot()));
85     }
86
87 }
88
Popular Tags