Source Code Cross Referenced for OperatingSystemMXBeanImplTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » lang » management » 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 » Apache Harmony Java SE » org package » org.apache.harmony.lang.management 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         * 
010:         *   http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         * 
019:         */
020:
021:        package org.apache.harmony.lang.management;
022:
023:        import java.lang.management.ManagementFactory;
024:        import java.util.Hashtable;
025:        import java.util.Iterator;
026:
027:        import javax.management.Attribute;
028:        import javax.management.AttributeList;
029:        import javax.management.AttributeNotFoundException;
030:        import javax.management.MBeanAttributeInfo;
031:        import javax.management.MBeanConstructorInfo;
032:        import javax.management.MBeanInfo;
033:        import javax.management.MBeanNotificationInfo;
034:        import javax.management.MBeanOperationInfo;
035:        import javax.management.NotificationEmitter;
036:
037:        import org.apache.harmony.lang.management.OperatingSystemMXBeanImpl;
038:
039:        public class OperatingSystemMXBeanImplTest extends
040:                SingleInstanceDynamicMXBeanImplTestBase {
041:
042:            private OperatingSystemMXBeanImpl notifierBean;
043:
044:            protected void setUp() throws Exception {
045:                super .setUp();
046:                mb = (OperatingSystemMXBeanImpl) ManagementFactory
047:                        .getOperatingSystemMXBean();
048:                notifierBean = (OperatingSystemMXBeanImpl) mb;
049:            }
050:
051:            protected void tearDown() throws Exception {
052:                super .tearDown();
053:            }
054:
055:            // -----------------------------------------------------------------
056:            // DynamicMBean behaviour tests follow ....
057:            // -----------------------------------------------------------------
058:
059:            public final void testGetAttribute() throws Exception {
060:                // The good attributes...
061:                assertTrue(mb.getAttribute("Arch") != null);
062:                assertTrue(mb.getAttribute("Arch") instanceof  String);
063:                assertTrue(((Integer) (mb.getAttribute("AvailableProcessors"))) > -1);
064:                assertTrue(mb.getAttribute("Name") != null);
065:                assertTrue(mb.getAttribute("Name") instanceof  String);
066:                assertTrue(mb.getAttribute("Version") != null);
067:                assertTrue(mb.getAttribute("Version") instanceof  String);
068:
069:                // A nonexistent attribute should throw an AttributeNotFoundException
070:                try {
071:                    mb.getAttribute("RPM");
072:                    fail("Should have thrown an AttributeNotFoundException.");
073:                } catch (AttributeNotFoundException ignore) {
074:                }
075:
076:                // Type mismatch should result in a casting exception
077:                try {
078:                    String bad = (String) (mb
079:                            .getAttribute("AvailableProcessors"));
080:                    fail("Should have thrown a ClassCastException");
081:                } catch (ClassCastException ignore) {
082:                }
083:            }
084:
085:            public final void testSetAttribute() throws Exception {
086:                // Nothing is writable for this type
087:                Attribute attr = new Attribute("Name", "Boris");
088:                try {
089:                    mb.setAttribute(attr);
090:                    fail("Should have thrown an AttributeNotFoundException.");
091:                } catch (AttributeNotFoundException ignore) {
092:                }
093:
094:                attr = new Attribute("Arch", "ie Bunker");
095:                try {
096:                    mb.setAttribute(attr);
097:                    fail("Should have thrown an AttributeNotFoundException.");
098:                } catch (AttributeNotFoundException ignore) {
099:                }
100:
101:                attr = new Attribute("Version", "27 and a half");
102:                try {
103:                    mb.setAttribute(attr);
104:                    fail("Should have thrown an AttributeNotFoundException.");
105:                } catch (AttributeNotFoundException ignore) {
106:                }
107:
108:                attr = new Attribute("AvailableProcessors", new Integer(2));
109:                try {
110:                    mb.setAttribute(attr);
111:                    fail("Should have thrown an AttributeNotFoundException.");
112:                } catch (AttributeNotFoundException ignore) {
113:                }
114:
115:                // Try and set the Name attribute with an incorrect type.
116:                attr = new Attribute("Name", new Long(42));
117:                try {
118:                    mb.setAttribute(attr);
119:                    fail("Should have thrown an AttributeNotFoundException.");
120:                } catch (AttributeNotFoundException ignore) {
121:                }
122:            }
123:
124:            public final void testGetAttributes() {
125:                AttributeList attributes = mb.getAttributes(attribs.keySet()
126:                        .toArray(new String[] {}));
127:                assertNotNull(attributes);
128:                assertEquals(attribs.size(), attributes.size());
129:
130:                // Check through the returned values
131:                Iterator<?> it = attributes.iterator();
132:                while (it.hasNext()) {
133:                    Attribute element = (Attribute) it.next();
134:                    assertNotNull(element);
135:                    String name = element.getName();
136:                    Object value = element.getValue();
137:                    if (name.equals("Arch")) {
138:                        assertTrue(value instanceof  String);
139:                        assertEquals(System.getProperty("os.arch"),
140:                                (String) value);
141:                    } else if (name.equals("AvailableProcessors")) {
142:                        assertTrue(((Integer) (value)) > -1);
143:                    } else if (name.equals("Name")) {
144:                        assertTrue(value instanceof  String);
145:                        assertEquals(System.getProperty("os.name"),
146:                                (String) value);
147:                    } else if (name.equals("Version")) {
148:                        assertTrue(value instanceof  String);
149:                        assertEquals(System.getProperty("os.version"),
150:                                (String) value);
151:                    } else if (name.equals("TotalPhysicalMemory")) {
152:                        assertTrue(value instanceof  Long);
153:                        assertTrue(((Long) (value)) > -1);
154:                    } else if (name.equals("ProcessingCapacity")) {
155:                        assertTrue(value instanceof  Integer);
156:                        assertTrue(((Integer) (value)) > -1);
157:                    } else {
158:                        fail("Unexpected attribute name returned!");
159:                    }
160:                }// end while
161:            }
162:
163:            public final void testSetAttributes() {
164:                // No writable attributes for this type - should get a failure...
165:                AttributeList badList = new AttributeList();
166:                Attribute garbage = new Attribute("Name",
167:                        "Waiting for the moon");
168:                badList.add(garbage);
169:                AttributeList setAttrs = mb.setAttributes(badList);
170:                assertNotNull(setAttrs);
171:                assertTrue(setAttrs.size() == 0);
172:            }
173:
174:            public final void testGetMBeanInfo() {
175:                MBeanInfo mbi = mb.getMBeanInfo();
176:                assertNotNull(mbi);
177:
178:                // Now make sure that what we got back is what we expected.
179:
180:                // Class name
181:                assertTrue(mbi.getClassName().equals(mb.getClass().getName()));
182:
183:                // No public constructors
184:                MBeanConstructorInfo[] constructors = mbi.getConstructors();
185:                assertNotNull(constructors);
186:                assertTrue(constructors.length == 0);
187:
188:                // No public operations
189:                MBeanOperationInfo[] operations = mbi.getOperations();
190:                assertNotNull(operations);
191:                assertTrue(operations.length == 0);
192:
193:                // No public notifications
194:                MBeanNotificationInfo[] notifications = mbi.getNotifications();
195:                assertNotNull(notifications);
196:                assertTrue(notifications.length == 0);
197:
198:                // Description is just the class name (until I hear it should be
199:                // different)
200:                assertTrue(mbi.getDescription().equals(mb.getClass().getName()));
201:
202:                // 4 standard attributes
203:                MBeanAttributeInfo[] attributes = mbi.getAttributes();
204:                assertNotNull(attributes);
205:                assertTrue(attributes.length == 4);
206:                for (int i = 0; i < attributes.length; i++) {
207:                    MBeanAttributeInfo info = attributes[i];
208:                    assertNotNull(info);
209:                    validateAttributeInfo(info);
210:                }// end for
211:            }
212:
213:            @Override
214:            protected void populateTestAttributes() {
215:                attribs = new Hashtable<String, AttributeData>();
216:                attribs.put("Arch", new AttributeData(String.class.getName(),
217:                        true, false, false));
218:                attribs.put("AvailableProcessors", new AttributeData(
219:                        Integer.TYPE.getName(), true, false, false));
220:                attribs.put("Name", new AttributeData(String.class.getName(),
221:                        true, false, false));
222:                attribs.put("Version", new AttributeData(
223:                        String.class.getName(), true, false, false));
224:            }
225:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.