1 19 20 package org.netbeans.modules.db; 21 22 import org.netbeans.modules.db.runtime.DatabaseRuntimeManager; 23 import org.netbeans.modules.db.test.TestBase; 24 import org.netbeans.spi.db.explorer.DatabaseRuntime; 25 import org.openide.filesystems.FileObject; 26 import org.openide.filesystems.FileUtil; 27 import org.openide.filesystems.Repository; 28 29 33 public class DatabaseModuleTest extends TestBase { 34 35 37 39 public DatabaseModuleTest(String testName) { 40 super(testName); 41 } 42 43 public void testRuntimesAreStopped() throws Exception { 44 FileObject runtimeFolder = Repository.getDefault().getDefaultFileSystem().getRoot().getFileObject("Databases/Runtimes"); 45 FileObject runtime1 = FileUtil.createData(runtimeFolder, "runtime1.instance"); 46 runtime1.setAttribute("instanceOf", DatabaseRuntime.class.getName()); 47 runtime1.setAttribute("instanceCreate", new DatabaseRuntimeImpl()); 48 FileObject runtime2 = FileUtil.createData(runtimeFolder, "runtime2.instance"); 49 runtime2.setAttribute("instanceOf", DatabaseRuntime.class.getName()); 50 runtime2.setAttribute("instanceCreate", new DatabaseRuntimeImpl()); 51 52 new DatabaseModule().close(); 53 54 DatabaseRuntime[] runtimes = DatabaseRuntimeManager.getDefault().getRuntimes(); 55 int checked = 0; 56 for (int i = 0; i < runtimes.length; i++) { 57 if (runtimes[i] instanceof DatabaseRuntimeImpl) { 58 assertTrue(((DatabaseRuntimeImpl)runtimes[i]).stopped); 59 checked++; 60 } 61 } 62 assertTrue(checked == 2); 64 } 65 66 static final class DatabaseRuntimeImpl implements DatabaseRuntime { 67 68 boolean stopped; 69 70 public boolean acceptsDatabaseURL(String url) { 71 return true; 72 } 73 74 public void stop() { 75 stopped = true; 76 } 77 78 public void start() { 79 } 80 81 public boolean isRunning() { 82 return true; 83 } 84 85 public String getJDBCDriverClass() { 86 return null; 87 } 88 89 public boolean canStart() { 90 return true; 91 } 92 } 93 } 94 | Popular Tags |