author | xyin |
Wed, 25 Jul 2018 11:03:07 +0800 | |
changeset 51192 | 499b873761d8 |
parent 48851 | 1d8f882f2b2f |
child 52205 | a562c65c3c74 |
permissions | -rw-r--r-- |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
1 |
/* |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
4 |
* |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
8 |
* |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
13 |
* accompanied this code). |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
14 |
* |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
18 |
* |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
21 |
* questions. |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
22 |
*/ |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
23 |
|
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
24 |
import javax.naming.Context; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
25 |
import javax.naming.NamingException; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
26 |
import javax.naming.directory.Attributes; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
27 |
import java.io.PrintStream; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
28 |
import java.nio.file.Files; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
29 |
import java.nio.file.Path; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
30 |
import java.nio.file.Paths; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
31 |
import java.util.Hashtable; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
32 |
|
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
33 |
/** |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
34 |
* This is utility class for DNS test, it contains many helper methods to |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
35 |
* support test construction. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
36 |
* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
37 |
* For basic test sequence see TestBase and DNSTestBase. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
38 |
*/ |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
39 |
public class DNSTestUtils { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
40 |
public static final String TEST_DNS_SERVER_THREAD = "test.dns.server.thread"; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
41 |
public static final String TEST_DNS_ROOT_URL = "test.dns.root.url"; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
42 |
public static final int HOSTS_LOOKUP_MAX_DEPTH = 3; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
43 |
|
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
44 |
protected static boolean debug = true; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
45 |
|
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
46 |
/** |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
47 |
* Check that attributes contains the mandatory attributes and the right |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
48 |
* objectclass attribute. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
49 |
* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
50 |
* @param attrs given attributes to verify |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
51 |
* @param mandatory given mandatory for verification |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
52 |
* @param optional given optional for verification |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
53 |
* @return <tt>true</tt> if check ok |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
54 |
*/ |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
55 |
public static boolean checkSchema(Attributes attrs, String[] mandatory, |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
56 |
String[] optional) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
57 |
// Check mandatory attributes |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
58 |
for (String mandatoryAttr : mandatory) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
59 |
if (attrs.get(mandatoryAttr) == null) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
60 |
debug("missing mandatory attribute: " + mandatoryAttr); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
61 |
return false; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
62 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
63 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
64 |
|
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
65 |
// Check optional attributes |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
66 |
int optMissing = 0; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
67 |
for (String optionalAttr : optional) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
68 |
if (attrs.get(optionalAttr) == null) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
69 |
debug("warning: missing optional attribute: " + optionalAttr); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
70 |
++optMissing; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
71 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
72 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
73 |
|
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
74 |
if (attrs.size() > (mandatory.length + (optional.length |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
75 |
- optMissing))) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
76 |
debug("too many attributes: " + attrs); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
77 |
return false; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
78 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
79 |
|
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
80 |
return true; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
81 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
82 |
|
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
83 |
/** |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
84 |
* Process command line arguments and init env. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
85 |
* This method will prepare default environments which to be used to initial |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
86 |
* DirContext. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
87 |
* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
88 |
* @param localServer <tt>true</tt> if this test will run against with local |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
89 |
* server against dump message playback |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
90 |
* @param testname test case name to identify playback file |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
91 |
* @param args additional arguments for env preparation |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
92 |
* @return prepared env which will be used later to initial DirContext |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
93 |
*/ |
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
94 |
public static Hashtable<Object, Object> initEnv(boolean localServer, |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
95 |
String testname, String[] args) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
96 |
|
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
97 |
Hashtable<Object, Object> env = new Hashtable<>(); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
98 |
|
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
99 |
// set some default parameters if no additional specified |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
100 |
env.put("DNS_DOMAIN", "domain1.com."); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
101 |
env.put("FOREIGN_DOMAIN", "Central.Sun.COM."); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
102 |
env.put("FOREIGN_LEAF", "sunweb"); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
103 |
|
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
104 |
// set defaults for some JNDI properties |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
105 |
env.put(Context.INITIAL_CONTEXT_FACTORY, |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
106 |
"com.sun.jndi.dns.DnsContextFactory"); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
107 |
|
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
108 |
boolean traceEnable = false; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
109 |
boolean loopPlayback = false; |
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
110 |
for (String arg : args) { |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
111 |
if (arg.startsWith("-D")) { |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
112 |
extractProperty(arg.substring(2), env); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
113 |
} else if (arg.equalsIgnoreCase("-trace")) { |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
114 |
traceEnable = true; |
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
115 |
} else if (arg.equalsIgnoreCase("-loop")) { |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
116 |
loopPlayback = true; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
117 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
118 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
119 |
|
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
120 |
debug = Boolean.valueOf(System.getProperty("debug", "true")); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
121 |
|
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
122 |
if (env.get("DNS_SERVER") != null) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
123 |
String port = (String) env.get("DNS_PORT"); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
124 |
String portSuffix = (port == null) ? "" : ":" + port; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
125 |
String url = "dns://" + env.get("DNS_SERVER") + portSuffix; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
126 |
env.put(Context.PROVIDER_URL, url); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
127 |
env.put(Context.PROVIDER_URL, url + "/" + env.get("DNS_DOMAIN")); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
128 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
129 |
|
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
130 |
Thread inst = null; |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
131 |
if (traceEnable) { |
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
132 |
// if trace is enabled, create DNSTracer to dump those message |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
133 |
inst = createDNSTracer(testname, env); |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
134 |
} else { |
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
135 |
if (localServer) { |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
136 |
// if use local server, create local DNSServer for playback |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
137 |
inst = createDNSServer(testname, loopPlayback); |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
138 |
} else { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
139 |
// for tests which run against remote server |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
140 |
// or no server required |
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
141 |
debug("Skip local DNS Server creation "); |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
142 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
143 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
144 |
|
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
145 |
if (inst != null) { |
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
146 |
inst.start(); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
147 |
env.put(TEST_DNS_SERVER_THREAD, inst); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
148 |
String url = "dns://localhost:" + ((Server) inst).getPort(); |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
149 |
|
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
150 |
env.put(TEST_DNS_ROOT_URL, url); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
151 |
env.put(Context.PROVIDER_URL, url + "/" + env.get("DNS_DOMAIN")); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
152 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
153 |
|
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
154 |
return env; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
155 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
156 |
|
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
157 |
/** |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
158 |
* Clean-up the given directory context. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
159 |
* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
160 |
* @param ctx given context object |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
161 |
*/ |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
162 |
public static void cleanup(Context ctx) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
163 |
if (ctx != null) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
164 |
try { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
165 |
ctx.close(); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
166 |
} catch (NamingException e) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
167 |
// ignore |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
168 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
169 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
170 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
171 |
|
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
172 |
private static void extractProperty(String propString, |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
173 |
Hashtable<Object, Object> env) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
174 |
int index; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
175 |
|
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
176 |
if ((index = propString.indexOf('=')) > 0) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
177 |
env.put(propString.substring(0, index), |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
178 |
propString.substring(index + 1)); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
179 |
} else { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
180 |
throw new RuntimeException( |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
181 |
"Failed to extract test args property from " + propString); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
182 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
183 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
184 |
|
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
185 |
/** |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
186 |
* Return new created DNS tracer. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
187 |
* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
188 |
* @param testname test case name to identify playback file |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
189 |
* @param env given env for initialization |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
190 |
* @return created DNS tracer |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
191 |
* @see DNSTracer |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
192 |
*/ |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
193 |
public static DNSTracer createDNSTracer(String testname, |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
194 |
Hashtable<Object, Object> env) { |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
195 |
try { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
196 |
PrintStream outStream = new PrintStream(getCaptureFile(testname)); |
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
197 |
return new DNSTracer(outStream, (String) env.get("DNS_SERVER"), |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
198 |
Integer.parseInt((String) env.get("DNS_PORT"))); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
199 |
} catch (Exception e) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
200 |
throw new RuntimeException( |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
201 |
"Error: failed to create DNSTracer : " + e.getMessage(), e); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
202 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
203 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
204 |
|
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
205 |
/** |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
206 |
* Return new created local DNS Server. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
207 |
* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
208 |
* @param testname test case name to identify playback file |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
209 |
* @param loop <tt>true</tt> if DNS server required playback message in loop |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
210 |
* @return created local DNS Server |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
211 |
* @see DNSServer |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
212 |
*/ |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
213 |
public static DNSServer createDNSServer(String testname, boolean loop) { |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
214 |
String path = getCaptureFile(testname); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
215 |
if (Files.exists(Paths.get(path))) { |
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
216 |
try { |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
217 |
return new DNSServer(path, loop); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
218 |
} catch (Exception e) { |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
219 |
throw new RuntimeException( |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
220 |
"Error: failed to create DNSServer : " + e.getMessage(), |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
221 |
e); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
222 |
} |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
223 |
} else { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
224 |
throw new RuntimeException( |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
225 |
"Error: failed to create DNSServer, not found dns " |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
226 |
+ "cache file " + path); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
227 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
228 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
229 |
|
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
230 |
/** |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
231 |
* Return dns message capture file path. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
232 |
* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
233 |
* @param testname test case name to identify playback file |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
234 |
* @return capture file path |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
235 |
*/ |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
236 |
public static String getCaptureFile(String testname) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
237 |
return Paths.get(System.getProperty("test.src")) |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
238 |
.resolve(testname + ".dns").toString(); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
239 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
240 |
|
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
241 |
/** |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
242 |
* Enable hosts file. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
243 |
* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
244 |
* @param hostsFile given hosts file |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
245 |
*/ |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
246 |
public static void enableHostsFile(String hostsFile) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
247 |
System.out.println("Enable jdk.net.hosts.file = " + hostsFile); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
248 |
System.setProperty("jdk.net.hosts.file", hostsFile); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
249 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
250 |
|
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
251 |
/** |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
252 |
* Enable hosts file by given searching depth. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
253 |
* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
254 |
* @param depth given depth for searching hosts file |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
255 |
*/ |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
256 |
public static void enableHostsFile(int depth) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
257 |
Path path = Paths.get(System.getProperty("test.src", ".")) |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
258 |
.toAbsolutePath(); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
259 |
for (int i = depth; i >= 0; i--) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
260 |
Path filePath = path.resolve("hosts"); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
261 |
if (Files.exists(filePath) && !Files.isDirectory(filePath)) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
262 |
enableHostsFile(filePath.toString()); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
263 |
break; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
264 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
265 |
|
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
266 |
path = path.getParent(); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
267 |
if (path == null) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
268 |
break; |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
269 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
270 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
271 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
272 |
|
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
273 |
/** |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
274 |
* Print given object if debug enabled. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
275 |
* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
276 |
* @param object given object to print |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
277 |
*/ |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
278 |
public static void debug(Object object) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
279 |
if (debug) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
280 |
System.out.println(object); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
281 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
282 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
283 |
|
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
284 |
/** |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
285 |
* Verify attributes contains the mandatory attributes and the right |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
286 |
* objectclass attribute, will throw RuntimeException if verify failed. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
287 |
* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
288 |
* @param attrs given attributes to verify |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
289 |
* @param mandatory given mandatory for verification |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
290 |
* @param optional given optional for verification |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
291 |
*/ |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
292 |
public static void verifySchema(Attributes attrs, String[] mandatory, |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
293 |
String[] optional) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
294 |
debug(attrs); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
295 |
if (!checkSchema(attrs, mandatory, optional)) { |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
296 |
throw new RuntimeException("Check schema failed."); |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
297 |
} |
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
298 |
} |
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
299 |
|
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
300 |
/** |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
301 |
* Return dns root url. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
302 |
* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
303 |
* @param env given env |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
304 |
* @return dns root url |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
305 |
*/ |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
306 |
public static String getRootUrl(Hashtable<Object, Object> env) { |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
307 |
return (String) env.get(TEST_DNS_ROOT_URL); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
308 |
} |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
309 |
|
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
310 |
/** |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
311 |
* Assemble a fully-qualified domain name from the base component and the |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
312 |
* domain name. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
313 |
* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
314 |
* @param base given base component |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
315 |
* @param env given env |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
316 |
* @param primary <tt>true</tt> if primary domain |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
317 |
* @return assembled fully-qualified domain name |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
318 |
*/ |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
319 |
public static String buildFqdn(String base, Hashtable<Object, Object> env, |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
320 |
boolean primary) { |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
321 |
String domain = (String) (primary ? |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
322 |
env.get("DNS_DOMAIN") : |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
323 |
env.get("FOREIGN_DOMAIN")); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
324 |
|
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
325 |
return base + "." + domain; |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
48851
diff
changeset
|
326 |
} |
48851
1d8f882f2b2f
8195976: Add JNDI test com/sun/jndi/dns/AttributeTests/GetAny.java
xyin
parents:
diff
changeset
|
327 |
} |