1 19 20 package org.netbeans.modules.apisupport.project.suite; 21 import java.io.File ; 22 import java.io.FileNotFoundException ; 23 import java.io.FileOutputStream ; 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.io.OutputStream ; 27 import java.net.MalformedURLException ; 28 import java.util.Arrays ; 29 import java.util.HashSet ; 30 import java.util.Set ; 31 import org.netbeans.api.project.ProjectManager; 32 import org.netbeans.modules.apisupport.project.TestBase; 33 import org.netbeans.modules.apisupport.project.ui.customizer.SuitePropertiesTest; 34 import org.netbeans.modules.apisupport.project.universe.NbPlatform; 35 import org.openide.filesystems.FileObject; 36 import org.openide.filesystems.FileUtil; 37 38 42 public class BrandingSupportTest extends TestBase { 43 private BrandingSupport instance = null; 44 45 public BrandingSupportTest(String testName) { 46 super(testName); 47 } 48 49 protected void setUp() throws Exception { 50 super.setUp(); 51 File suiteDir = new File (getWorkDir(), "testSuite"); 52 SuiteProjectGenerator.createSuiteProject(suiteDir, NbPlatform.PLATFORM_ID_DEFAULT); 53 FileObject fo = FileUtil.toFileObject(suiteDir); 54 SuiteProject suitePrj = (SuiteProject) ProjectManager.getDefault().findProject(fo); 55 assertNotNull(suitePrj); 56 57 instance = BrandingSupport.getInstance(SuitePropertiesTest.getSuiteProperties(suitePrj)); 58 59 } 60 61 public void testBranding1() throws IOException { 62 assertFalse(instance.getBrandingRoot().exists()); 63 Set keys = new HashSet (Arrays.asList(new String []{"CTL_About_Title"})); 64 implOfBundleKeyTest("org.netbeans.core.startup", 65 "org/netbeans/core/startup/Bundle.properties",keys, "About"); 66 } 67 68 public void testBranding2() throws IOException { 69 assertFalse(instance.getBrandingRoot().exists()); 70 Set keys = new HashSet (Arrays.asList(new String []{"CTL_About_Title"})); 71 implOfBundleKeyTest("org.netbeans.core.startup", null,keys, "About"); 72 } 73 74 75 public void testBranding3() throws IOException { 76 assertFalse(instance.getBrandingRoot().exists()); 77 Set keys = new HashSet (Arrays.asList(new String []{"LBL_ProductInformation"})); 78 implOfBundleKeyTest("org.netbeans.core", 79 "org/netbeans/core/ui/Bundle.properties", keys, "NetBeans Product Information"); 80 } 81 82 public void testBranding4() throws IOException { 83 assertFalse(instance.getBrandingRoot().exists()); 84 Set keys = new HashSet (Arrays.asList(new String []{"CTL_MainWindow_Title"})); 85 implOfBundleKeyTest("org.netbeans.core.windows", 86 "org/netbeans/core/windows/view/ui/Bundle.properties", keys, "NetBeans Platform {0}"); 87 } 88 89 public void testBrandingFile() throws IOException { 90 assertFalse(instance.getBrandingRoot().exists()); 91 assertNotNull(instance.getBrandedFiles()); 92 assertEquals(0,instance.getBrandedFiles().size()); 93 BrandingSupport.BrandedFile bFile = 94 instance.getBrandedFile("org.netbeans.core.startup","org/netbeans/core/startup/splash.gif"); 95 96 BrandingSupport.BrandedFile bFile2 = 97 instance.getBrandedFile("org.netbeans.core.startup","org/netbeans/core/startup/splash.gif"); 98 99 assertEquals(bFile2, bFile); 100 assertEquals(bFile2.getBrandingSource(), bFile.getBrandingSource()); 101 assertFalse(bFile.isModified()); 102 103 assertNotNull(bFile); 104 assertEquals(0,instance.getBrandedFiles().size()); 105 assertFalse(instance.isBranded(bFile)); 106 instance.brandFile(bFile); 107 assertFalse(bFile.isModified()); 108 109 assertFalse(instance.isBranded(bFile)); 110 assertEquals(0,instance.getBrandedFiles().size()); 111 112 File newSource = createNewSource(bFile); 113 assertEquals(0,instance.getBrandedFiles().size()); 114 115 bFile.setBrandingSource(newSource); 116 assertTrue(bFile.isModified()); 117 118 assertEquals(0,instance.getBrandedFiles().size()); 119 instance.brandFile(bFile); 120 assertFalse(bFile.isModified()); 121 122 123 assertEquals(1,instance.getBrandedFiles().size()); 124 assertTrue(instance.isBranded(bFile)); 125 assertEquals(bFile2, bFile); 126 assertFalse(bFile2.getBrandingSource().equals(bFile.getBrandingSource())); 127 128 129 130 } 131 132 private File createNewSource(final BrandingSupport.BrandedFile bFile) throws MalformedURLException , FileNotFoundException , IOException { 133 OutputStream os = null; 134 InputStream is = null; 135 File newSource = new File (getWorkDir(),"newSource.gif"); 136 137 try { 138 139 os = new FileOutputStream (newSource); 140 is = bFile.getBrandingSource().openStream(); 141 FileUtil.copy(is,os); 142 } finally { 143 if (is != null) { 144 is.close(); 145 } 146 if (os != null) { 147 os.close(); 148 } 149 } 150 return newSource; 151 } 152 153 154 private void implOfBundleKeyTest(final String moduleCodeNameBase, final String bundleEntry, final Set keys, String expectedValue) throws IOException { 155 Set bKeys; 156 if (bundleEntry != null) { 157 bKeys= instance.getBundleKeys(moduleCodeNameBase,bundleEntry,keys); 158 } else { 159 bKeys= instance.getLocalizingBundleKeys(moduleCodeNameBase,keys); 160 } 161 162 assertNotNull(bKeys); 163 assertEquals(1, bKeys.size()); 164 165 BrandingSupport.BundleKey bKey = (BrandingSupport.BundleKey) bKeys.toArray()[0]; 166 assertFalse(instance.isBranded(bKey)); 167 assertFalse(instance.isBranded(bKey.getModuleEntry())); 168 assertFalse(instance.getBrandingRoot().exists()); 169 assertFalse(instance.getModuleEntryDirectory(bKey.getModuleEntry()).exists()); 170 assertNotNull(instance.getBrandedBundleKeys()); 171 assertFalse(instance.getBrandedBundleKeys().contains(bKey)); 172 assertEquals(expectedValue, bKey.getValue()); 173 174 instance.brandBundleKeys(bKeys); 175 assertFalse(instance.isBranded(bKey)); 176 assertFalse(instance.isBranded(bKey.getModuleEntry())); 177 assertFalse(instance.getBrandingRoot().exists()); 178 assertFalse(instance.getModuleEntryDirectory(bKey.getModuleEntry()).exists()); 179 assertNotNull(instance.getBrandedBundleKeys()); 180 assertFalse(instance.getBrandedBundleKeys().contains(bKey)); 181 assertEquals(expectedValue, bKey.getValue()); 182 assertFalse(bKey.isModified()); 183 184 bKey.setValue("brandedValue"); 185 assertTrue(bKey.isModified()); 186 instance.brandBundleKeys(bKeys); 187 assertFalse(bKey.isModified()); 188 189 assertTrue(instance.isBranded(bKey)); 190 assertTrue(instance.isBranded(bKey.getModuleEntry())); 191 assertTrue(instance.getBrandingRoot().exists()); 192 assertTrue(instance.getModuleEntryDirectory(bKey.getModuleEntry()).exists()); 193 assertNotNull(instance.getBrandedBundleKeys()); 194 assertTrue(instance.getBrandedBundleKeys().contains(bKey)); 195 assertEquals("brandedValue", bKey.getValue()); 196 197 } 198 199 } 200 | Popular Tags |