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: * The Original Software is NetBeans. The Initial Developer of the Original
025: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
026: * Microsystems, Inc. All Rights Reserved.
027: *
028: * If you wish your version of this file to be governed by only the CDDL
029: * or only the GPL Version 2, indicate your decision by adding
030: * "[Contributor] elects to include this software in this distribution
031: * under the [CDDL or GPL Version 2] license." If you do not indicate a
032: * single choice of license, a recipient has the option to distribute
033: * your version of this file under either the CDDL, the GPL Version 2 or
034: * to extend the choice of license to its licensees as provided above.
035: * However, if you add GPL Version 2 code and therefore, elected the GPL
036: * Version 2 license, then the option applies only if the new code is
037: * made subject to such option by the copyright holder.
038: */
039: package org.netbeans.api.ruby.platform;
040:
041: import java.io.File;
042: import java.io.FileOutputStream;
043: import org.netbeans.modules.ruby.platform.gems.GemManager;
044: import org.netbeans.modules.ruby.spi.project.support.rake.EditableProperties;
045: import org.openide.filesystems.FileUtil;
046:
047: public final class RubyPlatformManagerTest extends RubyTestBase {
048:
049: public RubyPlatformManagerTest(final String testName) {
050: super (testName);
051: }
052:
053: @Override
054: protected void setUp() throws Exception {
055: super .setUp();
056: RubyPlatformManager.resetPlatforms();
057: }
058:
059: public void testAddPlatform() throws Exception {
060: assertEquals("bundle JRuby", 1, RubyPlatformManager
061: .getPlatforms().size());
062: RubyPlatform ruby = RubyPlatformManager
063: .addPlatform(setUpRuby());
064: File defaultRubyHome = getTestRubyHome();
065: assertEquals("right ruby home", defaultRubyHome, ruby.getHome());
066: assertEquals("right ruby lib", new File(defaultRubyHome,
067: "lib/ruby/1.8").getAbsolutePath(), ruby.getLibDir());
068: assertEquals("two platforms", 2, RubyPlatformManager
069: .getPlatforms().size());
070: RubyPlatformManager.removePlatform(ruby);
071: assertEquals("platform removed", 1, RubyPlatformManager
072: .getPlatforms().size());
073: }
074:
075: public void testGetPlatformByPath() throws Exception {
076: RubyPlatform ruby = RubyPlatformManager
077: .addPlatform(setUpRuby());
078: RubyPlatform alsoRuby = RubyPlatformManager
079: .getPlatformByPath(ruby.getInterpreter());
080: assertSame("found by path", ruby, alsoRuby);
081: RubyPlatform jruby = RubyPlatformManager
082: .getPlatformByPath(TestUtil.getXTestJRubyPath());
083: assertSame("found by path", RubyPlatformManager
084: .getDefaultPlatform(), jruby);
085: }
086:
087: public void test60PlatformInBuildProperties() throws Exception {
088: EditableProperties ep = new EditableProperties();
089: ep.setProperty("rubyplatform.ruby_(1_8_6).interpreter",
090: "/a/path/to/ruby");
091: ep.setProperty("rubyplatform.ruby_(1_8_6).label",
092: "ruby (1.8.6)");
093: File bp = new File(getWorkDir(), "build.properties");
094: FileOutputStream fos = new FileOutputStream(bp);
095: ep.store(fos);
096: fos.close();
097: RubyPlatformManager.getDefaultPlatform();
098: }
099:
100: public void testPlatformDetection() throws Exception {
101: // sanity-check test
102: RubyPlatformManager.performPlatformDetection();
103: }
104:
105: public void testAddInvalidPlatform() throws Exception { // #125296
106: RubyPlatformManager.TEST_RUBY_PROPS = null;
107: assertEquals("bundle JRuby", 1, RubyPlatformManager
108: .getPlatforms().size());
109: FileUtil.toFileObject(getWorkDir()).createData("invalid-ruby");
110: RubyPlatform plaf = RubyPlatformManager.addPlatform(new File(
111: getWorkDir(), "invalid-ruby"));
112: assertNull("invalid platform", plaf);
113: }
114:
115: public void testRepositoriesAreStored() throws Exception {
116: RubyPlatform platform = RubyPlatformManager
117: .getDefaultPlatform();
118: GemManager gemManager = platform.getGemManager();
119: File dummyRepo = new File(getWorkDirPath(), "/a");
120: assertEquals("one repositories", 1, gemManager
121: .getRepositories().size());
122:
123: // add and check
124: gemManager.addGemPath(dummyRepo);
125: assertEquals("two repositories", 2, gemManager
126: .getRepositories().size());
127: RubyPlatformManager.resetPlatforms();
128: platform = RubyPlatformManager.getDefaultPlatform();
129: gemManager = platform.getGemManager();
130: assertEquals("two repositories", 2, gemManager
131: .getRepositories().size());
132:
133: // remove and check
134: gemManager.removeGemPath(dummyRepo);
135: RubyPlatformManager.resetPlatforms();
136: platform = RubyPlatformManager.getDefaultPlatform();
137: gemManager = platform.getGemManager();
138: assertEquals("two repositories", 1, RubyPlatformManager
139: .getDefaultPlatform().getGemManager().getRepositories()
140: .size());
141: gemManager.removeGemPath(dummyRepo);
142: }
143:
144: }
|