1 22 package org.jboss.test.jmx.compliance.objectname; 23 24 import javax.management.MalformedObjectNameException ; 25 import javax.management.ObjectName ; 26 27 import junit.framework.TestCase; 28 29 public class PatternTEST extends TestCase 30 { 31 public PatternTEST(String s) 32 { 33 super(s); 34 } 35 36 public void testBasicDomainPattern() 37 { 38 String nameArg = "*:key1=val1,key2=val2"; 39 ObjectName name = constructSafely(nameArg); 40 assertTrue("isPattern should be true", name.isPattern()); 41 assertEquals("toString should be: '" + nameArg + "'", nameArg, name.toString()); 42 assertTrue("isPropertyPattern should be false", !name.isPropertyPattern()); 43 assertTrue("isDomainPattern should be true", name.isDomainPattern()); 44 assertEquals("*", name.getDomain()); 45 } 46 47 public void testBasicDomainPatternExtra() 48 { 49 String nameArg = "**:key1=val1,key2=val2"; 50 ObjectName name = constructSafely(nameArg); 51 assertTrue("isPattern should be true", name.isPattern()); 52 assertEquals("toString should be: '" + nameArg + "'", nameArg, name.toString()); 53 assertTrue("isPropertyPattern should be false", !name.isPropertyPattern()); 54 assertTrue("isDomainPattern should be true", name.isDomainPattern()); 55 assertEquals("**", name.getDomain()); 56 } 57 58 public void testPartialDomainPattern() 59 { 60 String nameArg = "*domain:key1=val1,key2=val2"; 61 ObjectName name = constructSafely(nameArg); 62 assertTrue("isPattern should be true", name.isPattern()); 63 assertEquals("toString should be: '" + nameArg + "'", nameArg, name.toString()); 64 assertTrue("isPropertyPattern should be false", !name.isPropertyPattern()); 65 assertTrue("isDomainPattern should be true", name.isDomainPattern()); 66 assertEquals("*domain", name.getDomain()); 67 } 68 69 public void testHarderPartialDomainPattern() 70 { 71 String nameArg = "d*n:key1=val1,key2=val2"; 72 ObjectName name = constructSafely(nameArg); 73 assertTrue("isPattern should be true", name.isPattern()); 74 assertEquals("toString should be: '" + nameArg + "'", nameArg, name.toString()); 75 assertTrue("isPropertyPattern should be false", !name.isPropertyPattern()); 76 assertTrue("isDomainPattern should be true", name.isDomainPattern()); 77 assertEquals("d*n", name.getDomain()); 78 } 79 80 public void testHarderPartialDomainPatternExtra() 81 { 82 String nameArg = "d**n:key1=val1,key2=val2"; 83 ObjectName name = constructSafely(nameArg); 84 assertTrue("isPattern should be true", name.isPattern()); 85 assertEquals("toString should be: '" + nameArg + "'", nameArg, name.toString()); 86 assertTrue("isPropertyPattern should be false", !name.isPropertyPattern()); 87 assertTrue("isDomainPattern should be true", name.isDomainPattern()); 88 assertEquals("d**n", name.getDomain()); 89 } 90 91 public void testPositionalDomainPattern() 92 { 93 String nameArg = "do??in:key1=val1,key2=val2"; 94 ObjectName name = constructSafely(nameArg); 95 assertTrue("isPattern should be true", name.isPattern()); 96 assertEquals("toString should be: '" + nameArg + "'", nameArg, name.toString()); 97 assertTrue("isPropertyPattern should be false", !name.isPropertyPattern()); 98 assertTrue("isDomainPattern should be true", name.isDomainPattern()); 99 assertEquals("do??in", name.getDomain()); 100 } 101 102 public void testPatternOnly() 103 { 104 String nameArg = "*:*"; 105 ObjectName name = constructSafely(nameArg); 106 assertTrue("isPattern should be true", name.isPattern()); 107 assertTrue("isPropertyPattern should be true", name.isPropertyPattern()); 108 assertTrue("isDomainPattern should be true", name.isDomainPattern()); 109 assertEquals("FAILS IN RI", nameArg, name.getCanonicalName()); 111 } 112 113 public void testKeyPatternOnly() 114 { 115 String nameArg = "domain:*"; 116 ObjectName name = constructSafely(nameArg); 117 assertTrue("isPattern should be true", name.isPattern()); 118 assertTrue("isPropertyPattern should be true", name.isPropertyPattern()); 119 assertTrue("isDomainPattern should be false", !name.isDomainPattern()); 120 assertEquals("FAILS IN RI", nameArg, name.getCanonicalName()); 122 assertTrue("key properties hash should be zero size", 0 == name.getKeyPropertyList().size()); 123 } 124 125 public void testPartialKeyPattern() 126 { 127 String nameArg = "domain:key2=val2,*,key1=val1"; 128 ObjectName name = constructSafely(nameArg); 129 assertTrue("isPattern should be true", name.isPattern()); 130 assertTrue("isPropertyPattern should be true", name.isPropertyPattern()); 131 assertTrue("isDomainPattern should be false", !name.isDomainPattern()); 132 assertEquals("FAILS IN RI", "domain:key1=val1,key2=val2,*", name.getCanonicalName()); 134 assertTrue("key properties hash should only have 2 elements", 2 == name.getKeyPropertyList().size()); 135 } 136 137 public void testEquality_a() 138 { 139 ObjectName pat1 = constructSafely("domain:*,key=value"); 140 ObjectName pat2 = constructSafely("domain:key=value,*"); 141 assertEquals(pat1, pat2); 142 } 143 144 public void testEquality_b() 145 { 146 ObjectName pat1 = constructSafely("do**main:key=value,*"); 147 ObjectName pat2 = constructSafely("do*main:key=value,*"); 148 assertTrue(".equals() should return false", !pat1.equals(pat2)); 149 } 150 151 public void testEquality_c() 152 { 153 ObjectName conc = constructSafely("domain:key=value"); 154 ObjectName pat = constructSafely("domain:key=value,*"); 155 assertTrue("toString() should not match", conc.toString().equals(pat.toString()) == false); 156 assertTrue("equals() should be false", !conc.equals(pat)); 157 } 158 159 private ObjectName constructSafely(String nameArg) 160 { 161 ObjectName name = null; 162 try 163 { 164 name = new ObjectName (nameArg); 165 } 166 catch (MalformedObjectNameException e) 167 { 168 fail("spurious MalformedObjectNameException on ('" + nameArg + "')"); 169 } 170 171 return name; 172 } 173 } 174 | Popular Tags |