Source Code Cross Referenced for CompositeDataSupportTestCase.java in  » EJB-Server-JBoss-4.2.1 » jmx » test » compliance » 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 » EJB Server JBoss 4.2.1 » jmx » test.compliance.openmbean 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package test.compliance.openmbean;
023:
024:        import java.io.ByteArrayInputStream;
025:        import java.io.ByteArrayOutputStream;
026:        import java.io.ObjectInputStream;
027:        import java.io.ObjectOutputStream;
028:        import java.util.Arrays;
029:        import java.util.Collection;
030:        import java.util.HashMap;
031:        import java.util.List;
032:
033:        import javax.management.openmbean.CompositeDataSupport;
034:        import javax.management.openmbean.CompositeType;
035:        import javax.management.openmbean.InvalidKeyException;
036:        import javax.management.openmbean.OpenDataException;
037:        import javax.management.openmbean.OpenType;
038:        import javax.management.openmbean.SimpleType;
039:
040:        import junit.framework.TestCase;
041:
042:        /**
043:         * Composite data support tests.<p>
044:         *
045:         * @author  <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
046:         */
047:        public class CompositeDataSupportTestCase extends TestCase {
048:            // Static --------------------------------------------------------------------
049:
050:            // Attributes ----------------------------------------------------------------
051:
052:            // Constructor ---------------------------------------------------------------
053:
054:            /**
055:             * Construct the test
056:             */
057:            public CompositeDataSupportTestCase(String s) {
058:                super (s);
059:            }
060:
061:            // Tests ---------------------------------------------------------------------
062:
063:            public void testCompositeDataSupport() throws Exception {
064:                String[] itemNames = new String[] { "name1", "name2" };
065:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
066:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
067:                        SimpleType.INTEGER };
068:                CompositeType compositeType = new CompositeType("typeName",
069:                        "description", itemNames, itemDescriptions, itemTypes);
070:                HashMap map = new HashMap();
071:                map.put("name1", "value1");
072:                map.put("name2", new Integer(2));
073:                new CompositeDataSupport(compositeType, map);
074:                new CompositeDataSupport(compositeType, new String[] { "name1",
075:                        "name2" }, new Object[] { "value1", new Integer(2) });
076:            }
077:
078:            public void testGetCompositeType() throws Exception {
079:                String[] itemNames = new String[] { "name1", "name2" };
080:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
081:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
082:                        SimpleType.INTEGER };
083:                CompositeType compositeType = new CompositeType("typeName",
084:                        "description", itemNames, itemDescriptions, itemTypes);
085:                HashMap map = new HashMap();
086:                map.put("name1", "value1");
087:                map.put("name2", new Integer(2));
088:                CompositeDataSupport data = new CompositeDataSupport(
089:                        compositeType, map);
090:                assertEquals(compositeType, data.getCompositeType());
091:            }
092:
093:            public void testGet() throws Exception {
094:                String[] itemNames = new String[] { "name1", "name2" };
095:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
096:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
097:                        SimpleType.INTEGER };
098:                CompositeType compositeType = new CompositeType("typeName",
099:                        "description", itemNames, itemDescriptions, itemTypes);
100:                HashMap map = new HashMap();
101:                map.put("name1", "value1");
102:                map.put("name2", new Integer(2));
103:                CompositeDataSupport data = new CompositeDataSupport(
104:                        compositeType, map);
105:                assertEquals("value1", data.get("name1"));
106:                assertEquals(new Integer(2), data.get("name2"));
107:            }
108:
109:            public void testGetAll() throws Exception {
110:                String[] itemNames = new String[] { "name1", "name2" };
111:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
112:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
113:                        SimpleType.INTEGER };
114:                CompositeType compositeType = new CompositeType("typeName",
115:                        "description", itemNames, itemDescriptions, itemTypes);
116:                HashMap map = new HashMap();
117:                map.put("name1", "value1");
118:                map.put("name2", new Integer(2));
119:                CompositeDataSupport data = new CompositeDataSupport(
120:                        compositeType, map);
121:                Object[] result = data
122:                        .getAll(new String[] { "name1", "name2" });
123:                assertEquals("value1", result[0]);
124:                assertEquals(new Integer(2), result[1]);
125:                result = data.getAll(new String[] { "name2", "name1" });
126:                assertEquals("value1", result[1]);
127:                assertEquals(new Integer(2), result[0]);
128:                result = data.getAll(new String[] { "name1" });
129:                assertEquals("value1", result[0]);
130:                result = data.getAll(new String[] { "name2" });
131:                assertEquals(new Integer(2), result[0]);
132:            }
133:
134:            public void testContainsKey() throws Exception {
135:                String[] itemNames = new String[] { "name1", "name2" };
136:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
137:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
138:                        SimpleType.INTEGER };
139:                CompositeType compositeType = new CompositeType("typeName",
140:                        "description", itemNames, itemDescriptions, itemTypes);
141:                HashMap map = new HashMap();
142:                map.put("name1", "value1");
143:                map.put("name2", new Integer(2));
144:                CompositeDataSupport data = new CompositeDataSupport(
145:                        compositeType, map);
146:                assertTrue("data should contain key name1", data
147:                        .containsKey("name1") == true);
148:                assertTrue("data should contain key name2", data
149:                        .containsKey("name2") == true);
150:                assertTrue("data should not contain key nameX", data
151:                        .containsKey("nameX") == false);
152:                assertTrue("data should not contain key null", data
153:                        .containsKey(null) == false);
154:                assertTrue("data should not contain key <empty>", data
155:                        .containsKey("") == false);
156:            }
157:
158:            public void testContainsValue() throws Exception {
159:                String[] itemNames = new String[] { "name1", "name2" };
160:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
161:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
162:                        SimpleType.INTEGER };
163:                CompositeType compositeType = new CompositeType("typeName",
164:                        "description", itemNames, itemDescriptions, itemTypes);
165:                HashMap map = new HashMap();
166:                map.put("name1", "value1");
167:                map.put("name2", new Integer(2));
168:                CompositeDataSupport data = new CompositeDataSupport(
169:                        compositeType, map);
170:                assertTrue("data should contain value value1", data
171:                        .containsValue("value1") == true);
172:                assertTrue("data should contain value 2", data
173:                        .containsValue(new Integer(2)) == true);
174:                assertTrue("data should not contain value name1", data
175:                        .containsValue("name1") == false);
176:                assertTrue("data should not contain key null", data
177:                        .containsValue(null) == false);
178:                assertTrue("data should not contain key <empty>", data
179:                        .containsValue("") == false);
180:
181:                map.clear();
182:                map.put("name1", "value1");
183:                map.put("name2", null);
184:                data = new CompositeDataSupport(compositeType, map);
185:                assertTrue("data should contain value null", data
186:                        .containsValue(null) == true);
187:            }
188:
189:            public void testValues() throws Exception {
190:                String[] itemNames = new String[] { "name1", "name2" };
191:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
192:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
193:                        SimpleType.INTEGER };
194:                CompositeType compositeType = new CompositeType("typeName",
195:                        "description", itemNames, itemDescriptions, itemTypes);
196:                HashMap map = new HashMap();
197:                map.put("name1", "value1");
198:                map.put("name2", new Integer(2));
199:                CompositeDataSupport data = new CompositeDataSupport(
200:                        compositeType, map);
201:                Collection values = data.values();
202:                assertTrue("data values contain 2 elements", values.size() == 2);
203:                assertTrue("data values should have value1", values
204:                        .contains("value1"));
205:                assertTrue("data values should have 2", values
206:                        .contains(new Integer(2)));
207:                assertTrue("data values should not have name1", values
208:                        .contains("name1") == false);
209:                assertTrue("data values should not have null", values
210:                        .contains(null) == false);
211:                assertTrue("data values should not have <empty>", values
212:                        .contains("") == false);
213:
214:                map.clear();
215:                map.put("name1", "value1");
216:                map.put("name2", null);
217:                data = new CompositeDataSupport(compositeType, map);
218:                values = data.values();
219:                assertTrue("data values should contain value null", values
220:                        .contains(null) == true);
221:            }
222:
223:            public void testEquals() throws Exception {
224:                String[] itemNames = new String[] { "name1", "name2" };
225:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
226:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
227:                        SimpleType.INTEGER };
228:                CompositeType compositeType = new CompositeType("typeName",
229:                        "description", itemNames, itemDescriptions, itemTypes);
230:                HashMap map = new HashMap();
231:                map.put("name1", "value1");
232:                map.put("name2", new Integer(2));
233:                CompositeDataSupport data = new CompositeDataSupport(
234:                        compositeType, map);
235:
236:                assertTrue("data should equal itself", data.equals(data));
237:                assertTrue("data should not equal null",
238:                        data.equals(null) == false);
239:                assertTrue("data should not equal non CompositeData", data
240:                        .equals(new Object()) == false);
241:
242:                String[] itemNames2 = new String[] { "name1", "name2" };
243:                String[] itemDescriptions2 = new String[] { "desc1", "desc2" };
244:                OpenType[] itemTypes2 = new OpenType[] { SimpleType.STRING,
245:                        SimpleType.INTEGER };
246:                CompositeType compositeType2 = new CompositeType("typeName",
247:                        "description", itemNames2, itemDescriptions2,
248:                        itemTypes2);
249:                HashMap map2 = new HashMap();
250:                map2.put("name1", "value1");
251:                map2.put("name2", new Integer(2));
252:                CompositeDataSupport data2 = new CompositeDataSupport(
253:                        compositeType2, map2);
254:
255:                assertTrue(
256:                        "data should equal with data2 with different instance of the same composite type",
257:                        data.equals(data2));
258:                assertTrue(
259:                        "data2 should equal with data with different instance of the same composite type",
260:                        data2.equals(data));
261:
262:                compositeType2 = new CompositeType("typeName2", "description",
263:                        itemNames2, itemDescriptions2, itemTypes2);
264:                data2 = new CompositeDataSupport(compositeType2, map2);
265:
266:                assertTrue(
267:                        "data should not be equal with data2 with different composite type",
268:                        data.equals(data2) == false);
269:                assertTrue(
270:                        "data2 should not be equal with data with different composite type",
271:                        data2.equals(data) == false);
272:
273:                map2 = new HashMap();
274:                map2.put("name1", "value1");
275:                map2.put("name2", new Integer(3));
276:                data2 = new CompositeDataSupport(compositeType, map2);
277:
278:                assertTrue(
279:                        "data should not be equal with data2 with different values",
280:                        data.equals(data2) == false);
281:                assertTrue(
282:                        "data2 should not be equal with data with different value",
283:                        data2.equals(data) == false);
284:            }
285:
286:            public void testHashCode() throws Exception {
287:                String[] itemNames = new String[] { "name1", "name2" };
288:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
289:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
290:                        SimpleType.INTEGER };
291:                CompositeType compositeType = new CompositeType("typeName",
292:                        "description", itemNames, itemDescriptions, itemTypes);
293:                HashMap map = new HashMap();
294:                map.put("name1", "value1");
295:                map.put("name2", new Integer(2));
296:                CompositeDataSupport data = new CompositeDataSupport(
297:                        compositeType, map);
298:
299:                int myHashCode = compositeType.hashCode() + "value1".hashCode()
300:                        + new Integer(2).hashCode();
301:                assertTrue("Wrong hash code generated", myHashCode == data
302:                        .hashCode());
303:            }
304:
305:            public void testToString() throws Exception {
306:                String[] itemNames = new String[] { "name1", "name2" };
307:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
308:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
309:                        SimpleType.INTEGER };
310:                CompositeType compositeType = new CompositeType("typeName",
311:                        "description", itemNames, itemDescriptions, itemTypes);
312:                HashMap map = new HashMap();
313:                map.put("name1", "value1");
314:                map.put("name2", new Integer(2));
315:                CompositeDataSupport data = new CompositeDataSupport(
316:                        compositeType, map);
317:
318:                String toString = data.toString();
319:
320:                assertTrue("toString() should contain the composite type",
321:                        toString.indexOf(compositeType.toString()) != -1);
322:                assertTrue("toString() should contain name1=value1", toString
323:                        .indexOf("name1=value1") != -1);
324:                assertTrue("toString() should contain name2=" + new Integer(2),
325:                        toString.indexOf("name2=" + new Integer(2)) != -1);
326:            }
327:
328:            public void testSerialization() throws Exception {
329:                String[] itemNames = new String[] { "name1", "name2" };
330:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
331:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
332:                        SimpleType.INTEGER };
333:                CompositeType compositeType = new CompositeType("typeName",
334:                        "description", itemNames, itemDescriptions, itemTypes);
335:                HashMap map = new HashMap();
336:                map.put("name1", "value1");
337:                map.put("name2", new Integer(2));
338:                CompositeDataSupport data = new CompositeDataSupport(
339:                        compositeType, map);
340:
341:                // Serialize it
342:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
343:                ObjectOutputStream oos = new ObjectOutputStream(baos);
344:                oos.writeObject(data);
345:
346:                // Deserialize it
347:                ByteArrayInputStream bais = new ByteArrayInputStream(baos
348:                        .toByteArray());
349:                ObjectInputStream ois = new ObjectInputStream(bais);
350:                Object result = ois.readObject();
351:
352:                assertEquals(data, result);
353:            }
354:
355:            public void testErrorsArray() throws Exception {
356:                String[] itemNames = new String[] { "name1", "name2" };
357:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
358:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
359:                        SimpleType.INTEGER };
360:                CompositeType compositeType = new CompositeType("typeName",
361:                        "description", itemNames, itemDescriptions, itemTypes);
362:                Object[] itemValues = new Object[] { "value1", new Integer(2) };
363:
364:                boolean caught = false;
365:                try {
366:                    new CompositeDataSupport(null, itemNames, itemValues);
367:                } catch (IllegalArgumentException e) {
368:                    caught = true;
369:                }
370:                if (caught == false)
371:                    fail("Excepted IllegalArgumentException for null composite type");
372:
373:                caught = false;
374:                try {
375:                    new CompositeDataSupport(compositeType, null, itemValues);
376:                } catch (IllegalArgumentException e) {
377:                    caught = true;
378:                }
379:                if (caught == false)
380:                    fail("Excepted IllegalArgumentException for null item names");
381:
382:                caught = false;
383:                try {
384:                    new CompositeDataSupport(compositeType, new String[0],
385:                            itemValues);
386:                } catch (IllegalArgumentException e) {
387:                    caught = true;
388:                }
389:                if (caught == false)
390:                    fail("Excepted IllegalArgumentException for empty item names");
391:
392:                caught = false;
393:                try {
394:                    new CompositeDataSupport(compositeType, itemNames, null);
395:                } catch (IllegalArgumentException e) {
396:                    caught = true;
397:                }
398:                if (caught == false)
399:                    fail("Excepted IllegalArgumentException for null item values");
400:
401:                caught = false;
402:                try {
403:                    new CompositeDataSupport(compositeType, itemNames,
404:                            new Object[0]);
405:                } catch (IllegalArgumentException e) {
406:                    caught = true;
407:                }
408:                if (caught == false)
409:                    fail("Excepted IllegalArgumentException for empty item values");
410:
411:                caught = false;
412:                try {
413:                    new CompositeDataSupport(compositeType, new String[] {
414:                            "name1", null }, itemValues);
415:                } catch (IllegalArgumentException e) {
416:                    caught = true;
417:                }
418:                if (caught == false)
419:                    fail("Excepted IllegalArgumentException for a null item name");
420:
421:                caught = false;
422:                try {
423:                    new CompositeDataSupport(compositeType, new String[] {
424:                            "name1", "" }, itemValues);
425:                } catch (IllegalArgumentException e) {
426:                    caught = true;
427:                }
428:                if (caught == false)
429:                    fail("Excepted IllegalArgumentException for an empty item name");
430:
431:                caught = false;
432:                try {
433:                    new CompositeDataSupport(compositeType, itemNames,
434:                            new Object[] { "wrong" });
435:                } catch (IllegalArgumentException e) {
436:                    caught = true;
437:                }
438:                if (caught == false)
439:                    fail("Excepted IllegalArgumentException for mismatch in number of itemNames/itemValues");
440:
441:                caught = false;
442:                try {
443:                    new CompositeDataSupport(compositeType,
444:                            new String[] { "name1" }, new Object[] { "value1" });
445:                } catch (OpenDataException e) {
446:                    caught = true;
447:                }
448:                if (caught == false)
449:                    fail("Excepted OpenDataException for mismatch in number of itemNames for CompositeType/CompositeData");
450:
451:                caught = false;
452:                try {
453:                    new CompositeDataSupport(compositeType, new String[] {
454:                            "name1", "wrongName" }, itemValues);
455:                } catch (OpenDataException e) {
456:                    caught = true;
457:                }
458:                if (caught == false)
459:                    fail("Excepted OpenDataException for an item name not in the composite type");
460:
461:                caught = false;
462:                try {
463:                    new CompositeDataSupport(compositeType, itemNames,
464:                            new Object[] { "value1", "wrong" });
465:                } catch (OpenDataException e) {
466:                    caught = true;
467:                }
468:                if (caught == false)
469:                    fail("Excepted OpenDataException for an item value of the wrong type");
470:
471:                new CompositeDataSupport(compositeType, itemNames,
472:                        new Object[] { "value1", null });
473:            }
474:
475:            public void testErrorsMap() throws Exception {
476:                String[] itemNames = new String[] { "name1", "name2" };
477:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
478:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
479:                        SimpleType.INTEGER };
480:                CompositeType compositeType = new CompositeType("typeName",
481:                        "description", itemNames, itemDescriptions, itemTypes);
482:                HashMap map = new HashMap();
483:                map.put("name1", "value1");
484:                map.put("name2", new Integer(2));
485:
486:                boolean caught = false;
487:                try {
488:                    new CompositeDataSupport(null, map);
489:                } catch (IllegalArgumentException e) {
490:                    caught = true;
491:                }
492:                if (caught == false)
493:                    fail("Excepted IllegalArgumentException for null composite type");
494:
495:                caught = false;
496:                try {
497:                    new CompositeDataSupport(compositeType, null);
498:                } catch (IllegalArgumentException e) {
499:                    caught = true;
500:                }
501:                if (caught == false)
502:                    fail("Excepted IllegalArgumentException for null map");
503:
504:                caught = false;
505:                try {
506:                    new CompositeDataSupport(compositeType, new HashMap());
507:                } catch (IllegalArgumentException e) {
508:                    caught = true;
509:                }
510:                if (caught == false)
511:                    fail("Excepted IllegalArgumentException for empty map");
512:
513:                caught = false;
514:                try {
515:                    HashMap map2 = new HashMap();
516:                    map2.put("name1", "value1");
517:                    map2.put(null, new Integer(2));
518:                    new CompositeDataSupport(compositeType, map2);
519:                } catch (IllegalArgumentException e) {
520:                    caught = true;
521:                }
522:                if (caught == false)
523:                    fail("Excepted IllegalArgumentException for a null key in map");
524:
525:                caught = false;
526:                try {
527:                    HashMap map2 = new HashMap();
528:                    map2.put("name1", "value1");
529:                    map2.put("", new Integer(2));
530:                    new CompositeDataSupport(compositeType, map2);
531:                } catch (IllegalArgumentException e) {
532:                    caught = true;
533:                }
534:                if (caught == false)
535:                    fail("Excepted IllegalArgumentException for an empty key in map");
536:
537:                caught = false;
538:                try {
539:                    HashMap map2 = new HashMap();
540:                    map2.put("name1", "value1");
541:                    new CompositeDataSupport(compositeType, map2);
542:                } catch (OpenDataException e) {
543:                    caught = true;
544:                }
545:                if (caught == false)
546:                    fail("Excepted OpenDataException for mismatch in number of items for CompositeType/CompositeData");
547:
548:                caught = false;
549:                try {
550:                    HashMap map2 = new HashMap();
551:                    map2.put("name1", "value1");
552:                    map2.put("wrongName", new Integer(2));
553:                    new CompositeDataSupport(compositeType, map2);
554:                } catch (OpenDataException e) {
555:                    caught = true;
556:                }
557:                if (caught == false)
558:                    fail("Excepted OpenDataException for an item name not in the composite type");
559:
560:                caught = false;
561:                try {
562:                    HashMap map2 = new HashMap();
563:                    map2.put("name1", "value1");
564:                    map2.put("name2", "wrong");
565:                    new CompositeDataSupport(compositeType, map2);
566:                } catch (OpenDataException e) {
567:                    caught = true;
568:                }
569:                if (caught == false)
570:                    fail("Excepted OpenDataException for an item value of the wrong type");
571:
572:                caught = false;
573:                try {
574:                    HashMap map2 = new HashMap();
575:                    map2.put("name1", "value1");
576:                    map2.put(new Integer(2), new Integer(2));
577:                    new CompositeDataSupport(compositeType, map2);
578:                } catch (ArrayStoreException e) {
579:                    caught = true;
580:                }
581:                if (caught == false)
582:                    fail("Excepted ArrayStoreException for a non String key in map");
583:
584:                HashMap map2 = new HashMap();
585:                map2.put("name1", "value1");
586:                map2.put("name2", null);
587:                new CompositeDataSupport(compositeType, map2);
588:            }
589:
590:            public void testErrors() throws Exception {
591:                String[] itemNames = new String[] { "name1", "name2" };
592:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
593:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
594:                        SimpleType.INTEGER };
595:                CompositeType compositeType = new CompositeType("typeName",
596:                        "description", itemNames, itemDescriptions, itemTypes);
597:                HashMap map = new HashMap();
598:                map.put("name1", "value1");
599:                map.put("name2", new Integer(2));
600:                CompositeDataSupport data = new CompositeDataSupport(
601:                        compositeType, map);
602:
603:                boolean caught = false;
604:                try {
605:                    data.get(null);
606:                } catch (IllegalArgumentException e) {
607:                    caught = true;
608:                }
609:                if (caught == false)
610:                    fail("Excepted IllegalArgumentException for get and a null key");
611:
612:                caught = false;
613:                try {
614:                    data.get("");
615:                } catch (IllegalArgumentException e) {
616:                    caught = true;
617:                }
618:                if (caught == false)
619:                    fail("Excepted IllegalArgumentException for get and an empty key");
620:
621:                caught = false;
622:                try {
623:                    data.get("wrong");
624:                } catch (InvalidKeyException e) {
625:                    caught = true;
626:                }
627:                if (caught == false)
628:                    fail("Excepted InvalidKeyException for get and a wrong key");
629:
630:                caught = false;
631:                try {
632:                    data.getAll(new String[] { "name1", null });
633:                } catch (IllegalArgumentException e) {
634:                    caught = true;
635:                }
636:                if (caught == false)
637:                    fail("Excepted IllegalArgumentException for getAll and a null key");
638:
639:                caught = false;
640:                try {
641:                    data.getAll(new String[] { "name1", "" });
642:                } catch (IllegalArgumentException e) {
643:                    caught = true;
644:                }
645:                if (caught == false)
646:                    fail("Excepted IllegalArgumentException for getAll and an empty key");
647:
648:                caught = false;
649:                try {
650:                    data.getAll(new String[] { "name1", "wrong" });
651:                } catch (IllegalArgumentException e) {
652:                    caught = true;
653:                }
654:                if (caught == false)
655:                    fail("Excepted InvalidKeyException for getAll and an invalid key");
656:            }
657:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.