1 7 8 package test.compliance.objectname; 9 10 import junit.framework.TestCase; 11 12 import javax.management.MalformedObjectNameException; 13 import javax.management.ObjectName; 14 import java.util.Hashtable; 15 16 public class CanonicalTEST extends TestCase 17 { 18 public static final String EXPECTED_NAME = "domain:a=a,b=b,c=c,d=d,e=e"; 19 public static final String[] KVP = {"a", "b", "c", "d", "e"}; 20 21 public CanonicalTEST(String s) 22 { 23 super(s); 24 } 25 26 public void testBasicCanonical() 27 { 28 try 29 { 30 ObjectName name = new ObjectName("domain:e=e,b=b,d=d,c=c,a=a"); 31 assertEquals(EXPECTED_NAME, name.getCanonicalName()); 32 } 33 catch (MalformedObjectNameException e) 34 { 35 fail("spurious MalformedObjectNameException"); 36 } 37 } 38 39 public void testHashtableCanonical() 40 { 41 try 42 { 43 Hashtable h = new Hashtable(); 44 for (int i = 0; i < KVP.length; i++) 45 { 46 h.put(KVP[i], KVP[i]); 47 } 48 ObjectName name = new ObjectName("domain", h); 49 assertEquals(EXPECTED_NAME, name.getCanonicalName()); 50 } 51 catch (MalformedObjectNameException e) 52 { 53 fail("spurious MalformedObjectNameException"); 54 } 55 } 56 57 public void testSingleKVP() 58 { 59 try 60 { 61 ObjectName name = new ObjectName("domain", "a", "a"); 62 assertEquals("domain:a=a", name.getCanonicalName()); 63 } 64 catch (MalformedObjectNameException e) 65 { 66 fail("spurious MalformedObjectNameException"); 67 } 68 } 69 } 70 | Popular Tags |