1 22 package org.jboss.test.jbossmx.compliance.objectname; 23 24 import org.jboss.test.jbossmx.compliance.TestCase; 25 26 import javax.management.MalformedObjectNameException ; 27 import javax.management.ObjectName ; 28 import java.util.Hashtable ; 29 30 public class BasicTestCase 31 extends TestCase 32 { 33 public static final String STD_DOMAIN = "domain"; 34 public static final String WHITESPACE_DOMAIN = " "; 35 public static final String STD_KEYPROP_STRING = "key1=val1,key2=val2"; 36 public static final String REV_KEYPROP_STRING = "key2=val2,key1=val1"; 37 public static final String KEY1 = "key1"; 38 public static final String KEY2 = "key2"; 39 public static final String VAL1 = "val1"; 40 public static final String VAL2 = "val2"; 41 42 public BasicTestCase(String s) 43 { 44 super(s); 45 } 46 47 public void testStringNoDomain() 48 { 49 String nameArg = ":" + STD_KEYPROP_STRING; 50 try 51 { 52 ObjectName name = new ObjectName (nameArg); 53 String domain = name.getDomain(); 54 if (null == domain) 55 { 56 fail("getDomain() should return empty string rather than null"); 57 } 58 assertTrue("domain should have been zero size", domain.length() == 0); 59 assertEquals("value for key: " + KEY1 + " should be: " + VAL1, VAL1, name.getKeyProperty(KEY1)); 60 assertEquals("value for key: " + KEY2 + " should be: " + VAL2, VAL2, name.getKeyProperty(KEY2)); 61 } 62 catch (MalformedObjectNameException e) 63 { 64 fail("spurious MalformedObjectNameException on ('" + nameArg + "')"); 65 } 66 } 67 68 public void testStringWithDomain() 69 { 70 String nameArg = STD_DOMAIN + ":" + STD_KEYPROP_STRING; 71 try 72 { 73 ObjectName name = new ObjectName (nameArg); 74 assertEquals("domain should be equivalent", STD_DOMAIN, name.getDomain()); 75 assertEquals("value for key: " + KEY1 + " should be: " + VAL1, VAL1, name.getKeyProperty(KEY1)); 76 assertEquals("value for key: " + KEY2 + " should be: " + VAL2, VAL2, name.getKeyProperty(KEY2)); 77 } 78 catch (MalformedObjectNameException e) 79 { 80 fail("spurious MalformedObjectNameException on ('" + nameArg + "')"); 81 } 82 } 83 84 public void testSingleKVP() 85 { 86 try 87 { 88 ObjectName name = new ObjectName (STD_DOMAIN, KEY1, VAL1); 89 assertEquals("domain should be equivalent", STD_DOMAIN, name.getDomain()); 90 assertEquals("value for key: " + KEY1 + " should be: " + VAL1, VAL1, name.getKeyProperty(KEY1)); 91 assertNull("should return NULL key property for: " + KEY2, name.getKeyProperty(KEY2)); 92 93 String kplistString = name.getKeyPropertyListString(); 94 if (null == kplistString) 95 { 96 fail("key property list string was null;"); 97 } 98 assertTrue("KeyPropertyListString should match", 99 kplistString.equals("key1=val1")); 100 101 } 102 catch (MalformedObjectNameException e) 103 { 104 fail("spurious MalformedObjectNameException on ('" + STD_DOMAIN + "','" + KEY1 + "','" + VAL1 + "')"); 105 } 106 } 107 108 public void testHashtable() 109 { 110 try 111 { 112 Hashtable properties = new Hashtable (); 113 properties.put(KEY1, VAL1); 114 properties.put(KEY2, VAL2); 115 ObjectName name = new ObjectName (STD_DOMAIN, properties); 116 assertEquals("domain should be equivalent", STD_DOMAIN, name.getDomain()); 117 assertEquals("value for key: " + KEY1 + " should be: " + VAL1, VAL1, name.getKeyProperty(KEY1)); 118 assertEquals("value for key: " + KEY2 + " should be: " + VAL2, VAL2, name.getKeyProperty(KEY2)); 119 120 String kplistString = name.getKeyPropertyListString(); 121 if (null == kplistString) 122 { 123 fail("key property list string was null;"); 124 } 125 assertTrue("KeyPropertyListString should match", 126 (kplistString.equals(STD_KEYPROP_STRING) || kplistString.equals(REV_KEYPROP_STRING))); 127 } 128 catch (MalformedObjectNameException e) 129 { 130 fail("spurious MalformedObjectNameException on ('" + STD_DOMAIN + "','" + KEY1 + "','" + VAL1 + "')"); 131 } 132 } 133 134 public void testWhitespaceDomain() 135 { 136 String wsDomain = " "; 137 String nameArg = wsDomain + ":" + STD_KEYPROP_STRING; 138 try 139 { 140 ObjectName name = new ObjectName (nameArg); 141 assertEquals("domain should be equivalent", wsDomain, name.getDomain()); 142 } 143 catch (MalformedObjectNameException e) 144 { 145 fail("spurious MalformedObjectNameException on ('" + nameArg + "')"); 146 } 147 } 148 149 public void testKeyPropertyList() 150 { 151 String nameArg = ":" + STD_KEYPROP_STRING; 152 try 153 { 154 ObjectName name = new ObjectName (nameArg); 155 String kplistString = name.getKeyPropertyListString(); 156 if (null == kplistString) 157 { 158 fail("key property list string was null;"); 159 } 160 assertTrue("KeyPropertyListString should match", 161 (kplistString.equals(STD_KEYPROP_STRING) || kplistString.equals(REV_KEYPROP_STRING))); 162 163 } 164 catch (MalformedObjectNameException e) 165 { 166 fail("spurious MalformedObjectNameException on ('" + nameArg + "')"); 167 } 168 } 169 170 public void testToString() 171 { 172 String nameArg1 = ":key1=val1"; 173 String nameArg2 = "domain:key1=val1"; 174 175 try 176 { 177 ObjectName name1 = new ObjectName (nameArg1); 178 assertEquals("toString should match", nameArg1, name1.toString()); 179 } 180 catch (MalformedObjectNameException e) 181 { 182 fail("spurious MalformedObjectNameException on ('" + nameArg1 + "')"); 183 } 184 185 try 186 { 187 ObjectName name2 = new ObjectName (nameArg2); 188 assertEquals("toString should match", nameArg2, name2.toString()); 189 } 190 catch (MalformedObjectNameException e) 191 { 192 fail("spurious MalformedObjectNameException on ('" + nameArg2 + "')"); 193 } 194 } 195 } 196 | Popular Tags |