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: package org.netbeans.modules.db;
043:
044: import org.netbeans.modules.db.runtime.DatabaseRuntimeManager;
045: import org.netbeans.modules.db.test.TestBase;
046: import org.netbeans.spi.db.explorer.DatabaseRuntime;
047: import org.openide.filesystems.FileObject;
048: import org.openide.filesystems.FileUtil;
049: import org.openide.filesystems.Repository;
050:
051: /**
052: *
053: * @author Andrei Badea
054: */
055: public class DatabaseModuleTest extends TestBase {
056:
057: // TODO should also test that connections are disconnected
058:
059: // TODO should also test that no errors are only logged to ErrorManager with EM.notify(INFORMATIONAL, e)
060:
061: public DatabaseModuleTest(String testName) {
062: super (testName);
063: }
064:
065: public void testRuntimesAreStopped() throws Exception {
066: FileObject runtimeFolder = Repository.getDefault()
067: .getDefaultFileSystem().getRoot().getFileObject(
068: "Databases/Runtimes");
069: FileObject runtime1 = FileUtil.createData(runtimeFolder,
070: "runtime1.instance");
071: runtime1.setAttribute("instanceOf", DatabaseRuntime.class
072: .getName());
073: runtime1.setAttribute("instanceCreate",
074: new DatabaseRuntimeImpl());
075: FileObject runtime2 = FileUtil.createData(runtimeFolder,
076: "runtime2.instance");
077: runtime2.setAttribute("instanceOf", DatabaseRuntime.class
078: .getName());
079: runtime2.setAttribute("instanceCreate",
080: new DatabaseRuntimeImpl());
081:
082: new DatabaseModule().close();
083:
084: DatabaseRuntime[] runtimes = DatabaseRuntimeManager
085: .getDefault().getRuntimes();
086: int checked = 0;
087: for (int i = 0; i < runtimes.length; i++) {
088: if (runtimes[i] instanceof DatabaseRuntimeImpl) {
089: assertTrue(((DatabaseRuntimeImpl) runtimes[i]).stopped);
090: checked++;
091: }
092: }
093: // check we have really tested our DatabaseRuntime implementations
094: assertTrue(checked == 2);
095: }
096:
097: static final class DatabaseRuntimeImpl implements DatabaseRuntime {
098:
099: boolean stopped;
100:
101: public boolean acceptsDatabaseURL(String url) {
102: return true;
103: }
104:
105: public void stop() {
106: stopped = true;
107: }
108:
109: public void start() {
110: }
111:
112: public boolean isRunning() {
113: return true;
114: }
115:
116: public String getJDBCDriverClass() {
117: return null;
118: }
119:
120: public boolean canStart() {
121: return true;
122: }
123: }
124: }
|