Source Code Cross Referenced for TestLocalStringKeys.java in  » ESB » open-esb » com » sun » jbi » framework » 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 » ESB » open esb » com.sun.jbi.framework 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)TestLocalStringKeys.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.framework;
030:
031:        import java.lang.reflect.Field;
032:        import java.text.MessageFormat;
033:        import java.util.Enumeration;
034:        import java.util.ResourceBundle;
035:
036:        /**
037:         * Tests for the LocalStringKeys class.
038:         *
039:         * @author Sun Microsystems, Inc.
040:         */
041:        public class TestLocalStringKeys extends junit.framework.TestCase {
042:            /**
043:             * The constructor for this testcase, forwards the test name to
044:             * the jUnit TestCase base class.
045:             * @param aTestName String with the name of this test.
046:             */
047:            public TestLocalStringKeys(String aTestName) {
048:                super (aTestName);
049:            }
050:
051:            /**
052:             * Test the message keys to make sure the class and the properties file
053:             * have the same set of keys.
054:             * @throws java.util.MissingResourceException when
055:             * ResourceBundle.getBundle fails
056:             */
057:            public void testKeys() throws java.util.MissingResourceException {
058:                System.out.println("TestLocalStringKeys.testKeys(): "
059:                        + "Testing that LocalStringKeys interface and "
060:                        + "LocalStrings.properties have "
061:                        + "the same set of keys.");
062:
063:                // Load resource bundle
064:
065:                String packageName = this .getClass().getPackage().getName();
066:                String bundleName = packageName + "."
067:                        + StringTranslator.RESOURCE_BUNDLE_NAME;
068:                ResourceBundle bundle = null;
069:                bundle = ResourceBundle.getBundle(bundleName);
070:
071:                boolean mismatch = false;
072:
073:                // Get a list of all the fields defined in the LocalStringKeys class
074:
075:                Field[] keyFields = (LocalStringKeys.class).getDeclaredFields();
076:                Field keyField;
077:                int numFields = keyFields.length;
078:
079:                // Get a list of all the keys defined in the resource bundle
080:
081:                Enumeration rbKeys = bundle.getKeys();
082:                String rbKey = null;
083:                int numKeys = 0;
084:
085:                // Verify that all the keys in the resource bundle are defined in the
086:                // fields in the LocalStringKeys class
087:
088:                while (rbKeys.hasMoreElements()) {
089:                    rbKey = (String) rbKeys.nextElement();
090:                    numKeys++;
091:                    try {
092:                        keyField = LocalStringKeys.class
093:                                .getDeclaredField(rbKey);
094:                    } catch (NoSuchFieldException nsfEx) {
095:                        System.out.println("Resource bundle key " + rbKey
096:                                + " is not defined in LocalStringKeys");
097:                        mismatch = true;
098:                    }
099:                }
100:
101:                // Verify that all the fields defined in the LocalStringKeys class
102:                // are defined as keys in the resource bundle
103:
104:                int i = 0;
105:                String str;
106:                while (i < numFields) {
107:                    try {
108:                        rbKey = keyFields[i].getName();
109:                        str = bundle.getString(rbKey);
110:                    } catch (java.util.MissingResourceException mrEx) {
111:                        System.out.println("LocalStringKeys field " + rbKey
112:                                + " is not defined in the resource bundle");
113:                        mismatch = true;
114:                    }
115:                    i++;
116:                }
117:
118:                // Ensure that the bundle and the interface have the same number
119:                // of keys and they all match
120:
121:                assertFalse("Resource bundle has " + numKeys + " keys; "
122:                        + "LocalStringKeys interface has " + numFields
123:                        + " fields", mismatch);
124:            }
125:
126:            /**
127:             * Test the content of the properties file for syntax errors.
128:             * @throws java.util.MissingResourceException when
129:             * ResourceBundle.getBundle fails
130:             */
131:            public void testProperties()
132:                    throws java.util.MissingResourceException {
133:                System.out.println("TestLocalStringKeys.testProperties(): "
134:                        + "Testing that LocalStrings.properties has "
135:                        + "no syntax errors.");
136:
137:                // Load resource bundle
138:
139:                String packageName = this .getClass().getPackage().getName();
140:                String bundleName = packageName + "."
141:                        + StringTranslator.RESOURCE_BUNDLE_NAME;
142:                ResourceBundle bundle = null;
143:                bundle = ResourceBundle.getBundle(bundleName);
144:
145:                boolean errors = false;
146:
147:                // Get a list of all the keys defined in the resource bundle
148:
149:                Enumeration rbKeys = bundle.getKeys();
150:
151:                String rbKey = null;
152:                String rbMsg = null;
153:                String msg = null;
154:                int numBad = 0;
155:
156:                // Check each property in the resource bundle for syntax errors.
157:                // Note: if a MissingResourceException is thrown here, something is
158:                // seriously wrong!
159:
160:                while (rbKeys.hasMoreElements()) {
161:                    rbKey = (String) rbKeys.nextElement();
162:                    try {
163:                        rbMsg = bundle.getString(rbKey);
164:                        msg = MessageFormat.format(rbMsg, "AAA", "BBB", "CCC",
165:                                "DDD", "EEE", "FFF", "GGG", "HHH");
166:                    } catch (IllegalArgumentException iaEx) {
167:                        System.out.println("---");
168:                        System.out.println("Resource bundle property " + rbKey
169:                                + " has invalid syntax: " + rbMsg);
170:                        System.out.println("Error message: "
171:                                + iaEx.getMessage());
172:                        errors = true;
173:                        ++numBad;
174:                    }
175:                }
176:
177:                // Ensure that there were no syntax errors.
178:
179:                assertFalse(
180:                        "Resource bundle has " + numBad + " syntax errors.",
181:                        errors);
182:            }
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.