1 25 package org.archive.util; 26 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.Map ; 30 31 import javax.management.openmbean.CompositeData ; 32 import javax.management.openmbean.CompositeDataSupport ; 33 import javax.management.openmbean.CompositeType ; 34 import javax.management.openmbean.OpenDataException ; 35 36 import junit.framework.TestCase; 37 38 public class JmxUtilsTest extends TestCase { 39 public void testCreateCompositeType() throws OpenDataException { 40 Map <String ,Object > m = new HashMap <String ,Object >(); 41 m.put("0", new Long (0)); 42 m.put("1", new Double (1)); 43 m.put("2", "2"); 44 CompositeType ct = JmxUtils.createCompositeType(m, "ct", "description"); 45 testCompositeDataHasMapContent(ct, m); 46 Map <String ,Object > n = new HashMap <String ,Object >(); 48 n.put("0", new Long (17)); 49 n.put("2", "Some old string"); 50 n.put("1", new Double (17.45)); 51 testCompositeDataHasMapContent(ct, n); 52 } 53 54 private void testCompositeDataHasMapContent(final CompositeType ct, 55 final Map m) 56 throws OpenDataException { 57 CompositeData cd = new CompositeDataSupport (ct, m); 58 for (final Iterator i = m.keySet().iterator(); i.hasNext();) { 59 String key = (String )i.next(); 60 assertTrue(cd.containsKey(key)); 61 assertEquals(m.get(key), cd.get(key)); 62 } 63 } 64 65 } 66 | Popular Tags |