author | uvangapally |
Fri, 19 May 2017 15:27:25 +0530 | |
changeset 45232 | 1e2ad0809162 |
parent 30376 | 2ccf2cf7ea48 |
child 44423 | 306c020eb154 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 4716807 |
|
27 |
* @summary Test if the repository supports correctly the use of |
|
28 |
* wildcards in the ObjectName key properties value part. |
|
29 |
* @author Luis-Miguel Alventosa |
|
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
5506
diff
changeset
|
30 |
* @modules java.management |
2 | 31 |
* @run clean RepositoryWildcardTest |
32 |
* @run build RepositoryWildcardTest |
|
33 |
* @run main RepositoryWildcardTest |
|
34 |
*/ |
|
35 |
||
36 |
import java.util.HashSet; |
|
37 |
import java.util.Set; |
|
38 |
import java.util.TreeSet; |
|
39 |
import javax.management.InstanceNotFoundException; |
|
40 |
import javax.management.MBeanServer; |
|
41 |
import javax.management.MBeanServerDelegate; |
|
42 |
import javax.management.MBeanServerFactory; |
|
43 |
import javax.management.ObjectName; |
|
44 |
import javax.management.RuntimeOperationsException; |
|
45 |
||
46 |
public class RepositoryWildcardTest { |
|
47 |
||
48 |
private static final String classname = |
|
49 |
"javax.management.monitor.StringMonitor"; |
|
50 |
||
51 |
private static int mbeanCreation(MBeanServer mbs, String name) |
|
52 |
throws Exception { |
|
53 |
int error = 0; |
|
54 |
try { |
|
55 |
System.out.println("Test: createMBean(" + name + ")"); |
|
56 |
mbs.createMBean(classname, ObjectName.getInstance(name)); |
|
57 |
error++; |
|
58 |
System.out.println("Didn't get expected exception!"); |
|
59 |
System.out.println("Test failed!"); |
|
60 |
} catch (RuntimeOperationsException e) { |
|
61 |
System.out.println("Got expected exception = " + |
|
62 |
e.getCause().toString()); |
|
63 |
System.out.println("Test passed!"); |
|
64 |
} |
|
65 |
return error; |
|
66 |
} |
|
67 |
||
68 |
private static int mbeanDeletion(MBeanServer mbs, String name) |
|
69 |
throws Exception { |
|
70 |
int error = 0; |
|
71 |
try { |
|
72 |
System.out.println("Test: unregisterMBean(" + name + ")"); |
|
73 |
mbs.unregisterMBean(ObjectName.getInstance(name)); |
|
74 |
error++; |
|
75 |
System.out.println("Didn't get expected exception!"); |
|
76 |
System.out.println("Test failed!"); |
|
77 |
} catch (InstanceNotFoundException e) { |
|
78 |
System.out.println("Got expected exception = " + e.toString()); |
|
79 |
System.out.println("Test passed!"); |
|
80 |
} |
|
81 |
return error; |
|
82 |
} |
|
83 |
||
84 |
private static int mbeanQuery(MBeanServer mbs, |
|
85 |
String name, |
|
86 |
Set<ObjectName> expectedSet) |
|
87 |
throws Exception { |
|
88 |
int error = 0; |
|
89 |
System.out.println("Test: queryNames(" + name + ")"); |
|
90 |
Set<ObjectName> returnedSet = |
|
91 |
mbs.queryNames(ObjectName.getInstance(name), null); |
|
92 |
System.out.println("ReturnedSet = " + new TreeSet(returnedSet)); |
|
93 |
System.out.println("ExpectedSet = " + new TreeSet(expectedSet)); |
|
94 |
if (returnedSet.equals(expectedSet)) { |
|
95 |
System.out.println("Test passed!"); |
|
96 |
} else { |
|
97 |
error++; |
|
98 |
System.out.println("Test failed!"); |
|
99 |
} |
|
100 |
return error; |
|
101 |
} |
|
102 |
||
103 |
public static void main(String[] args) throws Exception { |
|
104 |
||
105 |
int error = 0; |
|
106 |
||
107 |
MBeanServer mbs = MBeanServerFactory.newMBeanServer(); |
|
108 |
||
109 |
ObjectName[] namesArray = { |
|
110 |
ObjectName.getInstance("d:k=abc"), |
|
111 |
ObjectName.getInstance("d:k=abcd"), |
|
112 |
ObjectName.getInstance("d:k=abcde"), |
|
113 |
ObjectName.getInstance("d:k=abc,k2=v2"), |
|
114 |
ObjectName.getInstance("d:k=abcd,k2=v2"), |
|
115 |
ObjectName.getInstance("d:k=abcde,k2=v2"), |
|
116 |
ObjectName.getInstance("d:k=\"abc\""), |
|
117 |
ObjectName.getInstance("d:k=\"abc\",k2=v2"), |
|
118 |
ObjectName.getInstance("d:p1=v1,p2=v2,p3=v3,p4=v4,p5=v5,p6=v6," + |
|
119 |
"p7=v7,p8=v8,p9=v9,p10=v10,p11=v11,p12=v12") |
|
120 |
}; |
|
121 |
||
122 |
for (ObjectName name : namesArray) |
|
123 |
mbs.createMBean(classname, name); |
|
124 |
||
125 |
System.out.println("----------------------------------------------"); |
|
126 |
System.out.println("TEST createMBean WITH PATTERNS"); |
|
127 |
System.out.println("----------------------------------------------"); |
|
128 |
||
129 |
error += mbeanCreation(mbs, "d:k=v,*"); |
|
130 |
error += mbeanCreation(mbs, "d:k=*"); |
|
131 |
error += mbeanCreation(mbs, "d:k=a?b"); |
|
132 |
error += mbeanCreation(mbs, "d:k=\"?\""); |
|
133 |
error += mbeanCreation(mbs, "d:k=\"a*b\""); |
|
134 |
||
135 |
System.out.println("----------------------------------------------"); |
|
136 |
System.out.println("TEST queryNames WITH PATTERNS"); |
|
137 |
System.out.println("----------------------------------------------"); |
|
138 |
||
139 |
Set<ObjectName> expectedSet = new HashSet<ObjectName>(); |
|
140 |
for (ObjectName name : namesArray) |
|
141 |
expectedSet.add(name); |
|
142 |
expectedSet.add(MBeanServerDelegate.DELEGATE_NAME); |
|
143 |
Set<ObjectName> returnedSet = |
|
144 |
mbs.queryNames(ObjectName.getInstance("*:*"), null); |
|
145 |
error += mbeanQuery(mbs, "*:*", expectedSet); |
|
146 |
||
147 |
expectedSet = new HashSet<ObjectName>(); |
|
148 |
for (ObjectName name : namesArray) |
|
149 |
expectedSet.add(name); |
|
150 |
error += mbeanQuery(mbs, "d:*", expectedSet); |
|
151 |
||
152 |
expectedSet = new HashSet<ObjectName>(); |
|
153 |
expectedSet.add(namesArray[0]); |
|
154 |
expectedSet.add(namesArray[1]); |
|
155 |
expectedSet.add(namesArray[2]); |
|
156 |
expectedSet.add(namesArray[6]); |
|
157 |
error += mbeanQuery(mbs, "d:k=*", expectedSet); |
|
158 |
||
159 |
expectedSet = new HashSet<ObjectName>(); |
|
160 |
expectedSet.add(namesArray[3]); |
|
161 |
expectedSet.add(namesArray[4]); |
|
162 |
expectedSet.add(namesArray[5]); |
|
163 |
expectedSet.add(namesArray[7]); |
|
164 |
error += mbeanQuery(mbs, "d:k=*,k2=v2", expectedSet); |
|
165 |
||
166 |
expectedSet = new HashSet<ObjectName>(); |
|
167 |
expectedSet.add(namesArray[3]); |
|
168 |
expectedSet.add(namesArray[4]); |
|
169 |
expectedSet.add(namesArray[5]); |
|
170 |
expectedSet.add(namesArray[7]); |
|
171 |
error += mbeanQuery(mbs, "d:k=*,k2=v?", expectedSet); |
|
172 |
||
173 |
expectedSet = new HashSet<ObjectName>(); |
|
174 |
expectedSet.add(namesArray[3]); |
|
175 |
expectedSet.add(namesArray[4]); |
|
176 |
expectedSet.add(namesArray[5]); |
|
177 |
expectedSet.add(namesArray[7]); |
|
178 |
error += mbeanQuery(mbs, "d:*,k2=v2", expectedSet); |
|
179 |
||
180 |
expectedSet = new HashSet<ObjectName>(); |
|
181 |
expectedSet.add(namesArray[1]); |
|
182 |
error += mbeanQuery(mbs, "d:k=ab?d", expectedSet); |
|
183 |
||
184 |
expectedSet = new HashSet<ObjectName>(); |
|
185 |
expectedSet.add(namesArray[1]); |
|
186 |
expectedSet.add(namesArray[4]); |
|
187 |
error += mbeanQuery(mbs, "d:k=ab?d,*", expectedSet); |
|
188 |
||
189 |
expectedSet = new HashSet<ObjectName>(); |
|
190 |
expectedSet.add(namesArray[6]); |
|
191 |
error += mbeanQuery(mbs, "d:k=\"*\"", expectedSet); |
|
192 |
||
193 |
expectedSet = new HashSet<ObjectName>(); |
|
194 |
expectedSet.add(namesArray[7]); |
|
195 |
error += mbeanQuery(mbs, "d:k=\"*\",k2=v?", expectedSet); |
|
196 |
||
197 |
expectedSet = new HashSet<ObjectName>(); |
|
198 |
expectedSet.add(namesArray[8]); |
|
199 |
error += mbeanQuery(mbs, |
|
200 |
"d:p1=v?,p2=v?,p3=v?,p4=v?,p5=v?,p6=v?," + |
|
201 |
"p7=v?,p8=v?,p9=v?,p10=v??,p11=v??,p12=v??", |
|
202 |
expectedSet); |
|
203 |
||
204 |
System.out.println("----------------------------------------------"); |
|
205 |
System.out.println("TEST unregisterMBean WITH PATTERNS"); |
|
206 |
System.out.println("----------------------------------------------"); |
|
207 |
||
208 |
error += mbeanDeletion(mbs, "d:k=*"); |
|
209 |
error += mbeanDeletion(mbs, "d:k=\"*\""); |
|
210 |
||
211 |
if (error > 0) { |
|
212 |
final String msg = "Test FAILED! Got " + error + " error(s)"; |
|
213 |
System.out.println(msg); |
|
214 |
throw new IllegalArgumentException(msg); |
|
215 |
} else { |
|
216 |
System.out.println("Test PASSED!"); |
|
217 |
} |
|
218 |
} |
|
219 |
} |