001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * CompiledSourceForBinaryQueryTest.java
044: * JUnit based test
045: *
046: * Created on 14 February 2006, 10:43
047: */
048: package org.netbeans.modules.mobility.project.queries;
049:
050: import java.io.File;
051: import javax.swing.event.ChangeEvent;
052: import javax.swing.event.ChangeListener;
053: import junit.framework.*;
054: import java.net.URL;
055: import org.netbeans.api.java.queries.SourceForBinaryQuery;
056: import org.netbeans.api.project.Project;
057: import org.netbeans.api.project.ProjectManager;
058: import org.netbeans.junit.NbTestCase;
059: import org.netbeans.modules.masterfs.MasterFileSystem;
060: import org.netbeans.modules.mobility.project.J2MEProject;
061: import org.netbeans.modules.mobility.project.J2MEProjectGenerator;
062: import org.netbeans.modules.mobility.project.TestUtil;
063: import org.netbeans.modules.mobility.project.classpath.J2MEProjectClassPathExtenderTest;
064: import org.netbeans.spi.project.support.ant.AntProjectHelper;
065: import org.netbeans.spi.project.support.ant.EditableProperties;
066: import org.openide.filesystems.FileObject;
067: import org.openide.filesystems.FileStateInvalidException;
068: import org.openide.filesystems.FileUtil;
069:
070: /**
071: *
072: * @author lukas
073: */
074: public class CompiledSourceForBinaryQueryTest extends NbTestCase {
075: static AntProjectHelper aph = null;
076: static CompiledSourceForBinaryQuery instance = null;
077: static FileObject projDir = null;
078:
079: static {
080: TestUtil
081: .setLookup(new Object[] {},
082: CompiledSourceForBinaryQueryTest.class
083: .getClassLoader());
084: assertNotNull(MasterFileSystem.settingsFactory(null));
085: }
086:
087: public CompiledSourceForBinaryQueryTest(String testName) {
088: super (testName);
089:
090: TestUtil.setEnv();
091: }
092:
093: protected void setUp() throws Exception {
094: clearWorkDir();
095: File workDir = getWorkDir();
096: File proj = new File(workDir, "testProject");
097:
098: System.setProperty("netbeans.user", "test/tiredTester");
099:
100: aph = J2MEProjectGenerator.createNewProject(proj,
101: "testProject", null, null, null);
102: projDir = FileUtil.toFileObject(proj);
103: Project p = ProjectManager.getDefault().findProject(projDir);
104: assertNotNull(p);
105: projDir.getParent().createFolder("src2");
106: instance = p.getLookup().lookup(
107: CompiledSourceForBinaryQuery.class);
108: assertNotNull(instance);
109: EditableProperties ep = aph
110: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
111: ep.setProperty("libs.classpath", "../src2");
112: aph.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
113:
114: }
115:
116: protected void tearDown() throws Exception {
117: }
118:
119: public static Test suite() {
120: TestSuite suite = new TestSuite(
121: CompiledSourceForBinaryQueryTest.class);
122:
123: return suite;
124: }
125:
126: /**
127: * Test of findSourceRoots method, of class org.netbeans.modules.mobility.project.queries.CompiledSourceForBinaryQuery.
128: */
129: public void testFindSourceRoots() throws Exception {
130: System.out.println("findSourceRoots");
131: URL projRoot = null;
132: URL binRoot = null;
133: try {
134: projRoot = projDir.getURL();
135: binRoot = aph.resolveFile("dist").toURL();
136: } catch (FileStateInvalidException ex) {
137: ex.printStackTrace();
138: fail("Can't get URL");
139: }
140:
141: SourceForBinaryQuery.Result result = instance
142: .findSourceRoots(projRoot);
143: assertNotNull(result);
144: FileObject obj[] = result.getRoots();
145: assertNotNull(obj);
146: assertTrue(obj.length == 0);
147:
148: result = instance.findSourceRoots(binRoot);
149: assertNotNull(result);
150: obj = result.getRoots();
151: assertNotNull(obj);
152: assertTrue(obj.length > 0);
153:
154: assertEquals(obj[0], projDir.getFileObject("src"));
155:
156: //Improve test coverage
157: ChangeListener list = new ChangeListener() {
158: public void stateChanged(ChangeEvent e) {
159: }
160: };
161: result.addChangeListener(list);
162: result.removeChangeListener(null);
163: EditableProperties ep = aph
164: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
165: ep.setProperty("src.dir", "../src2");
166: aph.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
167: //result.removeChangeListener(list);
168: }
169:
170: public void testSourceLevelQueryImpl() throws Exception {
171: J2MEProject p = (J2MEProject) ProjectManager.getDefault()
172: .findProject(projDir);
173: SourceLevelQueryImpl simpl = p.getLookup().lookup(
174: SourceLevelQueryImpl.class);
175: String ver = simpl.getSourceLevel(null);
176: assertEquals(ver, "1.3");
177: }
178:
179: }
|