author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 51192 | 499b873761d8 |
permissions | -rw-r--r-- |
51192
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
1 |
/* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
2 |
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
4 |
* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
8 |
* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
13 |
* accompanied this code). |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
14 |
* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
18 |
* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
21 |
* questions. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
22 |
*/ |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
23 |
|
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
24 |
/* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
25 |
* @test |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
26 |
* @bug 8198882 |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
27 |
* @summary Tests that we can get an attribute that has a nonstandard name from |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
28 |
* a DNS entry. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
29 |
* @modules java.base/sun.security.util |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
30 |
* @library ../lib/ |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
31 |
* @run main GetNonstandard |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
32 |
*/ |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
33 |
|
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
34 |
import javax.naming.NamingException; |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
35 |
import javax.naming.directory.Attribute; |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
36 |
import javax.naming.directory.Attributes; |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
37 |
import java.util.Arrays; |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
38 |
|
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
39 |
public class GetNonstandard extends GetAttrsBase { |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
40 |
// "40 2 0.373 N 105 17 23.528 W 1638m" |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
41 |
private static final byte[] EXPECTED_VALUE = { (byte) 0, // version |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
42 |
(byte) 18, // size |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
43 |
(byte) 22, // horiz pre |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
44 |
(byte) 19, // vert pre |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
45 |
(byte) -120, // latitude 1 |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
46 |
(byte) -105, // latitude 2 |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
47 |
(byte) 26, // longitude 1 |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
48 |
(byte) 53, // longitude 2 |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
49 |
(byte) 105, // altitude 1 |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
50 |
(byte) 104, // altitude 2 |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
51 |
(byte) 65, (byte) 56, (byte) 0, (byte) -101, (byte) 22, |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
52 |
(byte) 88, }; |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
53 |
|
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
54 |
public GetNonstandard() { |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
55 |
// set new test data instead of default value |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
56 |
setMandatoryAttrs("29"); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
57 |
} |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
58 |
|
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
59 |
public static void main(String[] args) throws Exception { |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
60 |
new GetNonstandard().run(args); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
61 |
} |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
62 |
|
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
63 |
@Override public void runTest() throws Exception { |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
64 |
initContext(); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
65 |
Attributes retAttrs = getAttributes(); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
66 |
verifyAttributes(retAttrs); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
67 |
verifyLoc(retAttrs); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
68 |
} |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
69 |
|
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
70 |
/* |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
71 |
* Tests that we can get an attribute that has a nonstandard name from |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
72 |
* a DNS entry. |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
73 |
*/ |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
74 |
@Override public Attributes getAttributes() throws Exception { |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
75 |
return context().getAttributes(getKey(), getMandatoryAttrs()); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
76 |
} |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
77 |
|
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
78 |
private void verifyLoc(Attributes retAttrs) throws NamingException { |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
79 |
Attribute loc = retAttrs.get(getMandatoryAttrs()[0]); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
80 |
byte[] val = (byte[]) loc.get(0); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
81 |
|
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
82 |
String expected = Arrays.toString(EXPECTED_VALUE); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
83 |
String actual = Arrays.toString(val); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
84 |
DNSTestUtils.debug("Expected: " + expected); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
85 |
DNSTestUtils.debug("Actual: " + actual); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
86 |
|
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
87 |
if (!Arrays.equals(val, EXPECTED_VALUE)) { |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
88 |
throw new RuntimeException(String.format( |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
89 |
"Failed: values not match, expected: %s, actual: %s", |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
90 |
expected, actual)); |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
91 |
} |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
92 |
} |
499b873761d8
8198882: Add 10 JNDI tests to com/sun/jndi/dns/AttributeTests/
xyin
parents:
diff
changeset
|
93 |
} |