Source Code Cross Referenced for NLSSearchTest.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » ui » tests » search » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » jdt » org.eclipse.jdt.ui.tests.search 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2006, 2007 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.jdt.ui.tests.search;
011:
012:        import java.io.IOException;
013:        import java.io.InputStream;
014:        import java.io.Reader;
015:        import java.io.StringReader;
016:
017:        import junit.framework.Test;
018:        import junit.framework.TestCase;
019:        import junit.framework.TestSuite;
020:
021:        import org.eclipse.core.runtime.CoreException;
022:        import org.eclipse.core.runtime.NullProgressMonitor;
023:
024:        import org.eclipse.core.filebuffers.FileBuffers;
025:        import org.eclipse.core.filebuffers.ITextFileBuffer;
026:        import org.eclipse.core.filebuffers.ITextFileBufferManager;
027:        import org.eclipse.core.filebuffers.LocationKind;
028:
029:        import org.eclipse.core.resources.IFile;
030:        import org.eclipse.core.resources.IFolder;
031:
032:        import org.eclipse.jdt.core.ICompilationUnit;
033:        import org.eclipse.jdt.core.IJavaProject;
034:        import org.eclipse.jdt.core.IPackageFragment;
035:        import org.eclipse.jdt.core.IPackageFragmentRoot;
036:
037:        import org.eclipse.jdt.testplugin.JavaProjectHelper;
038:
039:        import org.eclipse.jdt.ui.tests.core.ProjectTestSetup;
040:
041:        public class NLSSearchTest extends TestCase {
042:
043:            private IJavaProject fJProject1;
044:            private IPackageFragmentRoot fSourceFolder;
045:
046:            public NLSSearchTest(String name) {
047:                super (name);
048:            }
049:
050:            public static Test allTests() {
051:                return new ProjectTestSetup(new TestSuite(NLSSearchTest.class));
052:            }
053:
054:            public static Test suite() {
055:                return allTests();
056:            }
057:
058:            public void setUp() throws CoreException {
059:                fJProject1 = ProjectTestSetup.getProject();
060:                fSourceFolder = JavaProjectHelper.addSourceContainer(
061:                        fJProject1, "src");
062:
063:                IPackageFragment pack = fSourceFolder.createPackageFragment(
064:                        "org.eclipse.osgi.util", false, null);
065:                StringBuffer buf = new StringBuffer();
066:                buf.append("package org.eclipse.osgi.util;\n");
067:                buf.append("public class NLS {\n");
068:                buf
069:                        .append("public static void initializeMessages(String s, Class c) {}\n}\n");
070:                pack.createCompilationUnit("NLS.java", buf.toString(), false,
071:                        null);
072:            }
073:
074:            protected void tearDown() throws Exception {
075:                JavaProjectHelper.clear(fJProject1, ProjectTestSetup
076:                        .getDefaultClasspath());
077:            }
078:
079:            private IFile write(IFolder folder, final String content,
080:                    final String fileName) throws IOException, CoreException {
081:                InputStream stream = new InputStream() {
082:                    private Reader fReader = new StringReader(content);
083:
084:                    public int read() throws IOException {
085:                        return fReader.read();
086:                    }
087:                };
088:                IFile file = fJProject1.getProject().getFile(
089:                        folder.getProjectRelativePath().append(fileName));
090:                file.create(stream, true, null);
091:                return file;
092:            }
093:
094:            public void test01() throws Exception {
095:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
096:                        "test", false, null);
097:                StringBuffer buf = new StringBuffer();
098:                buf.append("package test;\n");
099:                buf.append("import org.eclipse.osgi.util.NLS;\n");
100:                buf.append("public class Accessor extends NLS {\n");
101:                buf.append("    private Accessor() {}\n");
102:                buf
103:                        .append("    private static final String BUNDLE_NAME = \"test.Accessor\"; //$NON-NLS-1$\n");
104:                buf
105:                        .append("    static {NLS.initializeMessages(BUNDLE_NAME, Accessor.class);}\n");
106:                buf.append("}\n");
107:                ICompilationUnit accessor = pack1.createCompilationUnit(
108:                        "Accessor.java", buf.toString(), false, null);
109:
110:                IFile propertiesFile = write((IFolder) pack1
111:                        .getCorrespondingResource(), "", "Accessor.properties");
112:
113:                NLSSearchTestHelper.assertNumberOfProblems(accessor,
114:                        propertiesFile, 0);
115:            }
116:
117:            public void test02() throws Exception {
118:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
119:                        "test", false, null);
120:                StringBuffer buf = new StringBuffer();
121:                buf.append("package test;\n");
122:                buf.append("import org.eclipse.osgi.util.NLS;\n");
123:                buf.append("public class Accessor extends NLS {\n");
124:                buf.append("\n");
125:                buf.append("    public static String Client_s1;\n");
126:                buf.append("\n");
127:                buf.append("    private Accessor() {}\n");
128:                buf
129:                        .append("    private static final String BUNDLE_NAME = \"test.Accessor\"; //$NON-NLS-1$\n");
130:                buf
131:                        .append("    static {NLS.initializeMessages(BUNDLE_NAME, Accessor.class);}\n");
132:                buf.append("}\n");
133:                ICompilationUnit accessor = pack1.createCompilationUnit(
134:                        "Accessor.java", buf.toString(), false, null);
135:
136:                buf = new StringBuffer();
137:                buf.append("package test;\n");
138:                buf.append("public class Client {\n");
139:                buf.append("    public String s1= Accessor.Client_s1;\n");
140:                buf.append("}\n");
141:                pack1.createCompilationUnit("Client.java", buf.toString(),
142:                        false, null);
143:
144:                buf = new StringBuffer();
145:                buf.append("Client_s1=s1\n");
146:                IFile propertiesFile = write((IFolder) pack1
147:                        .getCorrespondingResource(), buf.toString(),
148:                        "Accessor.properties");
149:
150:                NLSSearchTestHelper.assertNumberOfProblems(accessor,
151:                        propertiesFile, 0);
152:            }
153:
154:            public void test03() throws Exception {
155:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
156:                        "test", false, null);
157:                StringBuffer buf = new StringBuffer();
158:                buf.append("package test;\n");
159:                buf.append("import org.eclipse.osgi.util.NLS;\n");
160:                buf.append("public class Accessor extends NLS {\n");
161:                buf.append("\n");
162:                buf.append("    public static String Client_s1;\n");
163:                buf.append("\n");
164:                buf.append("    private Accessor() {}\n");
165:                buf
166:                        .append("    private static final String BUNDLE_NAME = \"test.Accessor\"; //$NON-NLS-1$\n");
167:                buf
168:                        .append("    static {NLS.initializeMessages(BUNDLE_NAME, Accessor.class);}\n");
169:                buf.append("}\n");
170:                ICompilationUnit accessor = pack1.createCompilationUnit(
171:                        "Accessor.java", buf.toString(), false, null);
172:
173:                buf = new StringBuffer();
174:                buf.append("package test;\n");
175:                buf.append("public class Client {\n");
176:                buf.append("    public String s1= Accessor.Client_s1;\n");
177:                buf.append("}\n");
178:                ICompilationUnit client = pack1.createCompilationUnit(
179:                        "Client.java", buf.toString(), false, null);
180:
181:                buf = new StringBuffer();
182:                IFile propertiesFile = write((IFolder) pack1
183:                        .getCorrespondingResource(), buf.toString(),
184:                        "Accessor.properties");
185:
186:                NLSSearchTestHelper.assertNumberOfProblems(accessor,
187:                        propertiesFile, 2);
188:
189:                NLSSearchTestHelper.assertHasUndefinedKey(accessor,
190:                        propertiesFile, "Client_s1", (IFile) accessor
191:                                .getCorrespondingResource());
192:                NLSSearchTestHelper.assertHasUndefinedKey(accessor,
193:                        propertiesFile, "Client_s1", (IFile) client
194:                                .getCorrespondingResource());
195:            }
196:
197:            public void test04() throws Exception {
198:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
199:                        "test", false, null);
200:                StringBuffer buf = new StringBuffer();
201:                buf.append("package test;\n");
202:                buf.append("import org.eclipse.osgi.util.NLS;\n");
203:                buf.append("public class Accessor extends NLS {\n");
204:                buf.append("\n");
205:                buf.append("    public static String Client_s1;\n");
206:                buf.append("\n");
207:                buf.append("    private Accessor() {}\n");
208:                buf
209:                        .append("    private static final String BUNDLE_NAME = \"test.Accessor\"; //$NON-NLS-1$\n");
210:                buf
211:                        .append("    static {NLS.initializeMessages(BUNDLE_NAME, Accessor.class);}\n");
212:                buf.append("}\n");
213:                ICompilationUnit accessor = pack1.createCompilationUnit(
214:                        "Accessor.java", buf.toString(), false, null);
215:
216:                buf = new StringBuffer();
217:                buf.append("package test;\n");
218:                buf.append("public class Client {\n");
219:                buf.append("}\n");
220:                pack1.createCompilationUnit("Client.java", buf.toString(),
221:                        false, null);
222:
223:                buf = new StringBuffer();
224:                buf.append("Client_s1=foo\n");
225:                IFile propertiesFile = write((IFolder) pack1
226:                        .getCorrespondingResource(), buf.toString(),
227:                        "Accessor.properties");
228:
229:                NLSSearchTestHelper.assertNumberOfProblems(accessor,
230:                        propertiesFile, 2);
231:
232:                NLSSearchTestHelper.assertHasUnusedKey(accessor,
233:                        propertiesFile, "Client_s1", (IFile) accessor
234:                                .getCorrespondingResource());
235:                NLSSearchTestHelper.assertHasUnusedKey(accessor,
236:                        propertiesFile, "Client_s1", propertiesFile);
237:            }
238:
239:            public void test05() throws Exception {
240:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
241:                        "test", false, null);
242:                StringBuffer buf = new StringBuffer();
243:                buf.append("package test;\n");
244:                buf.append("import org.eclipse.osgi.util.NLS;\n");
245:                buf.append("public class Accessor extends NLS {\n");
246:                buf.append("\n");
247:                buf.append("    public static String Client_s1;\n");
248:                buf.append("\n");
249:                buf.append("    private Accessor() {}\n");
250:                buf
251:                        .append("    private static final String BUNDLE_NAME = \"test.Accessor\"; //$NON-NLS-1$\n");
252:                buf
253:                        .append("    static {NLS.initializeMessages(BUNDLE_NAME, Accessor.class);}\n");
254:                buf.append("}\n");
255:                ICompilationUnit accessor = pack1.createCompilationUnit(
256:                        "Accessor.java", buf.toString(), false, null);
257:
258:                buf = new StringBuffer();
259:                buf.append("package test;\n");
260:                buf.append("public class Client {\n");
261:                buf.append("}\n");
262:                pack1.createCompilationUnit("Client.java", buf.toString(),
263:                        false, null);
264:
265:                buf = new StringBuffer();
266:                IFile propertiesFile = write((IFolder) pack1
267:                        .getCorrespondingResource(), buf.toString(),
268:                        "Accessor.properties");
269:
270:                NLSSearchTestHelper.assertNumberOfProblems(accessor,
271:                        propertiesFile, 2);
272:
273:                NLSSearchTestHelper.assertHasUnusedKey(accessor,
274:                        propertiesFile, "Client_s1", (IFile) accessor
275:                                .getCorrespondingResource());
276:                NLSSearchTestHelper.assertHasUndefinedKey(accessor,
277:                        propertiesFile, "Client_s1", (IFile) accessor
278:                                .getCorrespondingResource());
279:            }
280:
281:            public void test06() throws Exception {
282:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
283:                        "test", false, null);
284:                StringBuffer buf = new StringBuffer();
285:                buf.append("package test;\n");
286:                buf.append("import org.eclipse.osgi.util.NLS;\n");
287:                buf.append("public class Accessor extends NLS {\n");
288:                buf.append("\n");
289:                buf.append("    public static String Client_s1;\n");
290:                buf.append("\n");
291:                buf.append("    private Accessor() {}\n");
292:                buf
293:                        .append("    private static final String BUNDLE_NAME = \"test.Accessor\"; //$NON-NLS-1$\n");
294:                buf
295:                        .append("    static {NLS.initializeMessages(BUNDLE_NAME, Accessor.class);}\n");
296:                buf.append("}\n");
297:                ICompilationUnit accessor = pack1.createCompilationUnit(
298:                        "Accessor.java", buf.toString(), false, null);
299:
300:                buf = new StringBuffer();
301:                buf.append("package test;\n");
302:                buf.append("public class Client {\n");
303:                buf.append("    public String s1= Accessor.Client_s1;\n");
304:                buf.append("}\n");
305:                pack1.createCompilationUnit("Client.java", buf.toString(),
306:                        false, null);
307:
308:                buf = new StringBuffer();
309:                buf.append("Client_s1=s1\n");
310:                buf.append("Client_s1=s1\n");
311:                IFile propertiesFile = write((IFolder) pack1
312:                        .getCorrespondingResource(), buf.toString(),
313:                        "Accessor.properties");
314:
315:                NLSSearchTestHelper.assertNumberOfProblems(accessor,
316:                        propertiesFile, 1);
317:
318:                NLSSearchTestHelper.assertHasDuplicateKey(accessor,
319:                        propertiesFile, "Client_s1", propertiesFile);
320:            }
321:
322:            public void testBug152604() throws Exception {
323:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
324:                        "test", false, null);
325:                StringBuffer buf = new StringBuffer();
326:                buf.append("package test;\n");
327:                buf.append("import org.eclipse.osgi.util.NLS;\n");
328:                buf.append("public class Accessor extends NLS {\n");
329:                buf.append("\n");
330:                buf.append("    public static String Client_s1;\n");
331:                buf.append("\n");
332:                buf.append("    private Accessor() {}\n");
333:                buf
334:                        .append("    private static final String BUNDLE_NAME = \"test.Accessor\"; //$NON-NLS-1$\n");
335:                buf
336:                        .append("    static {NLS.initializeMessages(BUNDLE_NAME, Accessor.class);}\n");
337:                buf.append("}\n");
338:                ICompilationUnit accessor = pack1.createCompilationUnit(
339:                        "Accessor.java", buf.toString(), false, null);
340:
341:                buf = new StringBuffer();
342:                buf.append("package test;\n");
343:                buf.append("public class Client {\n");
344:                buf
345:                        .append("    public int length= Accessor.Client_s1.length();\n");
346:                buf.append("}\n");
347:                pack1.createCompilationUnit("Client.java", buf.toString(),
348:                        false, null);
349:
350:                buf = new StringBuffer();
351:                buf.append("Client_s1=s1\n");
352:                IFile propertiesFile = write((IFolder) pack1
353:                        .getCorrespondingResource(), buf.toString(),
354:                        "Accessor.properties");
355:
356:                NLSSearchTestHelper.assertNumberOfProblems(accessor,
357:                        propertiesFile, 0);
358:            }
359:
360:            public void testBug133810() throws Exception {
361:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
362:                        "test", false, null);
363:                StringBuffer buf = new StringBuffer();
364:                buf.append("package test;\n");
365:                buf.append("import org.eclipse.osgi.util.NLS;\n");
366:                buf.append("public class Accessor extends NLS {\n");
367:                buf.append("\n");
368:                buf.append("    public static String Client_s1;\n");
369:                buf.append("\n");
370:                buf.append("    private Accessor() {}\n");
371:                buf
372:                        .append("    private static final String BUNDLE_NAME = \"test.Accessor\"; //$NON-NLS-1$\n");
373:                buf
374:                        .append("    static {NLS.initializeMessages(BUNDLE_NAME, Accessor.class);}\n");
375:                buf.append("}\n");
376:                ICompilationUnit accessor = pack1.createCompilationUnit(
377:                        "Accessor.java", buf.toString(), false, null);
378:
379:                buf = new StringBuffer();
380:                buf.append("package test;\n");
381:                buf.append("public class Client {\n");
382:                buf.append("    public String s1= Accessor.Client_s1;\n");
383:                buf.append("}\n");
384:                pack1.createCompilationUnit("Client.java", buf.toString(),
385:                        false, null);
386:
387:                buf = new StringBuffer();
388:                buf.append("Client_s2=s1\n");
389:                IFile propertiesFile = write((IFolder) pack1
390:                        .getCorrespondingResource(), buf.toString(),
391:                        "Accessor.properties");
392:
393:                ITextFileBufferManager manager = FileBuffers
394:                        .getTextFileBufferManager();
395:                try {
396:                    manager.connect(propertiesFile.getFullPath(),
397:                            LocationKind.IFILE, new NullProgressMonitor());
398:                    ITextFileBuffer buffer = manager.getTextFileBuffer(
399:                            propertiesFile.getFullPath(), LocationKind.IFILE);
400:                    buffer.getDocument().replace(8, 1, "1");
401:
402:                    NLSSearchTestHelper.assertNumberOfProblems(accessor,
403:                            propertiesFile, 0);
404:                } finally {
405:                    manager.disconnect(propertiesFile.getFullPath(),
406:                            LocationKind.IFILE, new NullProgressMonitor());
407:                }
408:            }
409:
410:            public void testBug185178() throws Exception {
411:                IPackageFragment pack1 = fSourceFolder.createPackageFragment(
412:                        "test", false, null);
413:                StringBuffer buf = new StringBuffer();
414:                buf.append("package test;\n");
415:                buf.append("import java.util.MissingResourceException;\n");
416:                buf.append("import java.util.ResourceBundle;\n");
417:                buf.append("public class Accessor {\n");
418:                buf
419:                        .append("    private static final String BUNDLE_NAME = \"test.Accessor\"; //$NON-NLS-1$\n");
420:                buf
421:                        .append("    private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);\n");
422:                buf.append("    private Accessor() {}\n");
423:                buf
424:                        .append("    public static String getString(String key) {\n");
425:                buf.append("        try {\n");
426:                buf
427:                        .append("            return RESOURCE_BUNDLE.getString(key);\n");
428:                buf.append("        } catch (MissingResourceException e) {\n");
429:                buf.append("            return '!' + key + '!';\n");
430:                buf.append("        }\n");
431:                buf.append("    }\n");
432:                buf.append("}\n");
433:                ICompilationUnit accessor = pack1.createCompilationUnit(
434:                        "Accessor.java", buf.toString(), false, null);
435:
436:                buf = new StringBuffer();
437:                buf.append("package test;\n");
438:                buf.append("public class Client {\n");
439:                buf.append("    public String s1= Accessor\n");
440:                buf
441:                        .append("                            .getString(\"Client.0\"); //$NON-NLS-1$\n");
442:                buf.append("}\n");
443:                pack1.createCompilationUnit("Client.java", buf.toString(),
444:                        false, null);
445:
446:                buf = new StringBuffer();
447:                buf.append("Client.0=s1\n");
448:                IFile propertiesFile = write((IFolder) pack1
449:                        .getCorrespondingResource(), buf.toString(),
450:                        "Accessor.properties");
451:
452:                NLSSearchTestHelper.assertNumberOfProblems(accessor,
453:                        propertiesFile, 0);
454:            }
455:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.