Path: blob/master/test/jdk/com/sun/jndi/dns/FedTests/GetAttrsSubLeaf.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*/2223import javax.naming.Context;24import javax.naming.NamingException;25import javax.naming.directory.Attribute;26import javax.naming.directory.Attributes;27import javax.naming.directory.InitialDirContext;2829/*30* @test31* @bug 821033932* @summary Tests that we can get the attributes of the leaf node33* in the subordinate naming system of a DNS entry.34* Use getAttributes form that has no attrIds parameter.35* @library ../lib/ ../AttributeTests/36* @modules java.naming/com.sun.jndi.toolkit.dir37* java.base/sun.security.util38* @build FedSubordinateNs FedObjectFactory39* @run main/othervm GetAttrsSubLeaf40*/4142public class GetAttrsSubLeaf extends GetAttrsBase {4344// pre defined attribute value for '/a/b/c'45public static final String ATTRIBUTE_VALUE = "c";4647public GetAttrsSubLeaf() {48setMandatoryAttrs("name", "description");49}5051public static void main(String[] args) throws Exception {52new GetAttrsSubLeaf().run(args);53}5455/*56* Tests that we can get the attributes of the leaf node57* in the subordinate naming system of a DNS entry.58*/59@Override60public void runTest() throws Exception {61env().put(Context.OBJECT_FACTORIES, "FedObjectFactory");62setContext(new InitialDirContext(env()));6364Attributes retAttrs = getAttributes();65Attribute attr = retAttrs.get("name");66verifyAttributes(retAttrs);67verifyAttribute(attr);68}6970/*71* Use getAttributes form that has no attrIds parameter.72*/73@Override74public Attributes getAttributes() throws NamingException {75return context().getAttributes(getKey() + "/a/b/c");76}7778private void verifyAttribute(Attribute attr) throws NamingException {79if (attr == null || !ATTRIBUTE_VALUE.equals(attr.get())) {80throw new RuntimeException(81"Expecting attribute value: " + ATTRIBUTE_VALUE82+ ", but actual: " + (attr != null ?83attr.get() :84attr));85}86}87}888990