KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > settings > ConvertorTest


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.spi.settings;
21
22 import java.io.*;
23 import org.netbeans.junit.NbTestCase;
24 import org.openide.filesystems.FileObject;
25 import org.openide.filesystems.FileSystem;
26 import org.openide.filesystems.LocalFileSystem;
27 import org.openide.util.Lookup;
28
29 /**
30  *
31  * @author Jan Pokorsky
32  */

33 public class ConvertorTest extends NbTestCase {
34
35     FileSystem fs;
36     FileObject contextFO;
37
38     /** Creates a new instance of EnvTest */
39     public ConvertorTest(String JavaDoc name) {
40         super(name);
41     }
42
43     protected void setUp() throws Exception JavaDoc {
44         super.setUp();
45         clearWorkDir();
46         File work = getWorkDir();
47         LocalFileSystem lfs = new LocalFileSystem();
48         lfs.setRootDirectory(work);
49         contextFO = lfs.getRoot().createData("context", "settings");
50         fs = lfs;
51     }
52     
53     public void testFindWriterContext() throws Exception JavaDoc {
54         Reader r = new java.io.InputStreamReader JavaDoc(contextFO.getInputStream());
55         Reader cr = org.netbeans.modules.settings.ContextProvider.createReaderContextProvider(r, contextFO);
56         Lookup l = Convertor.findContext(cr);
57         assertNotNull(l);
58         FileObject src = (FileObject) l.lookup(FileObject.class);
59         assertNotNull(src);
60         assertEquals(contextFO.getPath(), src.getPath());
61     }
62     
63     public void testFindReaderContext() throws Exception JavaDoc {
64         org.openide.filesystems.FileLock lock = contextFO.lock();
65         try {
66             Writer w = new java.io.OutputStreamWriter JavaDoc(contextFO.getOutputStream(lock));
67             Writer cw = org.netbeans.modules.settings.ContextProvider.createWriterContextProvider(w, contextFO);
68             Lookup l = Convertor.findContext(cw);
69             assertNotNull(l);
70             FileObject src = (FileObject) l.lookup(FileObject.class);
71             assertNotNull(src);
72             assertEquals(contextFO.getPath(), src.getPath());
73         } finally {
74             lock.releaseLock();
75         }
76     }
77     
78 }
79
Popular Tags