KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jbossmx > compliance > objectname > PatternTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.jbossmx.compliance.objectname;
23
24 import org.jboss.test.jbossmx.compliance.TestCase;
25
26 import javax.management.MalformedObjectNameException JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28
29 public class PatternTestCase
30    extends TestCase
31 {
32    public PatternTestCase(String JavaDoc s)
33    {
34       super(s);
35    }
36
37    public void testBasicDomainPattern()
38    {
39       String JavaDoc nameArg = "*:key1=val1,key2=val2";
40       ObjectName JavaDoc 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 JavaDoc nameArg = "**:key1=val1,key2=val2";
50       ObjectName JavaDoc 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 JavaDoc nameArg = "*domain:key1=val1,key2=val2";
60       ObjectName JavaDoc 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 JavaDoc nameArg = "d*n:key1=val1,key2=val2";
70       ObjectName JavaDoc 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 JavaDoc nameArg = "d**n:key1=val1,key2=val2";
80       ObjectName JavaDoc 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 JavaDoc nameArg = "do??in:key1=val1,key2=val2";
90       ObjectName JavaDoc 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 JavaDoc nameArg = "*:*";
100       ObjectName JavaDoc name = constructSafely(nameArg);
101       assertTrue("isPattern should be true", name.isPattern());
102       assertTrue("isPropertyPattern should be true", name.isPropertyPattern());
103       // The RI incorrectly (IMHO) removes the * from propertyPatterns
104
assertEquals("FAILS IN RI", nameArg, name.getCanonicalName());
105    }
106
107    public void testKeyPatternOnly()
108    {
109       String JavaDoc nameArg = "domain:*";
110       ObjectName JavaDoc name = constructSafely(nameArg);
111       assertTrue("isPattern should be true", name.isPattern());
112       assertTrue("isPropertyPattern should be true", name.isPropertyPattern());
113       // The RI incorrectly (IMHO) removes the * from propertyPatterns
114
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 JavaDoc nameArg = "domain:key2=val2,*,key1=val1";
121       ObjectName JavaDoc name = constructSafely(nameArg);
122       assertTrue("isPattern should be true", name.isPattern());
123       assertTrue("isPropertyPattern should be true", name.isPropertyPattern());
124       // The RI incorrectly (IMHO) removes the * from propertyPatterns
125
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 JavaDoc pat1 = constructSafely("domain:*,key=value");
132       ObjectName JavaDoc pat2 = constructSafely("domain:key=value,*");
133       assertEquals(pat1, pat2);
134    }
135
136    public void testEquality_b()
137    {
138       ObjectName JavaDoc pat1 = constructSafely("do**main:key=value,*");
139       ObjectName JavaDoc pat2 = constructSafely("do*main:key=value,*");
140       assertTrue(".equals() should return false", !pat1.equals(pat2));
141    }
142
143 /* FIXME THS - this test fails when run against the RI!
144    public void testEquality_c()
145    {
146       ObjectName conc = constructSafely("domain:key=value");
147       ObjectName pat = constructSafely("domain:key=value,*");
148       assertEquals("toString() should match", conc.toString(), pat.toString());
149       assertTrue("equals() should be false", !conc.equals(pat));
150    }
151 */

152
153    private ObjectName JavaDoc constructSafely(String JavaDoc nameArg)
154    {
155       ObjectName JavaDoc name = null;
156       try
157       {
158          name = new ObjectName JavaDoc(nameArg);
159       }
160       catch (MalformedObjectNameException JavaDoc e)
161       {
162          fail("spurious MalformedObjectNameException on ('" + nameArg + "')");
163       }
164
165       return name;
166    }
167 }
168
Popular Tags