KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > source > classpath > CacheSourceForBinaryQueryImplTest


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.modules.java.source.classpath;
21
22 import java.io.FileNotFoundException JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.io.OutputStream JavaDoc;
26 import java.util.Date JavaDoc;
27 import java.util.Enumeration JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30 import junit.framework.*;
31 import java.io.File JavaDoc;
32 import java.net.URI JavaDoc;
33 import java.net.URL JavaDoc;
34 import javax.swing.event.ChangeListener JavaDoc;
35 import org.netbeans.api.java.classpath.ClassPath;
36 import org.netbeans.api.java.queries.SourceForBinaryQuery;
37 import org.netbeans.api.java.source.ClasspathInfo;
38 import org.netbeans.junit.NbTestCase;
39 import org.netbeans.modules.java.source.usages.ClasspathInfoAccessor;
40 import org.netbeans.modules.java.source.usages.IndexUtil;
41 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
42 import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
43 import org.openide.filesystems.FileChangeListener;
44 import org.openide.filesystems.FileLock;
45 import org.openide.filesystems.FileObject;
46 import org.openide.filesystems.FileStateInvalidException;
47 import org.openide.filesystems.FileSystem;
48 import org.openide.filesystems.FileUtil;
49
50 /**
51  *
52  * @author Tomas Zezula
53  */

54 public class CacheSourceForBinaryQueryImplTest extends NbTestCase {
55     
56     FileObject[] srcRoots;
57     ClasspathInfo cpInfo;
58     CacheSourceForBinaryQueryImpl sfbq;
59     
60     public CacheSourceForBinaryQueryImplTest(String JavaDoc testName) {
61         super(testName);
62     }
63
64     protected @Override JavaDoc void setUp() throws Exception JavaDoc {
65         this.clearWorkDir();
66         File JavaDoc fwd = this.getWorkDir();
67         FileObject wd = FileUtil.toFileObject(fwd);
68         assertNotNull(wd);
69         File JavaDoc cacheFolder = new File JavaDoc (fwd,"cache"); //NOI18N
70
cacheFolder.mkdirs();
71         IndexUtil.setCacheFolder (cacheFolder);
72         this.srcRoots = new FileObject [2];
73         this.srcRoots[0] = wd.createFolder("src1"); //NOI18N
74
this.srcRoots[1] = wd.createFolder("src2"); //NOI18N
75
ClassPath bootPath = ClassPathSupport.createClassPath(new URL JavaDoc[0]);
76         ClassPath compilePath = ClassPathSupport.createClassPath(new URL JavaDoc[0]);
77         ClassPath srcPath = ClassPathSupport.createClassPath(srcRoots);
78         this.cpInfo = ClasspathInfo.create(bootPath,compilePath,srcPath);
79         this.sfbq = new CacheSourceForBinaryQueryImpl ();
80     }
81
82     protected @Override JavaDoc void tearDown() throws Exception JavaDoc {
83         this.cpInfo = null;
84     }
85
86     public void testFindSourceRoots() throws Exception JavaDoc {
87         ClassPath outCp = this.cpInfo.getClassPath(ClasspathInfo.PathKind.OUTPUT);
88         assertNotNull(outCp);
89         assertEquals(srcRoots.length,outCp.entries().size());
90         Iterator JavaDoc<ClassPath.Entry> it = ((List JavaDoc<ClassPath.Entry>)outCp.entries()).iterator();
91         for (int i=0; it.hasNext(); i++) {
92             ClassPath.Entry entry = it.next();
93             URL JavaDoc url = entry.getURL();
94             SourceForBinaryQuery.Result result = this.sfbq.findSourceRoots(url);
95             FileObject[] sourceRoots = result.getRoots();
96             assertNotNull(sourceRoots);
97             assertEquals(1,sourceRoots.length);
98             assertEquals(srcRoots[i],sourceRoots[0]);
99         }
100     }
101     
102 }
103
Popular Tags