KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > registry > serialdataconv > SerialDataConvertorTest


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.serialdataconv;
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 SerialDataConvertorTest extends NbTestCase {
43     
44     public SerialDataConvertorTest(String JavaDoc name) {
45         super (name);
46     }
47     
48     public static void main(String JavaDoc[] args) {
49         TestRunner.run(new NbTestSuite(SerialDataConvertorTest.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("folder2");
67         
68         SerializableCD c = (SerializableCD)ctx.getObject("cd1", null);
69         assertNotNull(c);
70         assertEquals(c, new SerializableCD("Giya Kancheli", "Mourned by the Wind"));
71         
72         c = (SerializableCD)ctx.getObject("cd2", null);
73         assertNotNull(c);
74         assertEquals(c, new SerializableCD());
75         
76         c = (SerializableCD)ctx.getObject("cd3", null);
77         assertNotNull(c);
78         assertEquals(c, new SerializableCD("V.A.", "Radio Kiss100 Mixes"));
79         
80         SerializableCD cd = new SerializableCD("Arvo Part", "Kanon Pokajanen");
81         SerializableCD cd2 = new SerializableCD("Arvo Part", "Kanon Pokajanen");
82
83         ctx.putObject("newcd", cd);
84         assertEquals(ctx.getObject("newcd", null), cd2);
85         cd = null;
86         System.gc();System.gc();System.gc();System.gc();System.gc();
87         assertEquals(ctx.getObject("newcd", null), cd2);
88         
89     }
90     
91 }
92
Popular Tags