Path: blob/master/test/jdk/com/sun/jndi/dns/AttributeTests/GetNonstandard.java
41155 views
/*1* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 819888226* @summary Tests that we can get an attribute that has a nonstandard name from27* a DNS entry.28* @modules java.base/sun.security.util29* @library ../lib/30* @run main GetNonstandard31*/3233import javax.naming.NamingException;34import javax.naming.directory.Attribute;35import javax.naming.directory.Attributes;36import java.util.Arrays;3738public class GetNonstandard extends GetAttrsBase {39// "40 2 0.373 N 105 17 23.528 W 1638m"40private static final byte[] EXPECTED_VALUE = { (byte) 0, // version41(byte) 18, // size42(byte) 22, // horiz pre43(byte) 19, // vert pre44(byte) -120, // latitude 145(byte) -105, // latitude 246(byte) 26, // longitude 147(byte) 53, // longitude 248(byte) 105, // altitude 149(byte) 104, // altitude 250(byte) 65, (byte) 56, (byte) 0, (byte) -101, (byte) 22,51(byte) 88, };5253public GetNonstandard() {54// set new test data instead of default value55setMandatoryAttrs("29");56}5758public static void main(String[] args) throws Exception {59new GetNonstandard().run(args);60}6162@Override public void runTest() throws Exception {63initContext();64Attributes retAttrs = getAttributes();65verifyAttributes(retAttrs);66verifyLoc(retAttrs);67}6869/*70* Tests that we can get an attribute that has a nonstandard name from71* a DNS entry.72*/73@Override public Attributes getAttributes() throws Exception {74return context().getAttributes(getKey(), getMandatoryAttrs());75}7677private void verifyLoc(Attributes retAttrs) throws NamingException {78Attribute loc = retAttrs.get(getMandatoryAttrs()[0]);79byte[] val = (byte[]) loc.get(0);8081String expected = Arrays.toString(EXPECTED_VALUE);82String actual = Arrays.toString(val);83DNSTestUtils.debug("Expected: " + expected);84DNSTestUtils.debug("Actual: " + actual);8586if (!Arrays.equals(val, EXPECTED_VALUE)) {87throw new RuntimeException(String.format(88"Failed: values not match, expected: %s, actual: %s",89expected, actual));90}91}92}939495