Path: blob/master/test/jdk/com/sun/jndi/dns/ConfigTests/AuthRecursiveBase.java
41155 views
/*1* Copyright (c) 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*/2223import javax.naming.NamingException;24import javax.naming.directory.Attributes;2526/**27* Abstract test base for Config related tests, this class extends DNSTestBase.28*29* @see DNSTestBase30* @see TestBase31*/32abstract class AuthRecursiveBase extends DNSTestBase {3334private static final String KEY = "host1";35private static final String[] MANDATORY_ATTRIBUTES = { "A", "MX", "HINFO",36"TXT", "29" };37private static final String[] OPTIONAL_ATTRIBUTES = {};3839private String fqdnUrl;40private String foreignFqdnUrl;4142/**43* Setup test before real test run, it overrides the method of TestBase.44*/45@Override46public void setupTest() {47super.setupTest();48String fqdn = DNSTestUtils.buildFqdn(KEY, env(), true);4950String foreignLeaf = (String) env().get("FOREIGN_LEAF");51String foreignFqdn = DNSTestUtils.buildFqdn(foreignLeaf, env(), false);5253fqdnUrl = DNSTestUtils.getRootUrl(env()) + "/" + fqdn;54foreignFqdnUrl = DNSTestUtils.getRootUrl(env()) + "/" + foreignFqdn;55}5657/**58* Overload method of retrieveAndVerifyData, it will retrieve all of the59* attributes associated with given named object and do verification.60*61* @param name given named object62* @throws NamingException if a naming exception is encountered63*/64public void retrieveAndVerifyData(String name) throws NamingException {65Attributes retAttrs = context().getAttributes(name);66DNSTestUtils.verifySchema(retAttrs, MANDATORY_ATTRIBUTES,67OPTIONAL_ATTRIBUTES);68}6970/**71* Retrieves selected attributes associated with a named object and do72* verification.73*74* @param name given named object75* @param attrIds given ids of the attributes to retrieve76* @throws NamingException if a naming exception is encountered77*/78public void retrieveAndVerifyData(String name, String[] attrIds)79throws NamingException {80Attributes retAttrs = context().getAttributes(name, attrIds);81DNSTestUtils.verifySchema(retAttrs, MANDATORY_ATTRIBUTES,82OPTIONAL_ATTRIBUTES);83}8485/**86* Return parsed flag from given test name.87*88* @return parsed flag from given test name89*/90public String parseFlagFromTestName() {91String name = (String) env().get("testname");92if (name == null || name.isEmpty()) {93throw new RuntimeException("test name expecting not null/empty");94}9596if (name.endsWith("Default")) {97return "default";98} else if (name.endsWith("True")) {99return "true";100} else if (name.endsWith("False")) {101return "false";102} else {103throw new RuntimeException("Invalid test name " + name);104}105}106107public String getFqdnUrl() {108return fqdnUrl;109}110111public String getForeignFqdnUrl() {112return foreignFqdnUrl;113}114}115116117