Source Code Cross Referenced for TabularDataSupportTest.java in  » JMX » mx4j » test » javax » management » openmbean » 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.openmbean 
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:         */package test.javax.management.openmbean;
008:
009:        import java.util.Collection;
010:        import java.util.Set;
011:        import javax.management.openmbean.CompositeData;
012:        import javax.management.openmbean.CompositeDataSupport;
013:        import javax.management.openmbean.CompositeType;
014:        import javax.management.openmbean.OpenType;
015:        import javax.management.openmbean.SimpleType;
016:        import javax.management.openmbean.TabularData;
017:        import javax.management.openmbean.TabularDataSupport;
018:        import javax.management.openmbean.TabularType;
019:
020:        import junit.framework.TestCase;
021:
022:        /**
023:         * @version $Revision: 1.10 $
024:         */
025:        public class TabularDataSupportTest extends TestCase {
026:            private String[] itemNames = null;
027:            private String[] itemDescriptions = null;
028:            private OpenType[] itemTypes;
029:            private String[] indexNames;
030:            private CompositeType tShirtType;
031:            private TabularType allTShirtTypes;
032:            private TabularDataSupport tabularSupport;
033:            private CompositeData compositeData;
034:
035:            public TabularDataSupportTest(String s) {
036:                super (s);
037:            }
038:
039:            protected void setUp() throws Exception {
040:                super .setUp();
041:                itemNames = new String[] { "model", "color", "size", "price" };
042:                itemDescriptions = new String[] { "TShirt's model name",
043:                        "TShirt's color", "TShirt's size", "TShirt's price" };
044:                itemTypes = new OpenType[] { SimpleType.STRING,
045:                        SimpleType.STRING, SimpleType.STRING, SimpleType.FLOAT };
046:                indexNames = new String[] { "model", "color", "size" };
047:                tShirtType = new CompositeType("tShirt", "a TShirt", itemNames,
048:                        itemDescriptions, itemTypes);
049:
050:                allTShirtTypes = new TabularType("tShirts",
051:                        "List of available TShirts", tShirtType, // row type
052:                        indexNames);
053:
054:                Object[] itemValues = new Object[] { "MX4J", "red", "L",
055:                        new Float(15.0f) };
056:
057:                compositeData = new CompositeDataSupport(tShirtType, itemNames,
058:                        itemValues);
059:                // takes tabular type
060:                tabularSupport = new TabularDataSupport(allTShirtTypes);
061:            }
062:
063:            protected void tearDown() throws Exception {
064:                super .tearDown();
065:            }
066:
067:            public void testCreation() {
068:                TabularDataSupport tabularData2 = new TabularDataSupport(
069:                        allTShirtTypes);
070:                assertTrue(tabularData2 != null);
071:            }
072:
073:            public void testPut() {
074:                try {
075:                    tabularSupport.put(compositeData);
076:                    assertTrue("tabularSupport doesn't contain compositeData",
077:                            tabularSupport.containsValue(compositeData));
078:                } catch (Exception e) {
079:                    e.printStackTrace();
080:                }
081:            }
082:
083:            public void testPutAll() throws Exception {
084:                CompositeData snmpshirt = new CompositeDataSupport(tShirtType,
085:                        itemNames, new Object[] { "SNMP", "green", null,
086:                                new Float(15.0f) });
087:                CompositeData[] shirts = { compositeData, snmpshirt };
088:                tabularSupport.putAll(shirts);
089:                assertTrue("tabularSupport doesn't contain compositeData",
090:                        tabularSupport.containsValue(compositeData));
091:                assertTrue("tabularSupport doesn't contain snmpshirt",
092:                        tabularSupport.containsValue(snmpshirt));
093:            }
094:
095:            public void testRemove() throws Exception {
096:                CompositeData snmpshirt = new CompositeDataSupport(tShirtType,
097:                        itemNames, new Object[] { "SNMP", "green", null,
098:                                new Float(15.0f) });
099:                CompositeData[] shirts = { compositeData, snmpshirt };
100:                tabularSupport.putAll(shirts);
101:                CompositeData oldshirt = tabularSupport.remove(new Object[] {
102:                        "SNMP", "green", null });
103:                assertFalse("oldshirt is null", oldshirt == null);
104:                assertTrue("Expecting oldshirt equals snmpshirt", snmpshirt
105:                        .equals(oldshirt));
106:            }
107:
108:            public void testGetTabularType() {
109:                TabularType toVerify = tabularSupport.getTabularType();
110:                assertEquals(toVerify, allTShirtTypes);
111:            }
112:
113:            public void testCalculateIndex() {
114:                // returns an array of the indexNames as represented by the simpleTypes(itemTypes) ie returns the values for the index names which are the simpleTypes
115:                Object[] object = tabularSupport.calculateIndex(compositeData);
116:                assertTrue(object.length == indexNames.length);
117:            }
118:
119:            public void testContainsValue() {
120:                OpenType[] keyTypes = new OpenType[] { SimpleType.STRING,
121:                        SimpleType.STRING, SimpleType.STRING };
122:                tabularSupport.put(compositeData);
123:                boolean expected = tabularSupport.containsValue(compositeData);
124:                assertTrue(expected);
125:            }
126:
127:            public void testContainsValueMissingValue() throws Exception {
128:                CompositeData snmpshirt = new CompositeDataSupport(tShirtType,
129:                        itemNames, new Object[] { "SNMP", "green", "M",
130:                                new Float(15.0f) });
131:                tabularSupport.put(compositeData);
132:                tabularSupport.put(snmpshirt);
133:                assertTrue("Should contain MX4J and SNMP shirts",
134:                        tabularSupport.containsValue(compositeData)
135:                                && tabularSupport.containsValue(snmpshirt));
136:                CompositeData jmxshirt = new CompositeDataSupport(tShirtType,
137:                        itemNames, new Object[] { "JMX", "blue", "M",
138:                                new Float(15.0f) });
139:                assertFalse("Contains JMX shirt", tabularSupport
140:                        .containsValue(jmxshirt));
141:                CompositeData bogusshirt = new CompositeDataSupport(tShirtType,
142:                        itemNames, new Object[] { "Bogus", null, "M",
143:                                new Float(15.0f) });
144:                assertFalse("Contains Bogus shirt", tabularSupport
145:                        .containsValue(bogusshirt));
146:            }
147:
148:            public void testContainsValueNullValue() throws Exception {
149:                assertFalse("Contains 'null'", tabularSupport
150:                        .containsValue(null));
151:            }
152:
153:            public void testKeySet() {
154:                tabularSupport.put(compositeData);
155:                Set set = tabularSupport.keySet();
156:                assertTrue(set.size() == 1);
157:            }
158:
159:            public void testValues() {
160:                tabularSupport.put(compositeData);
161:                Collection values = tabularSupport.values();
162:                assertTrue(values.contains(compositeData));
163:            }
164:
165:            public void testEquals() throws Exception {
166:                assertFalse("Equal to 'null'", tabularSupport.equals(null));
167:                assertFalse("Equal to Non-TabularData", tabularSupport
168:                        .equals(new Integer(42)));
169:
170:                String[] items = { "model", "color", "size", "price" };
171:
172:                String[] usdescriptions = { "Manufacturer's model name",
173:                        "The shirt's color", "How big is it",
174:                        "How much does it cost (dollars)" };
175:                String[] eurodescriptions = { "Designer's model name",
176:                        "The hue of the garment", "Garment size",
177:                        "How much does it cost (euros)" };
178:
179:                OpenType[] types = { SimpleType.STRING, SimpleType.STRING,
180:                        SimpleType.STRING, SimpleType.FLOAT };
181:                String[] indices = { "model", "color", "size" };
182:
183:                CompositeType usst = new CompositeType("tShirt", "US Shirt",
184:                        items, usdescriptions, types);
185:                CompositeType eurost = new CompositeType("tShirt",
186:                        "European Shirt", items, usdescriptions, types);
187:
188:                TabularType usstt = new TabularType("tShirts",
189:                        "List of available US Shirts", usst, indices);
190:                TabularType eurostt = new TabularType("tShirts",
191:                        "List of available European Shirts", eurost, indices);
192:
193:                TabularData ussdata = new TabularDataSupport(usstt);
194:                TabularData eurosdata = new TabularDataSupport(eurostt);
195:                assertTrue("Expecting equality for tabular shirt data", ussdata
196:                        .equals(eurosdata));
197:                assertTrue("Expecting equal hash codes for equal data",
198:                        eurosdata.hashCode() == ussdata.hashCode());
199:
200:                OpenType[] txtypes = { SimpleType.STRING, SimpleType.STRING,
201:                        SimpleType.STRING, SimpleType.DOUBLE };
202:                CompositeType txst = new CompositeType("tShirt", "Texas Shirt",
203:                        items, usdescriptions, txtypes);
204:                TabularType txstt = new TabularType("tShirts",
205:                        "List of available Texas Shirts", txst, indices);
206:                TabularData txsdata = new TabularDataSupport(txstt);
207:                assertFalse("Texas shirt equals US shirt", ussdata
208:                        .equals(txsdata));
209:
210:                CompositeData ussnmpshirt = new CompositeDataSupport(usst,
211:                        items, new Object[] { "SNMP", "green", "M",
212:                                new Float(15.0f) });
213:                CompositeData usjmxshirt = new CompositeDataSupport(usst,
214:                        items, new Object[] { "JMX", "blue", "M",
215:                                new Float(15.0f) });
216:                ussdata.put(ussnmpshirt);
217:                ussdata.put(usjmxshirt);
218:
219:                CompositeData eurosnmpshirt = new CompositeDataSupport(usst,
220:                        items, new Object[] { "SNMP", "green", "M",
221:                                new Float(15.0f) });
222:                CompositeData eurojmxshirt = new CompositeDataSupport(usst,
223:                        items, new Object[] { "JMX", "blue", "M",
224:                                new Float(15.0f) });
225:                eurosdata.put(eurosnmpshirt);
226:                eurosdata.put(eurojmxshirt);
227:
228:                assertTrue("Expecting US and Euro shirt data to be equal",
229:                        ussdata.equals(eurosdata));
230:                assertTrue(
231:                        "Expecting US and Euro shirt data hash codes to be equal",
232:                        eurosdata.hashCode() == ussdata.hashCode());
233:                int ushashcode = ussdata.getTabularType().hashCode();
234:                ushashcode += ussnmpshirt.hashCode();
235:                ushashcode += usjmxshirt.hashCode();
236:                assertTrue("Unexpected hash code computation", ussdata
237:                        .hashCode() == ushashcode);
238:            }
239:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.