Source Code Cross Referenced for TabularDataSupportTestCase.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) 


0001:        /*
0002:         * JBoss, Home of Professional Open Source.
0003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
0004:         * as indicated by the @author tags. See the copyright.txt file in the
0005:         * distribution for a full listing of individual contributors.
0006:         *
0007:         * This is free software; you can redistribute it and/or modify it
0008:         * under the terms of the GNU Lesser General Public License as
0009:         * published by the Free Software Foundation; either version 2.1 of
0010:         * the License, or (at your option) any later version.
0011:         *
0012:         * This software is distributed in the hope that it will be useful,
0013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0015:         * Lesser General Public License for more details.
0016:         *
0017:         * You should have received a copy of the GNU Lesser General Public
0018:         * License along with this software; if not, write to the Free
0019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
0020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
0021:         */
0022:        package test.compliance.openmbean;
0023:
0024:        import java.io.ByteArrayInputStream;
0025:        import java.io.ByteArrayOutputStream;
0026:        import java.io.ObjectInputStream;
0027:        import java.io.ObjectOutputStream;
0028:        import java.util.Arrays;
0029:        import java.util.Collection;
0030:        import java.util.HashMap;
0031:        import java.util.Map;
0032:        import java.util.Set;
0033:
0034:        import javax.management.openmbean.CompositeData;
0035:        import javax.management.openmbean.CompositeDataSupport;
0036:        import javax.management.openmbean.CompositeType;
0037:        import javax.management.openmbean.InvalidKeyException;
0038:        import javax.management.openmbean.InvalidOpenTypeException;
0039:        import javax.management.openmbean.KeyAlreadyExistsException;
0040:        import javax.management.openmbean.OpenType;
0041:        import javax.management.openmbean.SimpleType;
0042:        import javax.management.openmbean.TabularDataSupport;
0043:        import javax.management.openmbean.TabularType;
0044:
0045:        import junit.framework.TestCase;
0046:
0047:        /**
0048:         * Tabular data support tests.<p>
0049:         *
0050:         * @author  <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
0051:         */
0052:        public class TabularDataSupportTestCase extends TestCase {
0053:            // Static --------------------------------------------------------------------
0054:
0055:            // Attributes ----------------------------------------------------------------
0056:
0057:            // Constructor ---------------------------------------------------------------
0058:
0059:            /**
0060:             * Construct the test
0061:             */
0062:            public TabularDataSupportTestCase(String s) {
0063:                super (s);
0064:            }
0065:
0066:            // Tests ---------------------------------------------------------------------
0067:
0068:            public void testTabularDataSupport() throws Exception {
0069:                String[] itemNames = new String[] { "name1", "name2" };
0070:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0071:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0072:                        SimpleType.INTEGER };
0073:                CompositeType rowType = new CompositeType("rowTypeName",
0074:                        "rowDescription", itemNames, itemDescriptions,
0075:                        itemTypes);
0076:
0077:                String[] indexNames = new String[] { "name1", "name2" };
0078:                TabularType tabularType = new TabularType("typeName",
0079:                        "description", rowType, indexNames);
0080:
0081:                TabularDataSupport data = new TabularDataSupport(tabularType);
0082:                TabularDataSupport data2 = new TabularDataSupport(tabularType,
0083:                        100, .5f);
0084:            }
0085:
0086:            public void testGetTabularType() throws Exception {
0087:                String[] itemNames = new String[] { "name1", "name2" };
0088:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0089:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0090:                        SimpleType.INTEGER };
0091:                CompositeType rowType = new CompositeType("rowTypeName",
0092:                        "rowDescription", itemNames, itemDescriptions,
0093:                        itemTypes);
0094:
0095:                String[] indexNames = new String[] { "name1", "name2" };
0096:                TabularType tabularType = new TabularType("typeName",
0097:                        "description", rowType, indexNames);
0098:
0099:                TabularDataSupport data = new TabularDataSupport(tabularType);
0100:                assertTrue("Expected the same tabular type", data
0101:                        .getTabularType().equals(tabularType));
0102:            }
0103:
0104:            public void testCalculateIndex() throws Exception {
0105:                String[] itemNames = new String[] { "name1", "name2" };
0106:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0107:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0108:                        SimpleType.INTEGER };
0109:                CompositeType rowType = new CompositeType("rowTypeName",
0110:                        "rowDescription", itemNames, itemDescriptions,
0111:                        itemTypes);
0112:
0113:                String[] indexNames = new String[] { "name1", "name2" };
0114:                TabularType tabularType = new TabularType("typeName",
0115:                        "description", rowType, indexNames);
0116:
0117:                TabularDataSupport data = new TabularDataSupport(tabularType);
0118:
0119:                HashMap map = new HashMap();
0120:                map.put("name1", "value1");
0121:                map.put("name2", new Integer(2));
0122:                CompositeDataSupport compData = new CompositeDataSupport(
0123:                        rowType, map);
0124:                Object[] index = data.calculateIndex(compData);
0125:
0126:                assertTrue("Expected index element 0 to be value1", index[0]
0127:                        .equals("value1"));
0128:                assertTrue("Expected index element 1 to be 2", index[1]
0129:                        .equals(new Integer(2)));
0130:
0131:                map = new HashMap();
0132:                map.put("name1", "value2");
0133:                map.put("name2", new Integer(3));
0134:                compData = new CompositeDataSupport(rowType, map);
0135:                index = data.calculateIndex(compData);
0136:
0137:                assertTrue("Expected index element 0 to be value2", index[0]
0138:                        .equals("value2"));
0139:                assertTrue("Expected index element 1 to be 3", index[1]
0140:                        .equals(new Integer(3)));
0141:            }
0142:
0143:            public void testContainsKeyObject() throws Exception {
0144:                String[] itemNames = new String[] { "name1", "name2" };
0145:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0146:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0147:                        SimpleType.INTEGER };
0148:                CompositeType rowType = new CompositeType("rowTypeName",
0149:                        "rowDescription", itemNames, itemDescriptions,
0150:                        itemTypes);
0151:
0152:                String[] indexNames = new String[] { "name1", "name2" };
0153:                TabularType tabularType = new TabularType("typeName",
0154:                        "description", rowType, indexNames);
0155:
0156:                TabularDataSupport data = new TabularDataSupport(tabularType);
0157:
0158:                assertTrue("Didn't expect containsKey null", data
0159:                        .containsKey(null) == false);
0160:                assertTrue("Didn't expect containsKey not an Object array",
0161:                        data.containsKey(new Object()) == false);
0162:
0163:                Object[] index = new Object[] { "value1", new Integer(2) };
0164:                assertTrue("Didn't expect containsKey on empty data", data
0165:                        .containsKey((Object) index) == false);
0166:
0167:                HashMap map = new HashMap();
0168:                map.put("name1", "value1");
0169:                map.put("name2", new Integer(3));
0170:                CompositeDataSupport compData = new CompositeDataSupport(
0171:                        rowType, map);
0172:                assertTrue("Didn't expect containsKey on index not present",
0173:                        data.containsKey((Object) index) == false);
0174:
0175:                map = new HashMap();
0176:                map.put("name1", "value1");
0177:                map.put("name2", new Integer(2));
0178:                compData = new CompositeDataSupport(rowType, map);
0179:                data.put(compData);
0180:                assertTrue("Expected containsKey", data
0181:                        .containsKey((Object) index));
0182:
0183:                map = new HashMap();
0184:                map.put("name1", "value1");
0185:                map.put("name2", new Integer(3));
0186:                compData = new CompositeDataSupport(rowType, map);
0187:                assertTrue(
0188:                        "Didn't expect containsKey on index still not present",
0189:                        data
0190:                                .containsKey((Object) data
0191:                                        .calculateIndex(compData)) == false);
0192:
0193:                data.remove(index);
0194:                assertTrue("Didn't expect removed data in containsKey", data
0195:                        .containsKey((Object) index) == false);
0196:            }
0197:
0198:            public void testContainsKeyObjectArray() throws Exception {
0199:                String[] itemNames = new String[] { "name1", "name2" };
0200:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0201:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0202:                        SimpleType.INTEGER };
0203:                CompositeType rowType = new CompositeType("rowTypeName",
0204:                        "rowDescription", itemNames, itemDescriptions,
0205:                        itemTypes);
0206:
0207:                String[] indexNames = new String[] { "name1", "name2" };
0208:                TabularType tabularType = new TabularType("typeName",
0209:                        "description", rowType, indexNames);
0210:
0211:                TabularDataSupport data = new TabularDataSupport(tabularType);
0212:
0213:                assertTrue("Didn't expect containsKey null", data
0214:                        .containsKey(null) == false);
0215:                assertTrue("Didn't expect containsKey not an Object array",
0216:                        data.containsKey(new Object()) == false);
0217:
0218:                Object[] index = new Object[] { "value1", new Integer(2) };
0219:                assertTrue("Didn't expect containsKey on empty data", data
0220:                        .containsKey(index) == false);
0221:
0222:                HashMap map = new HashMap();
0223:                map.put("name1", "value1");
0224:                map.put("name2", new Integer(3));
0225:                CompositeDataSupport compData = new CompositeDataSupport(
0226:                        rowType, map);
0227:                assertTrue("Didn't expect containsKey on index not present",
0228:                        data.containsKey(index) == false);
0229:
0230:                map = new HashMap();
0231:                map.put("name1", "value1");
0232:                map.put("name2", new Integer(2));
0233:                compData = new CompositeDataSupport(rowType, map);
0234:                data.put(compData);
0235:                assertTrue("Expected containsKey", data.containsKey(index));
0236:
0237:                map = new HashMap();
0238:                map.put("name1", "value1");
0239:                map.put("name2", new Integer(3));
0240:                compData = new CompositeDataSupport(rowType, map);
0241:                assertTrue(
0242:                        "Didn't expect containsKey on index still not present",
0243:                        data.containsKey(data.calculateIndex(compData)) == false);
0244:
0245:                data.remove(index);
0246:                assertTrue("Didn't expect removed data in containsKey", data
0247:                        .containsKey(index) == false);
0248:            }
0249:
0250:            public void testContainsValueObject() throws Exception {
0251:                String[] itemNames = new String[] { "name1", "name2" };
0252:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0253:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0254:                        SimpleType.INTEGER };
0255:                CompositeType rowType = new CompositeType("rowTypeName",
0256:                        "rowDescription", itemNames, itemDescriptions,
0257:                        itemTypes);
0258:
0259:                String[] indexNames = new String[] { "name1", "name2" };
0260:                TabularType tabularType = new TabularType("typeName",
0261:                        "description", rowType, indexNames);
0262:
0263:                TabularDataSupport data = new TabularDataSupport(tabularType);
0264:
0265:                assertTrue("Didn't expect containsValue null", data
0266:                        .containsValue(null) == false);
0267:
0268:                itemNames = new String[] { "name1", "name2" };
0269:                itemDescriptions = new String[] { "desc1", "desc2" };
0270:                itemTypes = new OpenType[] { SimpleType.STRING,
0271:                        SimpleType.INTEGER };
0272:                CompositeType rowType2 = new CompositeType("rowTypeName2",
0273:                        "rowDescription", itemNames, itemDescriptions,
0274:                        itemTypes);
0275:
0276:                HashMap map = new HashMap();
0277:                map.put("name1", "value1");
0278:                map.put("name2", new Integer(2));
0279:                CompositeDataSupport compData2 = new CompositeDataSupport(
0280:                        rowType2, map);
0281:
0282:                assertTrue("Didn't expect containsValue wrong composite type",
0283:                        data.containsValue((Object) compData2) == false);
0284:
0285:                map = new HashMap();
0286:                map.put("name1", "value1");
0287:                map.put("name2", new Integer(3));
0288:                CompositeDataSupport compData = new CompositeDataSupport(
0289:                        rowType, map);
0290:                assertTrue("Didn't expect containsValue on data not present",
0291:                        data.containsValue((Object) compData) == false);
0292:
0293:                map = new HashMap();
0294:                map.put("name1", "value1");
0295:                map.put("name2", new Integer(2));
0296:                compData = new CompositeDataSupport(rowType, map);
0297:                data.put(compData);
0298:                assertTrue("Expected containsValue", data
0299:                        .containsValue((Object) compData));
0300:
0301:                map = new HashMap();
0302:                map.put("name1", "value1");
0303:                map.put("name2", new Integer(3));
0304:                compData = new CompositeDataSupport(rowType, map);
0305:                assertTrue(
0306:                        "Didn't expect containsValue on value still not present",
0307:                        data.containsValue((Object) compData) == false);
0308:
0309:                assertTrue(
0310:                        "Didn't expect containsValue still wrong composite type",
0311:                        data.containsValue((Object) compData2) == false);
0312:
0313:                data.remove(data.calculateIndex(compData));
0314:                assertTrue("Didn't expect removed data in containsValue", data
0315:                        .containsValue((Object) compData) == false);
0316:            }
0317:
0318:            public void testContainsValueCompositeData() throws Exception {
0319:                String[] itemNames = new String[] { "name1", "name2" };
0320:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0321:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0322:                        SimpleType.INTEGER };
0323:                CompositeType rowType = new CompositeType("rowTypeName",
0324:                        "rowDescription", itemNames, itemDescriptions,
0325:                        itemTypes);
0326:
0327:                String[] indexNames = new String[] { "name1", "name2" };
0328:                TabularType tabularType = new TabularType("typeName",
0329:                        "description", rowType, indexNames);
0330:
0331:                TabularDataSupport data = new TabularDataSupport(tabularType);
0332:
0333:                assertTrue("Didn't expect containsValue null", data
0334:                        .containsValue(null) == false);
0335:
0336:                itemNames = new String[] { "name1", "name2" };
0337:                itemDescriptions = new String[] { "desc1", "desc2" };
0338:                itemTypes = new OpenType[] { SimpleType.STRING,
0339:                        SimpleType.INTEGER };
0340:                CompositeType rowType2 = new CompositeType("rowTypeName2",
0341:                        "rowDescription", itemNames, itemDescriptions,
0342:                        itemTypes);
0343:
0344:                HashMap map = new HashMap();
0345:                map.put("name1", "value1");
0346:                map.put("name2", new Integer(2));
0347:                CompositeDataSupport compData2 = new CompositeDataSupport(
0348:                        rowType2, map);
0349:
0350:                assertTrue("Didn't expect containsValue wrong composite type",
0351:                        data.containsValue(compData2) == false);
0352:
0353:                map = new HashMap();
0354:                map.put("name1", "value1");
0355:                map.put("name2", new Integer(3));
0356:                CompositeDataSupport compData = new CompositeDataSupport(
0357:                        rowType, map);
0358:                assertTrue("Didn't expect containsValue on data not present",
0359:                        data.containsValue(compData) == false);
0360:
0361:                map = new HashMap();
0362:                map.put("name1", "value1");
0363:                map.put("name2", new Integer(2));
0364:                compData = new CompositeDataSupport(rowType, map);
0365:                data.put(compData);
0366:                assertTrue("Expected containsValue", data
0367:                        .containsValue(compData));
0368:
0369:                map = new HashMap();
0370:                map.put("name1", "value1");
0371:                map.put("name2", new Integer(3));
0372:                compData = new CompositeDataSupport(rowType, map);
0373:                assertTrue(
0374:                        "Didn't expect containsValue on value still not present",
0375:                        data.containsValue(compData) == false);
0376:
0377:                assertTrue(
0378:                        "Didn't expect containsValue still wrong composite type",
0379:                        data.containsValue(compData2) == false);
0380:
0381:                data.remove(data.calculateIndex(compData));
0382:                assertTrue("Didn't expect removed data in containsValue", data
0383:                        .containsValue(compData) == false);
0384:            }
0385:
0386:            public void testGetObject() throws Exception {
0387:                String[] itemNames = new String[] { "name1", "name2" };
0388:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0389:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0390:                        SimpleType.INTEGER };
0391:                CompositeType rowType = new CompositeType("rowTypeName",
0392:                        "rowDescription", itemNames, itemDescriptions,
0393:                        itemTypes);
0394:
0395:                String[] indexNames = new String[] { "name1", "name2" };
0396:                TabularType tabularType = new TabularType("typeName",
0397:                        "description", rowType, indexNames);
0398:
0399:                TabularDataSupport data = new TabularDataSupport(tabularType);
0400:
0401:                Object[] index = new Object[] { "value1", new Integer(3) };
0402:                assertTrue("Expected null for get on data not present", data
0403:                        .get((Object) index) == null);
0404:
0405:                HashMap map = new HashMap();
0406:                map.put("name1", "value1");
0407:                map.put("name2", new Integer(2));
0408:                CompositeDataSupport compData = new CompositeDataSupport(
0409:                        rowType, map);
0410:                index = new Object[] { "value1", new Integer(2) };
0411:                data.put(compData);
0412:                assertTrue("Expected get to return the same value", data.get(
0413:                        (Object) index).equals(compData));
0414:
0415:                index = new Object[] { "value1", new Integer(3) };
0416:                assertTrue("Didn't expect get on value still not present", data
0417:                        .get((Object) index) == null);
0418:
0419:                index = new Object[] { "value1", new Integer(2) };
0420:                data.remove(index);
0421:                assertTrue("Didn't expect removed data in get", data
0422:                        .get((Object) index) == null);
0423:            }
0424:
0425:            public void testGetObjectArray() throws Exception {
0426:                String[] itemNames = new String[] { "name1", "name2" };
0427:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0428:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0429:                        SimpleType.INTEGER };
0430:                CompositeType rowType = new CompositeType("rowTypeName",
0431:                        "rowDescription", itemNames, itemDescriptions,
0432:                        itemTypes);
0433:
0434:                String[] indexNames = new String[] { "name1", "name2" };
0435:                TabularType tabularType = new TabularType("typeName",
0436:                        "description", rowType, indexNames);
0437:
0438:                TabularDataSupport data = new TabularDataSupport(tabularType);
0439:
0440:                Object[] index = new Object[] { "value1", new Integer(3) };
0441:                assertTrue("Expected null for get on data not present", data
0442:                        .get(index) == null);
0443:
0444:                HashMap map = new HashMap();
0445:                map.put("name1", "value1");
0446:                map.put("name2", new Integer(2));
0447:                CompositeDataSupport compData = new CompositeDataSupport(
0448:                        rowType, map);
0449:                index = new Object[] { "value1", new Integer(2) };
0450:                data.put(compData);
0451:                assertTrue("Expected get to return the same value", data.get(
0452:                        index).equals(compData));
0453:
0454:                index = new Object[] { "value1", new Integer(3) };
0455:                assertTrue("Didn't expect get on value still not present", data
0456:                        .get(index) == null);
0457:
0458:                index = new Object[] { "value1", new Integer(2) };
0459:                data.remove(index);
0460:                assertTrue("Didn't expect removed data in get",
0461:                        data.get(index) == null);
0462:            }
0463:
0464:            public void testPutObjectObject() throws Exception {
0465:                String[] itemNames = new String[] { "name1", "name2" };
0466:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0467:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0468:                        SimpleType.INTEGER };
0469:                CompositeType rowType = new CompositeType("rowTypeName",
0470:                        "rowDescription", itemNames, itemDescriptions,
0471:                        itemTypes);
0472:
0473:                String[] indexNames = new String[] { "name1", "name2" };
0474:                TabularType tabularType = new TabularType("typeName",
0475:                        "description", rowType, indexNames);
0476:
0477:                TabularDataSupport data = new TabularDataSupport(tabularType);
0478:
0479:                HashMap map = new HashMap();
0480:                map.put("name1", "value1");
0481:                map.put("name2", new Integer(2));
0482:                CompositeDataSupport compData = new CompositeDataSupport(
0483:                        rowType, map);
0484:                Object[] index = new Object[] { "value1", new Integer(2) };
0485:                data.put(index, (Object) compData);
0486:                assertTrue("The data should be present after put", data.get(
0487:                        index).equals(compData));
0488:
0489:                HashMap map2 = new HashMap();
0490:                map2.put("name1", "value1");
0491:                map2.put("name2", new Integer(3));
0492:                CompositeDataSupport compData2 = new CompositeDataSupport(
0493:                        rowType, map2);
0494:                index = new Object[] { "value1", new Integer(3) };
0495:                data.put(index, (Object) compData2);
0496:                assertTrue("Another data should be present after put", data
0497:                        .get(index).equals(compData2));
0498:
0499:                index = new Object[] { "value1", new Integer(2) };
0500:                assertTrue("The previous data should be present after put",
0501:                        data.get(index).equals(compData));
0502:
0503:                data.remove(index);
0504:                data.put(index, compData);
0505:                assertTrue("Data should be present after remove/put", data.get(
0506:                        index).equals(compData));
0507:
0508:                HashMap map3 = new HashMap();
0509:                map3.put("name1", "value1");
0510:                map3.put("name2", new Integer(4));
0511:                CompositeDataSupport compData3 = new CompositeDataSupport(
0512:                        rowType, map3);
0513:                index = new Object[] { "value1", new Integer(4) };
0514:                data.put(new Object(), compData3);
0515:                assertTrue("The key should be ignored in put", data.get(index)
0516:                        .equals(compData3));
0517:            }
0518:
0519:            public void testPutCompositeData() throws Exception {
0520:                String[] itemNames = new String[] { "name1", "name2" };
0521:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0522:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0523:                        SimpleType.INTEGER };
0524:                CompositeType rowType = new CompositeType("rowTypeName",
0525:                        "rowDescription", itemNames, itemDescriptions,
0526:                        itemTypes);
0527:
0528:                String[] indexNames = new String[] { "name1", "name2" };
0529:                TabularType tabularType = new TabularType("typeName",
0530:                        "description", rowType, indexNames);
0531:
0532:                TabularDataSupport data = new TabularDataSupport(tabularType);
0533:
0534:                HashMap map = new HashMap();
0535:                map.put("name1", "value1");
0536:                map.put("name2", new Integer(2));
0537:                CompositeDataSupport compData = new CompositeDataSupport(
0538:                        rowType, map);
0539:                Object[] index = new Object[] { "value1", new Integer(2) };
0540:                data.put(compData);
0541:                assertTrue("The data should be present after put", data.get(
0542:                        index).equals(compData));
0543:
0544:                HashMap map2 = new HashMap();
0545:                map2.put("name1", "value1");
0546:                map2.put("name2", new Integer(3));
0547:                CompositeDataSupport compData2 = new CompositeDataSupport(
0548:                        rowType, map2);
0549:                index = new Object[] { "value1", new Integer(3) };
0550:                data.put(compData2);
0551:                assertTrue("Another data should be present after put", data
0552:                        .get(index).equals(compData2));
0553:
0554:                index = new Object[] { "value1", new Integer(2) };
0555:                assertTrue("The previous data should be present after put",
0556:                        data.get(index).equals(compData));
0557:
0558:                data.remove(index);
0559:                data.put(compData);
0560:                assertTrue("Data should be present after remove/put", data.get(
0561:                        index).equals(compData));
0562:            }
0563:
0564:            public void testRemoveObject() throws Exception {
0565:                String[] itemNames = new String[] { "name1", "name2" };
0566:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0567:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0568:                        SimpleType.INTEGER };
0569:                CompositeType rowType = new CompositeType("rowTypeName",
0570:                        "rowDescription", itemNames, itemDescriptions,
0571:                        itemTypes);
0572:
0573:                String[] indexNames = new String[] { "name1", "name2" };
0574:                TabularType tabularType = new TabularType("typeName",
0575:                        "description", rowType, indexNames);
0576:
0577:                TabularDataSupport data = new TabularDataSupport(tabularType);
0578:
0579:                HashMap map = new HashMap();
0580:                map.put("name1", "value1");
0581:                map.put("name2", new Integer(2));
0582:                CompositeDataSupport compData = new CompositeDataSupport(
0583:                        rowType, map);
0584:                Object[] index = new Object[] { "value1", new Integer(2) };
0585:
0586:                assertTrue("Remove on data not present returns null", data
0587:                        .remove((Object) index) == null);
0588:
0589:                data.put(compData);
0590:                assertTrue("Remove on data present returns the data", data
0591:                        .remove((Object) index).equals(compData));
0592:            }
0593:
0594:            public void testRemoveObjectArray() throws Exception {
0595:                String[] itemNames = new String[] { "name1", "name2" };
0596:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0597:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0598:                        SimpleType.INTEGER };
0599:                CompositeType rowType = new CompositeType("rowTypeName",
0600:                        "rowDescription", itemNames, itemDescriptions,
0601:                        itemTypes);
0602:
0603:                String[] indexNames = new String[] { "name1", "name2" };
0604:                TabularType tabularType = new TabularType("typeName",
0605:                        "description", rowType, indexNames);
0606:
0607:                TabularDataSupport data = new TabularDataSupport(tabularType);
0608:
0609:                HashMap map = new HashMap();
0610:                map.put("name1", "value1");
0611:                map.put("name2", new Integer(2));
0612:                CompositeDataSupport compData = new CompositeDataSupport(
0613:                        rowType, map);
0614:                Object[] index = new Object[] { "value1", new Integer(2) };
0615:
0616:                assertTrue("Remove on data not present returns null", data
0617:                        .remove(index) == null);
0618:
0619:                data.put(compData);
0620:                assertTrue("Remove on data present returns the data", data
0621:                        .remove(index).equals(compData));
0622:            }
0623:
0624:            public void testPutAllMap() throws Exception {
0625:                String[] itemNames = new String[] { "name1", "name2" };
0626:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0627:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0628:                        SimpleType.INTEGER };
0629:                CompositeType rowType = new CompositeType("rowTypeName",
0630:                        "rowDescription", itemNames, itemDescriptions,
0631:                        itemTypes);
0632:
0633:                String[] indexNames = new String[] { "name1", "name2" };
0634:                TabularType tabularType = new TabularType("typeName",
0635:                        "description", rowType, indexNames);
0636:
0637:                TabularDataSupport data = new TabularDataSupport(tabularType);
0638:
0639:                data.putAll((Map) null);
0640:                assertTrue("Put all null is ok", data.isEmpty());
0641:
0642:                HashMap map = new HashMap();
0643:                map.put("name1", "value1");
0644:                map.put("name2", new Integer(2));
0645:                CompositeDataSupport compData = new CompositeDataSupport(
0646:                        rowType, map);
0647:
0648:                HashMap toPut = new HashMap();
0649:                toPut.put(new Object(), compData);
0650:                data.putAll(toPut);
0651:                assertTrue("Put all added one", data.size() == 1);
0652:                assertTrue("Put all added the correct data", data
0653:                        .containsValue(compData));
0654:
0655:                HashMap map2 = new HashMap();
0656:                map2.put("name1", "value1");
0657:                map2.put("name2", new Integer(3));
0658:                CompositeDataSupport compData2 = new CompositeDataSupport(
0659:                        rowType, map2);
0660:
0661:                HashMap map3 = new HashMap();
0662:                map3.put("name1", "value1");
0663:                map3.put("name2", new Integer(4));
0664:                CompositeDataSupport compData3 = new CompositeDataSupport(
0665:                        rowType, map3);
0666:
0667:                toPut = new HashMap();
0668:                toPut.put(new Object(), compData2);
0669:                toPut.put(new Object(), compData3);
0670:                data.putAll(toPut);
0671:                assertTrue("Put all added two", data.size() == 3);
0672:                assertTrue("Put all added the correct data", data
0673:                        .containsValue(compData2));
0674:                assertTrue("Put all added the correct data", data
0675:                        .containsValue(compData3));
0676:                assertTrue("Put all original data still present", data
0677:                        .containsValue(compData));
0678:            }
0679:
0680:            public void testPutAllCompositeData() throws Exception {
0681:                String[] itemNames = new String[] { "name1", "name2" };
0682:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0683:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0684:                        SimpleType.INTEGER };
0685:                CompositeType rowType = new CompositeType("rowTypeName",
0686:                        "rowDescription", itemNames, itemDescriptions,
0687:                        itemTypes);
0688:
0689:                String[] indexNames = new String[] { "name1", "name2" };
0690:                TabularType tabularType = new TabularType("typeName",
0691:                        "description", rowType, indexNames);
0692:
0693:                TabularDataSupport data = new TabularDataSupport(tabularType);
0694:
0695:                data.putAll((CompositeData[]) null);
0696:                assertTrue("Put all null is ok", data.isEmpty());
0697:
0698:                HashMap map = new HashMap();
0699:                map.put("name1", "value1");
0700:                map.put("name2", new Integer(2));
0701:                CompositeDataSupport compData = new CompositeDataSupport(
0702:                        rowType, map);
0703:
0704:                CompositeData[] toPut = new CompositeData[] { compData };
0705:                data.putAll(toPut);
0706:                assertTrue("Put all added one", data.size() == 1);
0707:                assertTrue("Put all added the correct data", data
0708:                        .containsValue(compData));
0709:
0710:                HashMap map2 = new HashMap();
0711:                map2.put("name1", "value1");
0712:                map2.put("name2", new Integer(3));
0713:                CompositeDataSupport compData2 = new CompositeDataSupport(
0714:                        rowType, map2);
0715:
0716:                HashMap map3 = new HashMap();
0717:                map3.put("name1", "value1");
0718:                map3.put("name2", new Integer(4));
0719:                CompositeDataSupport compData3 = new CompositeDataSupport(
0720:                        rowType, map3);
0721:
0722:                toPut = new CompositeData[] { compData2, compData3 };
0723:                data.putAll(toPut);
0724:                assertTrue("Put all added two", data.size() == 3);
0725:                assertTrue("Put all added the correct data", data
0726:                        .containsValue(compData2));
0727:                assertTrue("Put all added the correct data", data
0728:                        .containsValue(compData3));
0729:                assertTrue("Put all original data still present", data
0730:                        .containsValue(compData));
0731:            }
0732:
0733:            public void testClear() throws Exception {
0734:                String[] itemNames = new String[] { "name1", "name2" };
0735:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0736:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0737:                        SimpleType.INTEGER };
0738:                CompositeType rowType = new CompositeType("rowTypeName",
0739:                        "rowDescription", itemNames, itemDescriptions,
0740:                        itemTypes);
0741:
0742:                String[] indexNames = new String[] { "name1", "name2" };
0743:                TabularType tabularType = new TabularType("typeName",
0744:                        "description", rowType, indexNames);
0745:
0746:                TabularDataSupport data = new TabularDataSupport(tabularType);
0747:
0748:                data.putAll((CompositeData[]) null);
0749:                assertTrue("Put all null is ok", data.isEmpty());
0750:
0751:                HashMap map = new HashMap();
0752:                map.put("name1", "value1");
0753:                map.put("name2", new Integer(2));
0754:                CompositeDataSupport compData = new CompositeDataSupport(
0755:                        rowType, map);
0756:
0757:                HashMap map2 = new HashMap();
0758:                map2.put("name1", "value1");
0759:                map2.put("name2", new Integer(3));
0760:                CompositeDataSupport compData2 = new CompositeDataSupport(
0761:                        rowType, map2);
0762:
0763:                HashMap map3 = new HashMap();
0764:                map3.put("name1", "value1");
0765:                map3.put("name2", new Integer(4));
0766:                CompositeDataSupport compData3 = new CompositeDataSupport(
0767:                        rowType, map3);
0768:
0769:                HashMap toPut = new HashMap();
0770:                toPut.put(new Object(), compData);
0771:                toPut.put(new Object(), compData2);
0772:                toPut.put(new Object(), compData3);
0773:                data.putAll(toPut);
0774:
0775:                data.clear();
0776:                assertTrue("Clear should clear the data", data.isEmpty());
0777:            }
0778:
0779:            public void testSize() throws Exception {
0780:                String[] itemNames = new String[] { "name1", "name2" };
0781:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0782:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0783:                        SimpleType.INTEGER };
0784:                CompositeType rowType = new CompositeType("rowTypeName",
0785:                        "rowDescription", itemNames, itemDescriptions,
0786:                        itemTypes);
0787:
0788:                String[] indexNames = new String[] { "name1", "name2" };
0789:                TabularType tabularType = new TabularType("typeName",
0790:                        "description", rowType, indexNames);
0791:
0792:                TabularDataSupport data = new TabularDataSupport(tabularType);
0793:
0794:                assertTrue("Initial size is zero", data.size() == 0);
0795:
0796:                HashMap map = new HashMap();
0797:                map.put("name1", "value1");
0798:                map.put("name2", new Integer(2));
0799:                CompositeDataSupport compData = new CompositeDataSupport(
0800:                        rowType, map);
0801:
0802:                CompositeData[] toPut = new CompositeData[] { compData };
0803:                data.putAll(toPut);
0804:                assertTrue("Expected one element", data.size() == 1);
0805:
0806:                HashMap map2 = new HashMap();
0807:                map2.put("name1", "value1");
0808:                map2.put("name2", new Integer(3));
0809:                CompositeDataSupport compData2 = new CompositeDataSupport(
0810:                        rowType, map2);
0811:
0812:                HashMap map3 = new HashMap();
0813:                map3.put("name1", "value1");
0814:                map3.put("name2", new Integer(4));
0815:                CompositeDataSupport compData3 = new CompositeDataSupport(
0816:                        rowType, map3);
0817:
0818:                toPut = new CompositeData[] { compData2, compData3 };
0819:                data.putAll(toPut);
0820:                assertTrue("Expected three elements", data.size() == 3);
0821:
0822:                data.remove(new Object[] { "value1", new Integer(4) });
0823:                assertTrue("Expected two elements", data.size() == 2);
0824:
0825:                data.clear();
0826:                assertTrue("Expected no elements", data.size() == 0);
0827:            }
0828:
0829:            public void testIsEmpty() throws Exception {
0830:                String[] itemNames = new String[] { "name1", "name2" };
0831:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0832:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0833:                        SimpleType.INTEGER };
0834:                CompositeType rowType = new CompositeType("rowTypeName",
0835:                        "rowDescription", itemNames, itemDescriptions,
0836:                        itemTypes);
0837:
0838:                String[] indexNames = new String[] { "name1", "name2" };
0839:                TabularType tabularType = new TabularType("typeName",
0840:                        "description", rowType, indexNames);
0841:
0842:                TabularDataSupport data = new TabularDataSupport(tabularType);
0843:
0844:                assertTrue("Initially empty", data.isEmpty());
0845:
0846:                HashMap map = new HashMap();
0847:                map.put("name1", "value1");
0848:                map.put("name2", new Integer(2));
0849:                CompositeDataSupport compData = new CompositeDataSupport(
0850:                        rowType, map);
0851:
0852:                CompositeData[] toPut = new CompositeData[] { compData };
0853:                data.putAll(toPut);
0854:                assertTrue("Not empty after a put", data.isEmpty() == false);
0855:
0856:                data.clear();
0857:                assertTrue("Expected no elements", data.isEmpty());
0858:            }
0859:
0860:            /**
0861:             * @todo full test, unmodifiable/iterator
0862:             */
0863:            public void testKeySet() throws Exception {
0864:                String[] itemNames = new String[] { "name1", "name2" };
0865:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0866:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0867:                        SimpleType.INTEGER };
0868:                CompositeType rowType = new CompositeType("rowTypeName",
0869:                        "rowDescription", itemNames, itemDescriptions,
0870:                        itemTypes);
0871:
0872:                String[] indexNames = new String[] { "name1", "name2" };
0873:                TabularType tabularType = new TabularType("typeName",
0874:                        "description", rowType, indexNames);
0875:
0876:                TabularDataSupport data = new TabularDataSupport(tabularType);
0877:
0878:                data.putAll((CompositeData[]) null);
0879:                assertTrue("Put all null is ok", data.isEmpty());
0880:
0881:                HashMap map = new HashMap();
0882:                map.put("name1", "value1");
0883:                map.put("name2", new Integer(2));
0884:                CompositeDataSupport compData = new CompositeDataSupport(
0885:                        rowType, map);
0886:
0887:                HashMap map2 = new HashMap();
0888:                map2.put("name1", "value1");
0889:                map2.put("name2", new Integer(3));
0890:                CompositeDataSupport compData2 = new CompositeDataSupport(
0891:                        rowType, map2);
0892:
0893:                HashMap map3 = new HashMap();
0894:                map3.put("name1", "value1");
0895:                map3.put("name2", new Integer(4));
0896:                CompositeDataSupport compData3 = new CompositeDataSupport(
0897:                        rowType, map3);
0898:
0899:                HashMap toPut = new HashMap();
0900:                toPut.put(new Object(), compData);
0901:                toPut.put(new Object(), compData2);
0902:                toPut.put(new Object(), compData3);
0903:                data.putAll(toPut);
0904:
0905:                Set keySet = data.keySet();
0906:                assertTrue("Key set should contain 3 elements",
0907:                        keySet.size() == 3);
0908:                assertTrue("Key set should contain index [value1, 2]", keySet
0909:                        .contains(Arrays.asList(new Object[] { "value1",
0910:                                new Integer(2) })));
0911:                assertTrue("Key set should contain index [value1, 3]", keySet
0912:                        .contains(Arrays.asList(new Object[] { "value1",
0913:                                new Integer(3) })));
0914:                assertTrue("Key set should contain index [value1, 4]", keySet
0915:                        .contains(Arrays.asList(new Object[] { "value1",
0916:                                new Integer(4) })));
0917:            }
0918:
0919:            /**
0920:             * @todo full test, modifiable/iterator
0921:             */
0922:            public void testValues() throws Exception {
0923:                String[] itemNames = new String[] { "name1", "name2" };
0924:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0925:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0926:                        SimpleType.INTEGER };
0927:                CompositeType rowType = new CompositeType("rowTypeName",
0928:                        "rowDescription", itemNames, itemDescriptions,
0929:                        itemTypes);
0930:
0931:                String[] indexNames = new String[] { "name1", "name2" };
0932:                TabularType tabularType = new TabularType("typeName",
0933:                        "description", rowType, indexNames);
0934:
0935:                TabularDataSupport data = new TabularDataSupport(tabularType);
0936:
0937:                data.putAll((CompositeData[]) null);
0938:                assertTrue("Put all null is ok", data.isEmpty());
0939:
0940:                HashMap map = new HashMap();
0941:                map.put("name1", "value1");
0942:                map.put("name2", new Integer(2));
0943:                CompositeDataSupport compData = new CompositeDataSupport(
0944:                        rowType, map);
0945:
0946:                HashMap map2 = new HashMap();
0947:                map2.put("name1", "value1");
0948:                map2.put("name2", new Integer(3));
0949:                CompositeDataSupport compData2 = new CompositeDataSupport(
0950:                        rowType, map2);
0951:
0952:                HashMap map3 = new HashMap();
0953:                map3.put("name1", "value1");
0954:                map3.put("name2", new Integer(4));
0955:                CompositeDataSupport compData3 = new CompositeDataSupport(
0956:                        rowType, map3);
0957:
0958:                HashMap toPut = new HashMap();
0959:                toPut.put(new Object(), compData);
0960:                toPut.put(new Object(), compData2);
0961:                toPut.put(new Object(), compData3);
0962:                data.putAll(toPut);
0963:
0964:                Collection values = data.values();
0965:                assertTrue("Values should contain 3 elements",
0966:                        values.size() == 3);
0967:                assertTrue("Values should contain index compData", values
0968:                        .contains(compData));
0969:                assertTrue("Values should contain index compData2", values
0970:                        .contains(compData2));
0971:                assertTrue("Values should contain index compData3", values
0972:                        .contains(compData3));
0973:            }
0974:
0975:            /**
0976:             * @todo this test
0977:             */
0978:            public void testEntrySet() throws Exception {
0979:            }
0980:
0981:            public void testClone() throws Exception {
0982:                String[] itemNames = new String[] { "name1", "name2" };
0983:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
0984:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0985:                        SimpleType.INTEGER };
0986:                CompositeType rowType = new CompositeType("rowTypeName",
0987:                        "rowDescription", itemNames, itemDescriptions,
0988:                        itemTypes);
0989:
0990:                String[] indexNames = new String[] { "name1", "name2" };
0991:                TabularType tabularType = new TabularType("typeName",
0992:                        "description", rowType, indexNames);
0993:
0994:                TabularDataSupport data = new TabularDataSupport(tabularType);
0995:
0996:                data.putAll((CompositeData[]) null);
0997:                assertTrue("Put all null is ok", data.isEmpty());
0998:
0999:                HashMap map = new HashMap();
1000:                map.put("name1", "value1");
1001:                map.put("name2", new Integer(2));
1002:                CompositeDataSupport compData = new CompositeDataSupport(
1003:                        rowType, map);
1004:
1005:                HashMap map2 = new HashMap();
1006:                map2.put("name1", "value1");
1007:                map2.put("name2", new Integer(3));
1008:                CompositeDataSupport compData2 = new CompositeDataSupport(
1009:                        rowType, map2);
1010:
1011:                HashMap map3 = new HashMap();
1012:                map3.put("name1", "value1");
1013:                map3.put("name2", new Integer(4));
1014:                CompositeDataSupport compData3 = new CompositeDataSupport(
1015:                        rowType, map3);
1016:
1017:                HashMap toPut = new HashMap();
1018:                toPut.put(new Object(), compData);
1019:                toPut.put(new Object(), compData2);
1020:                toPut.put(new Object(), compData3);
1021:                data.putAll(toPut);
1022:
1023:                TabularDataSupport clone = (TabularDataSupport) data.clone();
1024:                assertTrue("Clone should have the same tabular type", data
1025:                        .getTabularType().equals(clone.getTabularType()));
1026:                assertTrue("Clone should have the same number of elements",
1027:                        data.size() == clone.size());
1028:                CompositeData compDataClone = clone.get(new Object[] {
1029:                        "value1", new Integer(2) });
1030:                assertTrue("Should be a shallow clone",
1031:                        compData == compDataClone);
1032:            }
1033:
1034:            public void testEquals() throws Exception {
1035:                String[] itemNames = new String[] { "name1", "name2" };
1036:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
1037:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
1038:                        SimpleType.INTEGER };
1039:                CompositeType rowType = new CompositeType("rowTypeName",
1040:                        "rowDescription", itemNames, itemDescriptions,
1041:                        itemTypes);
1042:
1043:                String[] indexNames = new String[] { "name1", "name2" };
1044:                TabularType tabularType = new TabularType("typeName",
1045:                        "description", rowType, indexNames);
1046:
1047:                TabularDataSupport data = new TabularDataSupport(tabularType);
1048:
1049:                assertTrue("Null should not be equal",
1050:                        data.equals(null) == false);
1051:                assertTrue("Only TabularData should be equal", data
1052:                        .equals(new Object()) == false);
1053:
1054:                assertTrue("An instance should equal itself", data.equals(data));
1055:
1056:                TabularDataSupport data2 = new TabularDataSupport(tabularType);
1057:
1058:                assertTrue(
1059:                        "Two different instances with the same tabular type are equal",
1060:                        data.equals(data2));
1061:                assertTrue(
1062:                        "Two different instances with the same tabular type are equal",
1063:                        data2.equals(data));
1064:
1065:                TabularType tabularType2 = new TabularType("typeName2",
1066:                        "description", rowType, indexNames);
1067:                data2 = new TabularDataSupport(tabularType2);
1068:
1069:                assertTrue(
1070:                        "Instances with different tabular type are not equal",
1071:                        data.equals(data2) == false);
1072:                assertTrue(
1073:                        "Instances with different tabular type are not equal",
1074:                        data2.equals(data) == false);
1075:
1076:                HashMap map = new HashMap();
1077:                map.put("name1", "value1");
1078:                map.put("name2", new Integer(2));
1079:                CompositeDataSupport compData = new CompositeDataSupport(
1080:                        rowType, map);
1081:
1082:                HashMap map2 = new HashMap();
1083:                map2.put("name1", "value1");
1084:                map2.put("name2", new Integer(3));
1085:                CompositeDataSupport compData2 = new CompositeDataSupport(
1086:                        rowType, map2);
1087:
1088:                HashMap map3 = new HashMap();
1089:                map3.put("name1", "value1");
1090:                map3.put("name2", new Integer(4));
1091:                CompositeDataSupport compData3 = new CompositeDataSupport(
1092:                        rowType, map3);
1093:
1094:                HashMap toPut = new HashMap();
1095:                toPut.put(new Object(), compData);
1096:                toPut.put(new Object(), compData2);
1097:                toPut.put(new Object(), compData3);
1098:
1099:                data.putAll(toPut);
1100:                data2 = new TabularDataSupport(tabularType);
1101:                data2.putAll(toPut);
1102:                assertTrue("Instances with the same composite data are equal",
1103:                        data.equals(data2));
1104:                assertTrue("Instances with the same composite data are equal",
1105:                        data2.equals(data));
1106:
1107:                toPut = new HashMap();
1108:                toPut.put(new Object(), compData);
1109:                toPut.put(new Object(), compData2);
1110:                data2 = new TabularDataSupport(tabularType);
1111:                data2.putAll(toPut);
1112:                assertTrue(
1113:                        "Instances with different composite data are not equal",
1114:                        data.equals(data2) == false);
1115:                assertTrue(
1116:                        "Instances with different composite data are not equal",
1117:                        data2.equals(data) == false);
1118:            }
1119:
1120:            public void testHashCode() throws Exception {
1121:                String[] itemNames = new String[] { "name1", "name2" };
1122:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
1123:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
1124:                        SimpleType.INTEGER };
1125:                CompositeType rowType = new CompositeType("rowTypeName",
1126:                        "rowDescription", itemNames, itemDescriptions,
1127:                        itemTypes);
1128:
1129:                String[] indexNames = new String[] { "name1", "name2" };
1130:                TabularType tabularType = new TabularType("typeName",
1131:                        "description", rowType, indexNames);
1132:
1133:                TabularDataSupport data = new TabularDataSupport(tabularType);
1134:
1135:                data.putAll((CompositeData[]) null);
1136:                assertTrue("Put all null is ok", data.isEmpty());
1137:
1138:                HashMap map = new HashMap();
1139:                map.put("name1", "value1");
1140:                map.put("name2", new Integer(2));
1141:                CompositeDataSupport compData = new CompositeDataSupport(
1142:                        rowType, map);
1143:
1144:                HashMap map2 = new HashMap();
1145:                map2.put("name1", "value1");
1146:                map2.put("name2", new Integer(3));
1147:                CompositeDataSupport compData2 = new CompositeDataSupport(
1148:                        rowType, map2);
1149:
1150:                HashMap map3 = new HashMap();
1151:                map3.put("name1", "value1");
1152:                map3.put("name2", new Integer(4));
1153:                CompositeDataSupport compData3 = new CompositeDataSupport(
1154:                        rowType, map3);
1155:
1156:                HashMap toPut = new HashMap();
1157:                toPut.put(new Object(), compData);
1158:                toPut.put(new Object(), compData2);
1159:                toPut.put(new Object(), compData3);
1160:                data.putAll(toPut);
1161:
1162:                int myHashCode = tabularType.hashCode() + compData.hashCode()
1163:                        + compData2.hashCode() + compData3.hashCode();
1164:                assertTrue("Wrong hash code generated", myHashCode == data
1165:                        .hashCode());
1166:            }
1167:
1168:            public void testToString() throws Exception {
1169:                String[] itemNames = new String[] { "name1", "name2" };
1170:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
1171:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
1172:                        SimpleType.INTEGER };
1173:                CompositeType rowType = new CompositeType("rowTypeName",
1174:                        "rowDescription", itemNames, itemDescriptions,
1175:                        itemTypes);
1176:
1177:                String[] indexNames = new String[] { "name1", "name2" };
1178:                TabularType tabularType = new TabularType("typeName",
1179:                        "description", rowType, indexNames);
1180:
1181:                TabularDataSupport data = new TabularDataSupport(tabularType);
1182:
1183:                data.putAll((CompositeData[]) null);
1184:                assertTrue("Put all null is ok", data.isEmpty());
1185:
1186:                HashMap map = new HashMap();
1187:                map.put("name1", "value1");
1188:                map.put("name2", new Integer(2));
1189:                CompositeDataSupport compData = new CompositeDataSupport(
1190:                        rowType, map);
1191:
1192:                HashMap map2 = new HashMap();
1193:                map2.put("name1", "value1");
1194:                map2.put("name2", new Integer(3));
1195:                CompositeDataSupport compData2 = new CompositeDataSupport(
1196:                        rowType, map2);
1197:
1198:                HashMap map3 = new HashMap();
1199:                map3.put("name1", "value1");
1200:                map3.put("name2", new Integer(4));
1201:                CompositeDataSupport compData3 = new CompositeDataSupport(
1202:                        rowType, map3);
1203:
1204:                HashMap toPut = new HashMap();
1205:                toPut.put(new Object(), compData);
1206:                toPut.put(new Object(), compData2);
1207:                toPut.put(new Object(), compData3);
1208:                data.putAll(toPut);
1209:
1210:                String toString = data.toString();
1211:
1212:                assertTrue("toString() should contain the tabular type",
1213:                        toString.indexOf(tabularType.toString()) != -1);
1214:                assertTrue(
1215:                        "toString() should contain index=compositeData for compData",
1216:                        toString.indexOf(Arrays.asList(data
1217:                                .calculateIndex(compData))
1218:                                + "=" + compData) != -1);
1219:                assertTrue(
1220:                        "toString() should contain index=compositeData for compData2",
1221:                        toString.indexOf(Arrays.asList(data
1222:                                .calculateIndex(compData2))
1223:                                + "=" + compData2) != -1);
1224:                assertTrue(
1225:                        "toString() should contain index=compositeData for compData3",
1226:                        toString.indexOf(Arrays.asList(data
1227:                                .calculateIndex(compData3))
1228:                                + "=" + compData3) != -1);
1229:            }
1230:
1231:            public void testSerialization() throws Exception {
1232:                String[] itemNames = new String[] { "name1", "name2" };
1233:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
1234:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
1235:                        SimpleType.INTEGER };
1236:                CompositeType rowType = new CompositeType("rowTypeName",
1237:                        "rowDescription", itemNames, itemDescriptions,
1238:                        itemTypes);
1239:
1240:                String[] indexNames = new String[] { "name1", "name2" };
1241:                TabularType tabularType = new TabularType("typeName",
1242:                        "description", rowType, indexNames);
1243:
1244:                TabularDataSupport data = new TabularDataSupport(tabularType);
1245:
1246:                data.putAll((CompositeData[]) null);
1247:                assertTrue("Put all null is ok", data.isEmpty());
1248:
1249:                HashMap map = new HashMap();
1250:                map.put("name1", "value1");
1251:                map.put("name2", new Integer(2));
1252:                CompositeDataSupport compData = new CompositeDataSupport(
1253:                        rowType, map);
1254:
1255:                HashMap map2 = new HashMap();
1256:                map2.put("name1", "value1");
1257:                map2.put("name2", new Integer(3));
1258:                CompositeDataSupport compData2 = new CompositeDataSupport(
1259:                        rowType, map2);
1260:
1261:                HashMap map3 = new HashMap();
1262:                map3.put("name1", "value1");
1263:                map3.put("name2", new Integer(4));
1264:                CompositeDataSupport compData3 = new CompositeDataSupport(
1265:                        rowType, map3);
1266:
1267:                HashMap toPut = new HashMap();
1268:                toPut.put(new Object(), compData);
1269:                toPut.put(new Object(), compData2);
1270:                toPut.put(new Object(), compData3);
1271:                data.putAll(toPut);
1272:
1273:                // Serialize it
1274:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
1275:                ObjectOutputStream oos = new ObjectOutputStream(baos);
1276:                oos.writeObject(data);
1277:
1278:                // Deserialize it
1279:                ByteArrayInputStream bais = new ByteArrayInputStream(baos
1280:                        .toByteArray());
1281:                ObjectInputStream ois = new ObjectInputStream(bais);
1282:                Object result = ois.readObject();
1283:
1284:                assertEquals(data, result);
1285:            }
1286:
1287:            public void testErrors() throws Exception {
1288:                String[] itemNames = new String[] { "name1", "name2" };
1289:                String[] itemDescriptions = new String[] { "desc1", "desc2" };
1290:                OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
1291:                        SimpleType.INTEGER };
1292:
1293:                CompositeType rowType = new CompositeType("rowTypeName",
1294:                        "rowDescription", itemNames, itemDescriptions,
1295:                        itemTypes);
1296:                HashMap map = new HashMap();
1297:                map.put("name1", "value1");
1298:                map.put("name2", new Integer(2));
1299:                CompositeDataSupport compData = new CompositeDataSupport(
1300:                        rowType, map);
1301:
1302:                CompositeType rowType2 = new CompositeType("rowTypeName2",
1303:                        "rowDescription", itemNames, itemDescriptions,
1304:                        itemTypes);
1305:                CompositeDataSupport compData2 = new CompositeDataSupport(
1306:                        rowType2, map);
1307:
1308:                String[] indexNames = new String[] { "name1", "name2" };
1309:                TabularType tabularType = new TabularType("typeName",
1310:                        "description", rowType, indexNames);
1311:
1312:                boolean caught = false;
1313:                try {
1314:                    new TabularDataSupport(null);
1315:                } catch (IllegalArgumentException e) {
1316:                    caught = true;
1317:                }
1318:                if (caught == false)
1319:                    fail("Expected IllegalArgumentException for null tabular type");
1320:
1321:                caught = false;
1322:                try {
1323:                    new TabularDataSupport(null, 10, .5f);
1324:                } catch (IllegalArgumentException e) {
1325:                    caught = true;
1326:                }
1327:                if (caught == false)
1328:                    fail("Expected IllegalArgumentException for null tabular type");
1329:
1330:                caught = false;
1331:                try {
1332:                    new TabularDataSupport(tabularType, -1, .5f);
1333:                } catch (IllegalArgumentException e) {
1334:                    caught = true;
1335:                }
1336:                if (caught == false)
1337:                    fail("Expected IllegalArgumentException for negative initial capacity");
1338:
1339:                caught = false;
1340:                try {
1341:                    new TabularDataSupport(tabularType, 10, 0f);
1342:                } catch (IllegalArgumentException e) {
1343:                    caught = true;
1344:                }
1345:                if (caught == false)
1346:                    fail("Expected IllegalArgumentException for zero load factor");
1347:
1348:                caught = false;
1349:                try {
1350:                    new TabularDataSupport(tabularType, 10, -0.5f);
1351:                } catch (IllegalArgumentException e) {
1352:                    caught = true;
1353:                }
1354:                if (caught == false)
1355:                    fail("Expected IllegalArgumentException for negative load factor");
1356:
1357:                caught = false;
1358:                try {
1359:                    TabularDataSupport data = new TabularDataSupport(
1360:                            tabularType);
1361:                    data.calculateIndex(null);
1362:                } catch (NullPointerException e) {
1363:                    caught = true;
1364:                }
1365:                if (caught == false)
1366:                    fail("Expected NullPointerException for calculate index on null object");
1367:
1368:                caught = false;
1369:                try {
1370:                    TabularDataSupport data = new TabularDataSupport(
1371:                            tabularType);
1372:                    data.calculateIndex(compData2);
1373:                } catch (InvalidOpenTypeException e) {
1374:                    caught = true;
1375:                }
1376:                if (caught == false)
1377:                    fail("Expected InvalidOpenTypeException for calculate index on wrong composite type");
1378:
1379:                caught = false;
1380:                try {
1381:                    TabularDataSupport data = new TabularDataSupport(
1382:                            tabularType);
1383:                    data.get((Object) null);
1384:                } catch (NullPointerException e) {
1385:                    caught = true;
1386:                }
1387:                if (caught == false)
1388:                    fail("Expected NullPointerException for get((Object) null)");
1389:
1390:                caught = false;
1391:                try {
1392:                    TabularDataSupport data = new TabularDataSupport(
1393:                            tabularType);
1394:                    data.get(new Object());
1395:                } catch (ClassCastException e) {
1396:                    caught = true;
1397:                }
1398:                if (caught == false)
1399:                    fail("Expected ClassCastException for get(new Object())");
1400:
1401:                caught = false;
1402:                try {
1403:                    TabularDataSupport data = new TabularDataSupport(
1404:                            tabularType);
1405:                    data.get((Object) new Object[] { "wrong" });
1406:                } catch (InvalidKeyException e) {
1407:                    caught = true;
1408:                }
1409:                if (caught == false)
1410:                    fail("Expected InvalidKeyException for get(Object) wrong");
1411:
1412:                caught = false;
1413:                try {
1414:                    TabularDataSupport data = new TabularDataSupport(
1415:                            tabularType);
1416:                    data.get((Object[]) null);
1417:                } catch (NullPointerException e) {
1418:                    caught = true;
1419:                }
1420:                if (caught == false)
1421:                    fail("Expected NullPointerException for get((Object[]) null)");
1422:
1423:                caught = false;
1424:                try {
1425:                    TabularDataSupport data = new TabularDataSupport(
1426:                            tabularType);
1427:                    data.get(new Object[] { "wrong" });
1428:                } catch (InvalidKeyException e) {
1429:                    caught = true;
1430:                }
1431:                if (caught == false)
1432:                    fail("Expected InvalidKeyException for get(Object[]) wrong");
1433:
1434:                caught = false;
1435:                try {
1436:                    TabularDataSupport data = new TabularDataSupport(
1437:                            tabularType);
1438:                    data.put(new Object(), null);
1439:                } catch (NullPointerException e) {
1440:                    caught = true;
1441:                }
1442:                if (caught == false)
1443:                    fail("Expected NullPointerException for put(Object, Object) with null value");
1444:
1445:                caught = false;
1446:                try {
1447:                    TabularDataSupport data = new TabularDataSupport(
1448:                            tabularType);
1449:                    data.put(new Object(), new Object());
1450:                } catch (ClassCastException e) {
1451:                    caught = true;
1452:                }
1453:                if (caught == false)
1454:                    fail("Expected ClassCastException for put(Object, Object) with none CompositeData");
1455:
1456:                caught = false;
1457:                try {
1458:                    TabularDataSupport data = new TabularDataSupport(
1459:                            tabularType);
1460:                    data.put(new Object(), compData2);
1461:                } catch (InvalidOpenTypeException e) {
1462:                    caught = true;
1463:                }
1464:                if (caught == false)
1465:                    fail("Expected InvalidOpenTypeException for put(Object, Object) with wrong CompositeType");
1466:
1467:                caught = false;
1468:                try {
1469:                    TabularDataSupport data = new TabularDataSupport(
1470:                            tabularType);
1471:                    data.put(new Object(), compData);
1472:                    data.put(new Object(), compData);
1473:                } catch (KeyAlreadyExistsException e) {
1474:                    caught = true;
1475:                }
1476:                if (caught == false)
1477:                    fail("Expected KeyAlreadyExistsException for put(Object, Object)");
1478:
1479:                caught = false;
1480:                try {
1481:                    TabularDataSupport data = new TabularDataSupport(
1482:                            tabularType);
1483:                    data.put(null);
1484:                } catch (NullPointerException e) {
1485:                    caught = true;
1486:                }
1487:                if (caught == false)
1488:                    fail("Expected NullPointerException for put(CompositeData) with null value");
1489:
1490:                caught = false;
1491:                try {
1492:                    TabularDataSupport data = new TabularDataSupport(
1493:                            tabularType);
1494:                    data.put(compData2);
1495:                } catch (InvalidOpenTypeException e) {
1496:                    caught = true;
1497:                }
1498:                if (caught == false)
1499:                    fail("Expected InvalidOpenTypeException for put(CompositeData) with wrong CompositeType");
1500:
1501:                caught = false;
1502:                try {
1503:                    TabularDataSupport data = new TabularDataSupport(
1504:                            tabularType);
1505:                    data.put(compData);
1506:                    data.put(compData);
1507:                } catch (KeyAlreadyExistsException e) {
1508:                    caught = true;
1509:                }
1510:                if (caught == false)
1511:                    fail("Expected KeyAlreadyExistsException for put(CompositeData)");
1512:
1513:                caught = false;
1514:                try {
1515:                    TabularDataSupport data = new TabularDataSupport(
1516:                            tabularType);
1517:                    data.remove((Object) null);
1518:                } catch (NullPointerException e) {
1519:                    caught = true;
1520:                }
1521:                if (caught == false)
1522:                    fail("Expected NullPointerException for remove((Object) null)");
1523:
1524:                caught = false;
1525:                try {
1526:                    TabularDataSupport data = new TabularDataSupport(
1527:                            tabularType);
1528:                    data.remove(new Object());
1529:                } catch (ClassCastException e) {
1530:                    caught = true;
1531:                }
1532:                if (caught == false)
1533:                    fail("Expected ClassCastException for remove(new Object())");
1534:
1535:                caught = false;
1536:                try {
1537:                    TabularDataSupport data = new TabularDataSupport(
1538:                            tabularType);
1539:                    data.remove((Object) new Object[] { "wrong" });
1540:                } catch (InvalidKeyException e) {
1541:                    caught = true;
1542:                }
1543:                if (caught == false)
1544:                    fail("Expected InvalidKeyException for remove(Object) wrong");
1545:
1546:                caught = false;
1547:                try {
1548:                    TabularDataSupport data = new TabularDataSupport(
1549:                            tabularType);
1550:                    data.remove((Object[]) null);
1551:                } catch (NullPointerException e) {
1552:                    caught = true;
1553:                }
1554:                if (caught == false)
1555:                    fail("Expected NullPointerException for remove((Object[]) null)");
1556:
1557:                caught = false;
1558:                try {
1559:                    TabularDataSupport data = new TabularDataSupport(
1560:                            tabularType);
1561:                    data.remove(new Object[] { "wrong" });
1562:                } catch (InvalidKeyException e) {
1563:                    caught = true;
1564:                }
1565:                if (caught == false)
1566:                    fail("Expected InvalidKeyException for remove(Object[]) wrong");
1567:
1568:                caught = false;
1569:                try {
1570:                    TabularDataSupport data = new TabularDataSupport(
1571:                            tabularType);
1572:                    HashMap toPut = new HashMap();
1573:                    toPut.put(new Object(), compData);
1574:                    toPut.put(new Object(), null);
1575:                    data.putAll(toPut);
1576:                } catch (NullPointerException e) {
1577:                    caught = true;
1578:                }
1579:                if (caught == false)
1580:                    fail("Expected NullPointerException for putAll(Map) null");
1581:
1582:                {
1583:                    TabularDataSupport data = new TabularDataSupport(
1584:                            tabularType);
1585:                    HashMap toPut = new HashMap();
1586:                    toPut.put(new Object(), compData);
1587:                    toPut.put(new Object(), null);
1588:                    try {
1589:                        data.putAll(toPut);
1590:                    } catch (NullPointerException expected) {
1591:                    }
1592:                    assertTrue(
1593:                            "Nothing should be added for NullPointerException putAll(Map)",
1594:                            data.isEmpty());
1595:                }
1596:
1597:                caught = false;
1598:                try {
1599:                    TabularDataSupport data = new TabularDataSupport(
1600:                            tabularType);
1601:                    HashMap toPut = new HashMap();
1602:                    toPut.put(new Object(), compData);
1603:                    toPut.put(new Object(), new Object());
1604:                    data.putAll(toPut);
1605:                } catch (ClassCastException e) {
1606:                    caught = true;
1607:                }
1608:                if (caught == false)
1609:                    fail("Expected ClassCastException for putAll(Map) non composite data");
1610:
1611:                {
1612:                    TabularDataSupport data = new TabularDataSupport(
1613:                            tabularType);
1614:                    HashMap toPut = new HashMap();
1615:                    toPut.put(new Object(), compData);
1616:                    toPut.put(new Object(), new Object());
1617:                    try {
1618:                        data.putAll(toPut);
1619:                    } catch (ClassCastException expected) {
1620:                    }
1621:                    assertTrue(
1622:                            "Nothing should be added for ClassCastException putAll(Map)",
1623:                            data.isEmpty());
1624:                }
1625:
1626:                caught = false;
1627:                try {
1628:                    TabularDataSupport data = new TabularDataSupport(
1629:                            tabularType);
1630:                    HashMap toPut = new HashMap();
1631:                    toPut.put(new Object(), compData);
1632:                    toPut.put(new Object(), compData2);
1633:                    data.putAll(toPut);
1634:                } catch (InvalidOpenTypeException e) {
1635:                    caught = true;
1636:                }
1637:                if (caught == false)
1638:                    fail("Expected InvalidOpenTypeException for putAll(Map) wrong composite type");
1639:
1640:                {
1641:                    TabularDataSupport data = new TabularDataSupport(
1642:                            tabularType);
1643:                    HashMap toPut = new HashMap();
1644:                    toPut.put(new Object(), compData);
1645:                    toPut.put(new Object(), compData2);
1646:                    try {
1647:                        data.putAll(toPut);
1648:                    } catch (InvalidOpenTypeException expected) {
1649:                    }
1650:                    assertTrue(
1651:                            "Nothing should be added for InvalidOpenTypeException putAll(Map)",
1652:                            data.isEmpty());
1653:                }
1654:
1655:                caught = false;
1656:                try {
1657:                    TabularDataSupport data = new TabularDataSupport(
1658:                            tabularType);
1659:                    HashMap toPut = new HashMap();
1660:                    toPut.put(new Object(), compData);
1661:                    toPut.put(new Object(), compData);
1662:                    data.putAll(toPut);
1663:                } catch (KeyAlreadyExistsException e) {
1664:                    caught = true;
1665:                }
1666:                if (caught == false)
1667:                    fail("Expected InvalidOpenTypeException for putAll(Map) with duplicate data");
1668:
1669:                {
1670:                    TabularDataSupport data = new TabularDataSupport(
1671:                            tabularType);
1672:                    HashMap toPut = new HashMap();
1673:                    toPut.put(new Object(), compData);
1674:                    toPut.put(new Object(), compData);
1675:                    try {
1676:                        data.putAll(toPut);
1677:                    } catch (KeyAlreadyExistsException expected) {
1678:                    }
1679:                    assertTrue(
1680:                            "Nothing should be added for KeyAlreadyExistsException duplicates putAll(Map)",
1681:                            data.isEmpty());
1682:                }
1683:
1684:                caught = false;
1685:                try {
1686:                    TabularDataSupport data = new TabularDataSupport(
1687:                            tabularType);
1688:                    HashMap toPut = new HashMap();
1689:                    toPut.put(new Object(), compData);
1690:                    data.putAll(toPut);
1691:                    toPut = new HashMap();
1692:                    toPut.put(new Object(), compData);
1693:                    data.putAll(toPut);
1694:                } catch (KeyAlreadyExistsException e) {
1695:                    caught = true;
1696:                }
1697:                if (caught == false)
1698:                    fail("Expected InvalidOpenTypeException for putAll(Map) adding a duplicate");
1699:
1700:                {
1701:                    TabularDataSupport data = new TabularDataSupport(
1702:                            tabularType);
1703:                    HashMap toPut = new HashMap();
1704:                    toPut.put(new Object(), compData);
1705:                    data.putAll(toPut);
1706:                    toPut = new HashMap();
1707:                    toPut.put(new Object(), compData);
1708:                    try {
1709:                        data.putAll(toPut);
1710:                    } catch (KeyAlreadyExistsException expected) {
1711:                    }
1712:                    assertTrue(
1713:                            "Nothing should be added for KeyAlreadyExistsException already put putAll(Map)",
1714:                            data.size() == 1);
1715:                }
1716:
1717:                caught = false;
1718:                try {
1719:                    TabularDataSupport data = new TabularDataSupport(
1720:                            tabularType);
1721:                    CompositeData[] toPut = new CompositeData[] { compData,
1722:                            null };
1723:                    data.putAll(toPut);
1724:                } catch (NullPointerException e) {
1725:                    caught = true;
1726:                }
1727:                if (caught == false)
1728:                    fail("Expected NullPointerException for putAll(CompositeData[]) null");
1729:
1730:                {
1731:                    TabularDataSupport data = new TabularDataSupport(
1732:                            tabularType);
1733:                    CompositeData[] toPut = new CompositeData[] { compData,
1734:                            null };
1735:                    try {
1736:                        data.putAll(toPut);
1737:                    } catch (NullPointerException expected) {
1738:                    }
1739:                    assertTrue(
1740:                            "Nothing should be added for NullPointerException putAll(CompositeData[])",
1741:                            data.isEmpty());
1742:                }
1743:
1744:                caught = false;
1745:                try {
1746:                    TabularDataSupport data = new TabularDataSupport(
1747:                            tabularType);
1748:                    CompositeData[] toPut = new CompositeData[] { compData,
1749:                            compData2 };
1750:                    data.putAll(toPut);
1751:                } catch (InvalidOpenTypeException e) {
1752:                    caught = true;
1753:                }
1754:                if (caught == false)
1755:                    fail("Expected InvalidOpenTypeException for putAll(CompositeData[]) wrong composite type");
1756:
1757:                {
1758:                    TabularDataSupport data = new TabularDataSupport(
1759:                            tabularType);
1760:                    CompositeData[] toPut = new CompositeData[] { compData,
1761:                            compData2 };
1762:                    try {
1763:                        data.putAll(toPut);
1764:                    } catch (InvalidOpenTypeException expected) {
1765:                    }
1766:                    assertTrue(
1767:                            "Nothing should be added for InvalidOpenTypeException putAll(CompositeData[])",
1768:                            data.isEmpty());
1769:                }
1770:
1771:                caught = false;
1772:                try {
1773:                    TabularDataSupport data = new TabularDataSupport(
1774:                            tabularType);
1775:                    CompositeData[] toPut = new CompositeData[] { compData,
1776:                            compData };
1777:                    data.putAll(toPut);
1778:                } catch (KeyAlreadyExistsException e) {
1779:                    caught = true;
1780:                }
1781:                if (caught == false)
1782:                    fail("Expected InvalidOpenTypeException for putAll(CompositeData[]) with duplicate data");
1783:
1784:                {
1785:                    TabularDataSupport data = new TabularDataSupport(
1786:                            tabularType);
1787:                    CompositeData[] toPut = new CompositeData[] { compData,
1788:                            compData };
1789:                    try {
1790:                        data.putAll(toPut);
1791:                    } catch (KeyAlreadyExistsException expected) {
1792:                    }
1793:                    assertTrue(
1794:                            "Nothing should be added for KeyAlreadyExistsException duplicates putAll(CompositeData[])",
1795:                            data.isEmpty());
1796:                }
1797:
1798:                caught = false;
1799:                try {
1800:                    TabularDataSupport data = new TabularDataSupport(
1801:                            tabularType);
1802:                    CompositeData[] toPut = new CompositeData[] { compData };
1803:                    data.putAll(toPut);
1804:                    data.putAll(toPut);
1805:                } catch (KeyAlreadyExistsException e) {
1806:                    caught = true;
1807:                }
1808:                if (caught == false)
1809:                    fail("Expected InvalidOpenTypeException for putAll(CompositeData[]) adding a duplicate");
1810:
1811:                {
1812:                    TabularDataSupport data = new TabularDataSupport(
1813:                            tabularType);
1814:                    CompositeData[] toPut = new CompositeData[] { compData };
1815:                    data.putAll(toPut);
1816:                    try {
1817:                        data.putAll(toPut);
1818:                    } catch (KeyAlreadyExistsException expected) {
1819:                    }
1820:                    assertTrue(
1821:                            "Nothing should be added for KeyAlreadyExistsException already put putAll(CompositeData[])",
1822:                            data.size() == 1);
1823:                }
1824:            }
1825:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.