author | xdono |
Thu, 30 Apr 2009 15:04:39 -0700 | |
changeset 2691 | bad7bbf42755 |
parent 1327 | 912486b03832 |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
1327
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
1 |
/* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
2 |
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
4 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Sun designates this |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
10 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
15 |
* accompanied this code). |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
16 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
20 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
23 |
* have any questions. |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
24 |
*/ |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
25 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
26 |
/* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
27 |
* @test |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
28 |
* @bug 6622366 |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
29 |
* @summary Basic Test for registry class |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
30 |
* by replacing stclient with SvcTagClient utility |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
31 |
* @author Mandy Chung |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
32 |
* |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
33 |
* @run build SvcTagClient SystemRegistryTest Util |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
34 |
* @run main SystemRegistryTest |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
35 |
*/ |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
36 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
37 |
import com.sun.servicetag.*; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
38 |
import java.io.*; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
39 |
import java.util.*; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
40 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
41 |
public class SystemRegistryTest { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
42 |
private static String registryDir = System.getProperty("test.classes"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
43 |
private static String servicetagDir = System.getProperty("test.src"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
44 |
private static List<ServiceTag> list = new ArrayList<ServiceTag>(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
45 |
private static String[] files = new String[] { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
46 |
"servicetag1.properties", |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
47 |
"servicetag2.properties", |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
48 |
"servicetag3.properties" |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
49 |
}; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
50 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
51 |
private static Registry registry; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
52 |
public static void main(String[] argv) throws Exception { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
53 |
registry = Util.getSvcTagClientRegistry(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
54 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
55 |
for (String filename : files) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
56 |
File f = new File(servicetagDir, filename); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
57 |
ServiceTag svcTag = Util.newServiceTag(f); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
58 |
ServiceTag st = registry.addServiceTag(svcTag); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
59 |
list.add(st); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
60 |
System.out.println(st); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
61 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
62 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
63 |
testDuplicate(list.get(0)); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
64 |
testNotFound(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
65 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
66 |
// remove a service tag |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
67 |
String urn = list.get(0).getInstanceURN(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
68 |
ServiceTag svcTag = registry.removeServiceTag(urn); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
69 |
if (!Util.matches(svcTag, list.get(0))) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
70 |
throw new RuntimeException(urn + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
71 |
" deleted but does not match."); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
72 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
73 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
74 |
// get a service tag |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
75 |
svcTag = list.get(1); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
76 |
urn = svcTag.getInstanceURN(); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
77 |
ServiceTag st = registry.getServiceTag(urn); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
78 |
if (!Util.matches(svcTag, st)) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
79 |
throw new RuntimeException(urn + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
80 |
" returned from getServiceTag but does not match."); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
81 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
82 |
// update the service tag |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
83 |
registry.updateServiceTag(urn, "My new defined ID"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
84 |
st = registry.getServiceTag(urn); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
85 |
if (Util.matches(svcTag, st)) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
86 |
throw new RuntimeException(urn + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
87 |
" updated but expected to be different."); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
88 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
89 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
90 |
if (!st.getProductDefinedInstanceID().equals("My new defined ID")) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
91 |
throw new RuntimeException("Invalid product_defined_instance_id " + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
92 |
st.getProductDefinedInstanceID()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
93 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
94 |
if (st.getInstallerUID() != -1) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
95 |
throw new RuntimeException("Invalid installer_uid " + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
96 |
st.getInstallerUID()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
97 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
98 |
if (st.getTimestamp().equals(svcTag.getTimestamp())) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
99 |
throw new RuntimeException("Timestamp " + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
100 |
st.getTimestamp() + " == " + svcTag.getTimestamp()); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
101 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
102 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
103 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
104 |
private static void testDuplicate(ServiceTag st) throws IOException { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
105 |
boolean dup = false; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
106 |
try { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
107 |
registry.addServiceTag(st); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
108 |
} catch (IllegalArgumentException e) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
109 |
dup = true; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
110 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
111 |
if (!dup) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
112 |
throw new RuntimeException(st.getInstanceURN() + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
113 |
" added successfully but expected to be a duplicated."); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
114 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
115 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
116 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
117 |
private static void testNotFound() throws Exception { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
118 |
String instanceURN = "urn:st:721cf98a-f4d7-6231-bb1d-f2f5aa903ef7"; |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
119 |
ServiceTag svctag = registry.removeServiceTag(instanceURN); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
120 |
if (svctag != null) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
121 |
throw new RuntimeException(instanceURN + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
122 |
" exists but expected not found"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
123 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
124 |
|
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
125 |
svctag = registry.updateServiceTag(instanceURN, "testing"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
126 |
if (svctag != null) { |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
127 |
throw new RuntimeException(instanceURN + |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
128 |
" exists but expected not found"); |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
129 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
130 |
} |
912486b03832
6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff
changeset
|
131 |
} |