KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > suite > BrandingSupportTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project.suite;
21 import java.io.File JavaDoc;
22 import java.io.FileNotFoundException JavaDoc;
23 import java.io.FileOutputStream JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.io.OutputStream JavaDoc;
27 import java.net.MalformedURLException JavaDoc;
28 import java.util.Arrays JavaDoc;
29 import java.util.HashSet JavaDoc;
30 import java.util.Set JavaDoc;
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 /**
39  *
40  * @author Radek Matous
41  */

42 public class BrandingSupportTest extends TestBase {
43     private BrandingSupport instance = null;
44     
45     public BrandingSupportTest(String JavaDoc testName) {
46         super(testName);
47     }
48     
49     protected void setUp() throws Exception JavaDoc {
50         super.setUp();
51         File JavaDoc suiteDir = new File JavaDoc(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 JavaDoc {
62         assertFalse(instance.getBrandingRoot().exists());
63         Set JavaDoc keys = new HashSet JavaDoc(Arrays.asList(new String JavaDoc[]{"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 JavaDoc {
69         assertFalse(instance.getBrandingRoot().exists());
70         Set JavaDoc keys = new HashSet JavaDoc(Arrays.asList(new String JavaDoc[]{"CTL_About_Title"}));
71         implOfBundleKeyTest("org.netbeans.core.startup", null,keys, "About");
72     }
73     
74     
75     public void testBranding3() throws IOException JavaDoc {
76         assertFalse(instance.getBrandingRoot().exists());
77         Set JavaDoc keys = new HashSet JavaDoc(Arrays.asList(new String JavaDoc[]{"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 JavaDoc {
83         assertFalse(instance.getBrandingRoot().exists());
84         Set JavaDoc keys = new HashSet JavaDoc(Arrays.asList(new String JavaDoc[]{"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 JavaDoc {
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 JavaDoc 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 JavaDoc createNewSource(final BrandingSupport.BrandedFile bFile) throws MalformedURLException JavaDoc, FileNotFoundException JavaDoc, IOException JavaDoc {
133         OutputStream JavaDoc os = null;
134         InputStream JavaDoc is = null;
135         File JavaDoc newSource = new File JavaDoc(getWorkDir(),"newSource.gif");
136         
137         try {
138             
139             os = new FileOutputStream JavaDoc(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 JavaDoc moduleCodeNameBase, final String JavaDoc bundleEntry, final Set JavaDoc keys, String JavaDoc expectedValue) throws IOException JavaDoc {
155         Set JavaDoc 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