1 // Copyright (C) 2007 Red Hat, Inc. |
|
2 // Written by Gary Benson <gbenson@redhat.com> |
|
3 |
|
4 // This file is part of Mauve. |
|
5 |
|
6 // Mauve is free software; you can redistribute it and/or modify |
|
7 // it under the terms of the GNU General Public License as published by |
|
8 // the Free Software Foundation; either version 2, or (at your option) |
|
9 // any later version. |
|
10 |
|
11 // Mauve is distributed in the hope that it will be useful, |
|
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 // GNU General Public License for more details. |
|
15 |
|
16 // You should have received a copy of the GNU General Public License |
|
17 // along with Mauve; see the file COPYING. If not, write to |
|
18 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
19 // Boston, MA 02111-1307, USA. |
|
20 |
|
21 // Tags: JDK1.5 |
|
22 |
|
23 package gnu.testlet.javax.management.ObjectName; |
|
24 |
|
25 import javax.management.MalformedObjectNameException; |
|
26 import javax.management.ObjectName; |
|
27 |
|
28 import gnu.testlet.Testlet; |
|
29 import gnu.testlet.TestHarness; |
|
30 |
|
31 public class apply implements Testlet |
|
32 { |
|
33 private String[] domains = new String[] { |
|
34 "mauve", "m?uve", "*ve", "*au*", "m?*e", "mauv?", "m*v*", "*"}; |
|
35 |
|
36 private boolean domainMatches(String a, String b) |
|
37 { |
|
38 // XXX This is very hacky. The spec says that nothing matches |
|
39 // a pattern. And all the patterns here match the non-pattern. |
|
40 return !b.contains("?") && !b.contains("*"); |
|
41 } |
|
42 |
|
43 private String[] properties = new String[] { |
|
44 "foo=bar", "foo=bar,spam=eggs", "spam=eggs,foo=bar", "foo=bar,*", "*"}; |
|
45 |
|
46 private boolean propertyMatches(String a, String b) |
|
47 { |
|
48 // Again, nothing matches a pattern. |
|
49 if (b.contains("*")) |
|
50 return false; |
|
51 // All the patterns here match the non-patterns. |
|
52 if (a.contains("*")) |
|
53 return true; |
|
54 // If they're the same length then they match (XXX hacky) |
|
55 return a.length() == b.length(); |
|
56 } |
|
57 |
|
58 public void test(TestHarness harness) |
|
59 { |
|
60 for (int ida = 0; ida < domains.length; ida++) |
|
61 { |
|
62 for (int idb = 0; idb < domains.length; idb++) |
|
63 { |
|
64 for (int ipa = 0; ipa < properties.length; ipa++) |
|
65 { |
|
66 for (int ipb = 0; ipb < properties.length; ipb++) |
|
67 { |
|
68 String da = domains[ida]; |
|
69 String db = domains[idb]; |
|
70 boolean dm = domainMatches(da, db); |
|
71 |
|
72 String pa = properties[ipa]; |
|
73 String pb = properties[ipb]; |
|
74 boolean pm = propertyMatches(pa, pb); |
|
75 |
|
76 String sa = da + ":" + pa; |
|
77 String sb = db + ":" + pb; |
|
78 boolean expect = dm && pm; |
|
79 |
|
80 try |
|
81 { |
|
82 ObjectName ona = new ObjectName(sa); |
|
83 ObjectName onb = new ObjectName(sb); |
|
84 |
|
85 harness.check(ona.apply(onb) == expect, |
|
86 sa + " should" + |
|
87 (expect ? "" : " not") + |
|
88 " match " + sb); |
|
89 } |
|
90 catch (MalformedObjectNameException e) |
|
91 { |
|
92 harness.check(false); |
|
93 harness.debug(e); |
|
94 } |
|
95 } |
|
96 } |
|
97 } |
|
98 } |
|
99 } |
|
100 } |
|