1 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 ; 35 36 import java.beans.PropertyVetoException ; 37 import java.io.IOException ; 38 import java.net.URL ; 39 40 44 public class CDConvertorTest extends NbTestCase { 45 46 public CDConvertorTest(String name) { 47 super (name); 48 } 49 50 public static void main(String [] args) { 51 TestRunner.run(new NbTestSuite(CDConvertorTest.class)); 52 } 53 54 protected void setUp () throws Exception { 55 Lookup.getDefault().lookup(ModuleInfo.class); 56 } 57 58 public void testConvertor() throws Exception { 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 , IOException , SAXException { 76 LocalFileSystem lfs = new LocalFileSystem(); 77 lfs.setRootDirectory(getWorkDir()); 78 79 URL 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 |