Source Code Cross Referenced for PackageTest.java in  » Testing » jakarta-jmeter » org » apache » jmeter » testbeans » gui » 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 » Testing » jakarta jmeter » org.apache.jmeter.testbeans.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *   http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.jmeter.testbeans.gui;
018:
019:        import java.beans.BeanInfo;
020:        import java.beans.IntrospectionException;
021:        import java.beans.Introspector;
022:        import java.beans.PropertyDescriptor;
023:        import java.util.Enumeration;
024:        import java.util.Iterator;
025:        import java.util.Locale;
026:        import java.util.ResourceBundle;
027:
028:        import org.apache.jmeter.junit.JMeterTestCase;
029:        import org.apache.jmeter.testbeans.TestBean;
030:        import org.apache.jmeter.testelement.TestElement;
031:        import org.apache.jmeter.util.JMeterUtils;
032:        import org.apache.jorphan.logging.LoggingManager;
033:        import org.apache.jorphan.reflect.ClassFinder;
034:        import org.apache.log.Logger;
035:
036:        import junit.framework.Test; // import junit.framework.TestCase;
037:        import junit.framework.TestSuite;
038:
039:        /*
040:         * Find all beans out there and check their resource property files: - Check
041:         * that non-default property files don't have any extra keys. - Check all
042:         * necessary properties are defined at least in the default property file,
043:         * except for beans whose name contains "Experimental" or "Alpha". TODO: - Check
044:         * property files don't have duplicate keys (is this important)
045:         * 
046:         * @version $Revision: 493796 $ updated on $Date: 2007-01-07 18:31:05 +0000 (Sun, 07 Jan 2007) $
047:         */
048:        public class PackageTest extends JMeterTestCase {
049:            private static Logger log = LoggingManager.getLoggerForClass();
050:
051:            private ResourceBundle defaultBundle;
052:
053:            private Class testBeanClass;
054:
055:            // ResourceBundle i18nEdit=
056:            // ResourceBundle.getBundle("org.apache.jmeter.resources.i18nedit");
057:            private static final Locale defaultLocale = new Locale("en", ""); // i18nEdit.getString("locale.default");
058:
059:            // TODO: find a clean way to get these from i18nedit.properties
060:
061:            private static final Locale[] locales = new Locale[] {
062:            // new Locale("de"), // No resources yet
063:                    new Locale("ja", ""),
064:                    // new Locale("no",""), // No resources yet
065:                    // new Locale("fr",""), // No resources yet
066:                    // new Locale("zh","CN"), //No resources yet
067:                    new Locale("zh", "TW") };
068:
069:            private Locale testLocale;
070:
071:            private PackageTest(Class testBeanClass, Locale locale,
072:                    ResourceBundle defaultBundle) {
073:                super (testBeanClass.getName() + " - " + locale.getLanguage()
074:                        + " - " + locale.getCountry());
075:                this .testBeanClass = testBeanClass;
076:                this .testLocale = locale;
077:                this .defaultBundle = defaultBundle;
078:            }
079:
080:            BeanInfo beanInfo;
081:
082:            ResourceBundle bundle;
083:
084:            public void setUp() {
085:                JMeterUtils.setLocale(testLocale);
086:                Introspector.flushFromCaches(testBeanClass);
087:                try {
088:                    beanInfo = Introspector.getBeanInfo(testBeanClass);
089:                    bundle = (ResourceBundle) beanInfo
090:                            .getBeanDescriptor()
091:                            .getValue(GenericTestBeanCustomizer.RESOURCE_BUNDLE);
092:                } catch (IntrospectionException e) {
093:                    log.error("Can't get beanInfo for "
094:                            + testBeanClass.getName(), e);
095:                    throw new Error(e.toString()); // Programming error. Don't
096:                    // continue.
097:                }
098:                if (bundle == null)
099:                    throw new Error("This can't happen!");
100:            }
101:
102:            public void tearDown() {
103:                JMeterUtils.setLocale(Locale.getDefault());
104:            }
105:
106:            public void runTest() {
107:                if (bundle == defaultBundle)
108:                    checkAllNecessaryKeysPresent();
109:                else
110:                    checkNoInventedKeys();
111:            }
112:
113:            public void checkNoInventedKeys() {
114:                // Check that all keys in the bundle are also in the default bundle:
115:                for (Enumeration keys = bundle.getKeys(); keys
116:                        .hasMoreElements();) {
117:                    String key = (String) keys.nextElement();
118:                    defaultBundle.getString(key);
119:                    // Will throw MissingResourceException if key is not there.
120:                }
121:            }
122:
123:            public void checkAllNecessaryKeysPresent() {
124:                // Check that all necessary keys are there:
125:
126:                // displayName is always mandatory:
127:                String dn = defaultBundle.getString("displayName").toUpperCase(
128:                        Locale.ENGLISH);
129:
130:                // Skip the rest of this test for alpha/experimental beans:
131:                if (dn.indexOf("(ALPHA") != -1
132:                        || dn.indexOf("(EXPERIMENTAL") != -1)
133:                    return;
134:
135:                // Check for property- and group-related texts:
136:                PropertyDescriptor[] descriptors = beanInfo
137:                        .getPropertyDescriptors();
138:                for (int i = 0; i < descriptors.length; i++) {
139:                    // Skip non-editable properties, that is:
140:                    // Ignore hidden, read-only, and write-only properties
141:                    if (descriptors[i].isHidden()
142:                            || descriptors[i].getReadMethod() == null
143:                            || descriptors[i].getWriteMethod() == null)
144:                        continue;
145:                    // Ignore TestElement properties which don't have an explicit
146:                    // editor:
147:                    if (TestElement.class.isAssignableFrom(descriptors[i]
148:                            .getPropertyType())
149:                            && descriptors[i].getPropertyEditorClass() == null)
150:                        continue;
151:                    // Done -- we're working with an editable property.
152:
153:                    String name = descriptors[i].getName();
154:
155:                    bundle.getString(name + ".displayName");
156:                    // bundle.getString(name+".shortDescription"); NOT MANDATORY
157:
158:                    String group = (String) descriptors[i]
159:                            .getValue(GenericTestBeanCustomizer.GROUP);
160:                    if (group != null)
161:                        bundle.getString(group + ".displayName");
162:                }
163:            }
164:
165:            public static Test suite() throws Exception {
166:                TestSuite suite = new TestSuite("Bean Resource Test Suite");
167:
168:                Iterator iter = ClassFinder.findClassesThatExtend(
169:                        JMeterUtils.getSearchPaths(),
170:                        new Class[] { TestBean.class }).iterator();
171:
172:                while (iter.hasNext()) {
173:                    String className = (String) iter.next();
174:                    Class testBeanClass = Class.forName(className);
175:                    JMeterUtils.setLocale(defaultLocale);
176:                    ResourceBundle defaultBundle;
177:                    try {
178:                        defaultBundle = (ResourceBundle) Introspector
179:                                .getBeanInfo(testBeanClass)
180:                                .getBeanDescriptor()
181:                                .getValue(
182:                                        GenericTestBeanCustomizer.RESOURCE_BUNDLE);
183:                    } catch (IntrospectionException e) {
184:                        log.error("Can't get beanInfo for "
185:                                + testBeanClass.getName(), e);
186:                        throw new Error(e.toString()); // Programming error. Don't
187:                        // continue.
188:                    }
189:
190:                    if (defaultBundle == null) {
191:                        if (className.startsWith("org.apache.jmeter.examples.")) {
192:                            log
193:                                    .warn("No default bundle found for "
194:                                            + className);
195:                            continue;
196:                        }
197:                        throw new Error("No default bundle for class "
198:                                + className);
199:                    }
200:
201:                    suite.addTest(new PackageTest(testBeanClass, defaultLocale,
202:                            defaultBundle));
203:
204:                    for (int i = 0; i < locales.length; i++) {
205:                        suite.addTest(new PackageTest(testBeanClass,
206:                                locales[i], defaultBundle));
207:                    }
208:                }
209:
210:                return suite;
211:            }
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.