Source Code Cross Referenced for ModelMBeanAttributeInfoTest.java in  » JMX » mx4j » test » javax » management » modelmbean » 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 » JMX » mx4j » test.javax.management.modelmbean 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) The MX4J Contributors.
003:         * All rights reserved.
004:         *
005:         * This software is distributed under the terms of the MX4J License version 1.0.
006:         * See the terms of the MX4J License in the documentation provided with this software.
007:         */
008:
009:        package test.javax.management.modelmbean;
010:
011:        import java.lang.reflect.Method;
012:        import java.util.Arrays;
013:        import java.util.List;
014:        import javax.management.Descriptor;
015:        import javax.management.IntrospectionException;
016:        import javax.management.modelmbean.DescriptorSupport;
017:        import javax.management.modelmbean.ModelMBeanAttributeInfo;
018:
019:        import test.MX4JTestCase;
020:
021:        /**
022:         * Test case of ModelMBeanAttributeInfo. It will try to verify an appropriate
023:         * behaviour in particular with respect to the descriptor values
024:         *
025:         * @version $Revision: 1.7 $
026:         * @see
027:         */
028:
029:        public class ModelMBeanAttributeInfoTest extends MX4JTestCase {
030:            public static class BogusNIC {
031:                public String getMAC() {
032:                    return null;
033:                }
034:
035:                public void setMAC(int mac) {
036:                }
037:            }
038:
039:            public ModelMBeanAttributeInfoTest(String s) {
040:                super (s);
041:            }
042:
043:            public void setUp() throws Exception {
044:                super .setUp();
045:            }
046:
047:            public void tearDown() throws Exception {
048:                super .tearDown();
049:            }
050:
051:            public void testValidDescriptorFields() throws Exception {
052:                // testcase for bug #794320
053:                // Test that only name and descriptorType are mandatory
054:                Descriptor descriptor = new DescriptorSupport(new String[] {
055:                        "name", "descriptortype", "default" }, new String[] {
056:                        "attribute1", "attribute", "default" });
057:                ModelMBeanAttributeInfo attribute = new ModelMBeanAttributeInfo(
058:                        "attribute1", "java.lang.String", "An attribute", true,
059:                        true, false, descriptor);
060:                // in case of bug #794320 the descriptor is overrided
061:                assertEquals(
062:                        attribute.getDescriptor().getFieldValue("default"),
063:                        "default");
064:                assertNull(attribute.getDescriptor().getFieldValue("value"));
065:            }
066:
067:            public void testBadCtor() throws Exception {
068:                try {
069:                    Method macgetter = BogusNIC.class.getMethod("getMAC",
070:                            new Class[0]);
071:                    Method macsetter = BogusNIC.class.getMethod("setMAC",
072:                            new Class[] { int.class });
073:                    ModelMBeanAttributeInfo attrinfo = new ModelMBeanAttributeInfo(
074:                            "MAC", "MAC Address", macgetter, macsetter);
075:                    fail("Expecting an IntrospectionException");
076:                } catch (IntrospectionException x) {
077:                    assertTrue(true); // success;
078:                }
079:            }
080:
081:            public void testValuelessAttribute() throws Exception {
082:                ModelMBeanAttributeInfo attrinfo = new ModelMBeanAttributeInfo(
083:                        "SerialNo", "NIC Card's serial number", null, null);
084:                attrinfo = new ModelMBeanAttributeInfo("SerialNo", "String",
085:                        "NIC Card's serial number", false, false, false);
086:            }
087:
088:            public void testCaseInsenstiveDescriptorType() {
089:                DescriptorSupport ds = new DescriptorSupport(new String[] {
090:                        "name=PreferredWine", "descriptorType=Attribute",
091:                        "value=Amarone", "default=Red" });
092:                ModelMBeanAttributeInfo attrinfo = new ModelMBeanAttributeInfo(
093:                        "PreferredWine", "String", "Wine of choice", true,
094:                        false, false, ds);
095:            }
096:
097:            public void testGetDescriptor() {
098:                DescriptorSupport defds = new DescriptorSupport(new String[] {
099:                        "name=PreferredWine", "descriptorType=Attribute",
100:                        "displayName=PreferredWine" });
101:                DescriptorSupport ds = new DescriptorSupport(new String[] {
102:                        "name=PreferredWine", "descriptorType=Attribute",
103:                        "value=Amarone", "displayName=PreferredWine",
104:                        "default=Red" });
105:
106:                ModelMBeanAttributeInfo attrinfo = new ModelMBeanAttributeInfo(
107:                        "PreferredWine", "String", "Wine of choice", true,
108:                        false, false);
109:                Descriptor d = attrinfo.getDescriptor();
110:                assertTrue("Expecting default descriptor", descriptorsEqual(d,
111:                        defds));
112:
113:                attrinfo = new ModelMBeanAttributeInfo("PreferredWine",
114:                        "String", "Wine of choice", true, false, false, ds);
115:                d = attrinfo.getDescriptor();
116:                assertTrue("Expecting copy of ds", descriptorsEqual(d, ds));
117:            }
118:
119:            private boolean descriptorsEqual(Descriptor done, Descriptor dtwo) {
120:                List cifields = Arrays.asList(new String[] { "descriptortype",
121:                        "persistpolicy", "log" });
122:                String[] fields = done.getFieldNames();
123:                boolean result = done.getFields().length == dtwo.getFields().length;
124:                for (int i = 0; i < fields.length && result == true; i++) {
125:                    String field = fields[i];
126:                    Object vone = done.getFieldValue(field);
127:                    Object vtwo = done.getFieldValue(field);
128:                    if (vtwo == null) {
129:                        result = false;
130:                    } else if (cifields.contains(field)) {
131:                        if (!(vone instanceof  String)
132:                                || !(vtwo instanceof  String)) {
133:                            result = false;
134:                        } else {
135:                            result = ((String) vone)
136:                                    .compareToIgnoreCase((String) vtwo) == 0;
137:                        }
138:                    } else {
139:                        vone.equals(vtwo);
140:                    }
141:                }
142:                return result;
143:            }
144:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.