Path: blob/master/test/jdk/com/sun/jndi/dns/EnvTests/SubcontextRemove.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 child27* context, its changes do not affect the environment properties of28* the parent context.29* @library ../lib/30* @modules java.base/sun.security.util31* @run main SubcontextRemove32*/3334import javax.naming.Context;35import javax.naming.NamingException;36import javax.naming.directory.InitialDirContext;37import java.util.Hashtable;3839public class SubcontextRemove extends EnvTestBase {4041public static void main(String[] args) throws Exception {42new SubcontextRemove().run(args);43}4445/*46* Tests that when we remove environment properties from a child47* context, its changes do not affect the environment properties of48* the parent context.49*/50@Override public void runTest() throws Exception {51initContext();5253Context child = (Context) context().lookup(getKey());5455// some.irrelevant.property been set in initContext(), should not be null56Object val = child.removeFromEnvironment("some.irrelevant.property");5758if (!"somevalue".equals(val)) {59throw new RuntimeException(60"Failed: unexpected return value for removeFromEnvironment: "61+ val);62}6364Hashtable<?,?> envParent = context().getEnvironment();65Hashtable<?,?> envChild = child.getEnvironment();6667DNSTestUtils.debug(child);68DNSTestUtils.debug("Parent env: " + envParent);69DNSTestUtils.debug("Child env: " + envChild);7071verifyEnvProperty(envParent, "com.sun.jndi.dns.recursion", "false");72verifyEnvProperty(envParent, "some.irrelevant.property", "somevalue");73verifyEnvProperty(envChild, "com.sun.jndi.dns.recursion", "false");74verifyEnvProperty(envChild, "some.irrelevant.property", null);75}7677private void initContext() throws NamingException {78env().put("com.sun.jndi.dns.recursion", "false");79env().put("some.irrelevant.property", "somevalue");80setContext(new InitialDirContext(env()));81}82}838485