1 19 20 package org.netbeans.modules.derby; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import org.netbeans.modules.derby.test.TestBase; 25 import org.openide.modules.InstalledFileLocator; 26 27 31 public class DerbyOptionsTest extends TestBase { 32 33 File userdir; 34 File externalDerby; 35 36 public DerbyOptionsTest(String testName) { 37 super(testName); 38 } 39 40 public void setUp() throws Exception { 41 clearWorkDir(); 42 43 userdir = new File (getWorkDir(), ".netbeans"); 44 userdir.mkdirs(); 45 46 externalDerby = new File (userdir, "derby"); 48 createFakeDerbyInstallation(externalDerby); 49 } 50 51 public void testDerbyLocationIsNullWhenBundledDerbyNotInstalled() { 52 assertNull(DerbyOptions.getDefaultInstallLocation()); 54 55 DerbyOptions.getDefault().setLocation(externalDerby.getAbsolutePath()); 56 assertFalse(DerbyOptions.getDefault().isLocationNull()); 57 58 DerbyOptions.getDefault().setLocation(""); 59 assertTrue(DerbyOptions.getDefault().isLocationNull()); 60 } 61 62 public void testDerbyLocationIsNotNullWhenBundledDerbyInstalled() throws Exception { 63 File bundledDerby = new File (userdir, DerbyOptions.INST_DIR); 65 createFakeDerbyInstallation(bundledDerby); 66 67 setLookup(new Object [] { new InstalledFileLocatorImpl(userdir) }); 69 70 String derbyLocation = DerbyOptions.getDefaultInstallLocation(); 72 assertNotNull(derbyLocation); 73 74 DerbyOptions.getDefault().setLocation(externalDerby.getAbsolutePath()); 75 assertFalse(DerbyOptions.getDefault().isLocationNull()); 76 77 DerbyOptions.getDefault().setLocation(""); assertFalse(DerbyOptions.getDefault().isLocationNull()); 79 assertEquals(DerbyOptions.getDefault().getLocation(), derbyLocation); 80 } 81 82 public void testLocationWhenNDSHPropertySetIssue76908() throws IOException { 83 assertEquals("", DerbyOptions.getDefault().getSystemHome()); 84 85 File ndshSystemHome = new File (getWorkDir(), ".netbeans-derby-ndsh"); 86 if (!ndshSystemHome.mkdirs()) { 87 throw new IOException ("Could not create " + ndshSystemHome); 88 } 89 File systemHome = new File (getWorkDir(), ".netbeans-derby"); 90 if (!systemHome.mkdirs()) { 91 throw new IOException ("Could not create " + systemHome); 92 } 93 94 System.setProperty(DerbyOptions.NETBEANS_DERBY_SYSTEM_HOME, ndshSystemHome.getAbsolutePath()); 96 assertEquals(ndshSystemHome.getAbsolutePath(), DerbyOptions.getDefault().getSystemHome()); 97 98 DerbyOptions.getDefault().setSystemHome(systemHome.getAbsolutePath()); 100 assertEquals(systemHome.getAbsolutePath(), DerbyOptions.getDefault().getSystemHome()); 101 } 102 103 private static final class InstalledFileLocatorImpl extends InstalledFileLocator { 104 105 private File userdir; 106 107 public InstalledFileLocatorImpl(File userdir) { 108 this.userdir = userdir; 109 } 110 111 public File locate(String relativePath, String codeNameBase, boolean localized) { 112 File f = new File (userdir, relativePath); 113 return f.exists() ? f : null; 114 } 115 } 116 } 117 | Popular Tags |