Path: blob/master/test/jdk/com/sun/jndi/dns/EnvTests/RemoveInherited.java
41155 views
/*1* Copyright (c) 2000, 2020, 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 820827926* @summary Tests that when we remove environment properties from a context,27* its changes are reflected in the environment properties of any28* child context derived from the context.29* @library ../lib/30* @modules java.base/sun.security.util31* @run main RemoveInherited32*/3334import javax.naming.Context;35import javax.naming.NamingException;36import javax.naming.directory.InitialDirContext;37import java.util.Hashtable;3839public class RemoveInherited extends EnvTestBase {4041private static final String IRRELEVANT_PROPERTY_NAME = "some.irrelevant.property";42private static final String IRRELEVANT_PROPERTY_VALUE = "somevalue";43private static final String DNS_RECURSION_PROPERTY_NAME = "com.sun.jndi.dns.recursion";44private static final String DNS_RECURSION_PROPERTY_VALUE = "false";4546public static void main(String[] args) throws Exception {47new RemoveInherited().run(args);48}4950/*51* Tests that when we remove environment properties from a context,52* its changes are reflected in the environment properties of any53* child context derived from the context.54*/55@Override public void runTest() throws Exception {56initContext();5758// some.irrelevant.property been set in initContext(), should not be null59Object val = context().removeFromEnvironment(IRRELEVANT_PROPERTY_NAME);6061if (!IRRELEVANT_PROPERTY_VALUE.equals(val)) {62throw new RuntimeException(63"Failed: unexpected return value for removeFromEnvironment: "64+ val);65}6667Context child = (Context) context().lookup(getKey());6869Hashtable<?,?> envParent = context().getEnvironment();70Hashtable<?,?> envChild = child.getEnvironment();7172DNSTestUtils.debug(child);73DNSTestUtils.debug("Parent env: " + envParent);74DNSTestUtils.debug("Child env: " + envChild);7576verifyEnvProperty(envParent, DNS_RECURSION_PROPERTY_NAME,77DNS_RECURSION_PROPERTY_VALUE);78verifyEnvProperty(envParent, IRRELEVANT_PROPERTY_NAME, null);79verifyEnvProperty(envChild, DNS_RECURSION_PROPERTY_NAME,80DNS_RECURSION_PROPERTY_VALUE);81verifyEnvProperty(envChild, IRRELEVANT_PROPERTY_NAME, null);82}8384private void initContext() throws NamingException {85env().put(DNS_RECURSION_PROPERTY_NAME, DNS_RECURSION_PROPERTY_VALUE);86env().put(IRRELEVANT_PROPERTY_NAME, IRRELEVANT_PROPERTY_VALUE);87setContext(new InitialDirContext(env()));88}89}909192