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 29 public class PatternTestCase 30 extends TestCase 31 { 32 public PatternTestCase(String s) 33 { 34 super(s); 35 } 36 37 public void testBasicDomainPattern() 38 { 39 String nameArg = "*:key1=val1,key2=val2"; 40 ObjectName name = constructSafely(nameArg); 41 assertTrue("isPattern should be true", name.isPattern()); 42 assertEquals("toString should be: '" + nameArg + "'", nameArg, name.toString()); 43 assertTrue("isPropertyPattern should be false", !name.isPropertyPattern()); 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 assertEquals("**", name.getDomain()); 55 } 56 57 public void testPartialDomainPattern() 58 { 59 String nameArg = "*domain:key1=val1,key2=val2"; 60 ObjectName name = constructSafely(nameArg); 61 assertTrue("isPattern should be true", name.isPattern()); 62 assertEquals("toString should be: '" + nameArg + "'", nameArg, name.toString()); 63 assertTrue("isPropertyPattern should be false", !name.isPropertyPattern()); 64 assertEquals("*domain", name.getDomain()); 65 } 66 67 public void testHarderPartialDomainPattern() 68 { 69 String nameArg = "d*n:key1=val1,key2=val2"; 70 ObjectName name = constructSafely(nameArg); 71 assertTrue("isPattern should be true", name.isPattern()); 72 assertEquals("toString should be: '" + nameArg + "'", nameArg, name.toString()); 73 assertTrue("isPropertyPattern should be false", !name.isPropertyPattern()); 74 assertEquals("d*n", name.getDomain()); 75 } 76 77 public void testHarderPartialDomainPatternExtra() 78 { 79 String nameArg = "d**n:key1=val1,key2=val2"; 80 ObjectName name = constructSafely(nameArg); 81 assertTrue("isPattern should be true", name.isPattern()); 82 assertEquals("toString should be: '" + nameArg + "'", nameArg, name.toString()); 83 assertTrue("isPropertyPattern should be false", !name.isPropertyPattern()); 84 assertEquals("d**n", name.getDomain()); 85 } 86 87 public void testPositionalDomainPattern() 88 { 89 String nameArg = "do??in:key1=val1,key2=val2"; 90 ObjectName name = constructSafely(nameArg); 91 assertTrue("isPattern should be true", name.isPattern()); 92 assertEquals("toString should be: '" + nameArg + "'", nameArg, name.toString()); 93 assertTrue("isPropertyPattern should be false", !name.isPropertyPattern()); 94 assertEquals("do??in", name.getDomain()); 95 } 96 97 public void testPatternOnly() 98 { 99 String nameArg = "*:*"; 100 ObjectName name = constructSafely(nameArg); 101 assertTrue("isPattern should be true", name.isPattern()); 102 assertTrue("isPropertyPattern should be true", name.isPropertyPattern()); 103 assertEquals("FAILS IN RI", nameArg, name.getCanonicalName()); 105 } 106 107 public void testKeyPatternOnly() 108 { 109 String nameArg = "domain:*"; 110 ObjectName name = constructSafely(nameArg); 111 assertTrue("isPattern should be true", name.isPattern()); 112 assertTrue("isPropertyPattern should be true", name.isPropertyPattern()); 113 assertEquals("FAILS IN RI", nameArg, name.getCanonicalName()); 115 assertTrue("key properties hash should be zero size", 0 == name.getKeyPropertyList().size()); 116 } 117 118 public void testPartialKeyPattern() 119 { 120 String nameArg = "domain:key2=val2,*,key1=val1"; 121 ObjectName name = constructSafely(nameArg); 122 assertTrue("isPattern should be true", name.isPattern()); 123 assertTrue("isPropertyPattern should be true", name.isPropertyPattern()); 124 assertEquals("FAILS IN RI", "domain:key1=val1,key2=val2,*", name.getCanonicalName()); 126 assertTrue("key properties hash should only have 2 elements", 2 == name.getKeyPropertyList().size()); 127 } 128 129 public void testEquality_a() 130 { 131 ObjectName pat1 = constructSafely("domain:*,key=value"); 132 ObjectName pat2 = constructSafely("domain:key=value,*"); 133 assertEquals(pat1, pat2); 134 } 135 136 public void testEquality_b() 137 { 138 ObjectName pat1 = constructSafely("do**main:key=value,*"); 139 ObjectName pat2 = constructSafely("do*main:key=value,*"); 140 assertTrue(".equals() should return false", !pat1.equals(pat2)); 141 } 142 143 152 153 private ObjectName constructSafely(String nameArg) 154 { 155 ObjectName name = null; 156 try 157 { 158 name = new ObjectName (nameArg); 159 } 160 catch (MalformedObjectNameException e) 161 { 162 fail("spurious MalformedObjectNameException on ('" + nameArg + "')"); 163 } 164 165 return name; 166 } 167 } 168 | Popular Tags |