1 22 package org.jboss.test.mx.mxbean.test; 23 24 import java.lang.reflect.Type ; 25 import java.util.LinkedHashMap ; 26 import java.util.Map ; 27 28 import javax.management.openmbean.CompositeDataSupport ; 29 import javax.management.openmbean.CompositeType ; 30 import javax.management.openmbean.TabularDataSupport ; 31 import javax.management.openmbean.TabularType ; 32 33 import junit.framework.Test; 34 import junit.framework.TestSuite; 35 36 import org.jboss.mx.mxbean.MXBeanUtils; 37 import org.jboss.test.mx.mxbean.support.TestParameterizedType; 38 39 45 public class CompositeDataMapUnitTestCase extends CompositeDataTest 46 { 47 private static final TestParameterizedType MAP_OF_STRINGS_TO_INTEGERS = new TestParameterizedType(Map .class, new Type [] { String .class, Integer .class }); 48 private static final TabularType TABLE_STRING_TO_INTEGER = MXBeanUtils.createMapType(String .class, Integer .class); 49 50 public static Test suite() 51 { 52 return new TestSuite(CompositeDataMapUnitTestCase.class); 53 } 54 55 public CompositeDataMapUnitTestCase(String name) 56 { 57 super(name); 58 } 59 60 public void testMap() throws Exception 61 { 62 Map <String , Integer > c = new LinkedHashMap <String , Integer >(); 63 c.put("one", 1); 64 c.put("two", 2); 65 c.put("three", 3); 66 TabularDataSupport openData = new TabularDataSupport (TABLE_STRING_TO_INTEGER); 67 CompositeType entryType = TABLE_STRING_TO_INTEGER.getRowType(); 68 openData.put(new CompositeDataSupport (entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object [] { "one", 1 })); 69 openData.put(new CompositeDataSupport (entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object [] { "two", 2 })); 70 openData.put(new CompositeDataSupport (entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object [] { "three", 3 })); 71 constructReconstructTest(c, MAP_OF_STRINGS_TO_INTEGERS, openData); 72 } 73 74 public void testMapNull() throws Exception 75 { 76 constructReconstructTest(null, MAP_OF_STRINGS_TO_INTEGERS); 77 } 78 79 public void testMapNullKey() throws Exception 80 { 81 Map <String , Integer > c = new LinkedHashMap <String , Integer >(); 82 c.put("one", 1); 83 c.put(null, 2); 84 c.put("three", 3); 85 TabularDataSupport openData = new TabularDataSupport (TABLE_STRING_TO_INTEGER); 86 CompositeType entryType = TABLE_STRING_TO_INTEGER.getRowType(); 87 openData.put(new CompositeDataSupport (entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object [] { "one", 1 })); 88 openData.put(new CompositeDataSupport (entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object [] { null, 2 })); 89 openData.put(new CompositeDataSupport (entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object [] { "three", 3 })); 90 constructReconstructTest(c, MAP_OF_STRINGS_TO_INTEGERS, openData); 91 } 92 93 public void testMapNullValue() throws Exception 94 { 95 Map <String , Integer > c = new LinkedHashMap <String , Integer >(); 96 c.put("one", 1); 97 c.put("two", null); 98 c.put("three", 3); 99 TabularDataSupport openData = new TabularDataSupport (TABLE_STRING_TO_INTEGER); 100 CompositeType entryType = TABLE_STRING_TO_INTEGER.getRowType(); 101 openData.put(new CompositeDataSupport (entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object [] { "one", 1 })); 102 openData.put(new CompositeDataSupport (entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object [] { "two", null })); 103 openData.put(new CompositeDataSupport (entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object [] { "three", 3 })); 104 constructReconstructTest(c, MAP_OF_STRINGS_TO_INTEGERS, openData); 105 } 106 } 107 | Popular Tags |