< prev index next >

test/jdk/com/sun/jndi/dns/EnvTests/SubcontextRemove.java

Print this page


   1 /*
   2  * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  45 
  46     /*
  47      * Tests that when we remove environment properties from a child
  48      * context, its changes do not affect the environment properties of
  49      * the parent context.
  50      */
  51     @Override public void runTest() throws Exception {
  52         initContext();
  53 
  54         Context child = (Context) context().lookup(getKey());
  55 
  56         // some.irrelevant.property been set in initContext(), should not be null
  57         Object val = child.removeFromEnvironment("some.irrelevant.property");
  58 
  59         if (!"somevalue".equals(val)) {
  60             throw new RuntimeException(
  61                     "Failed: unexpected return value for removeFromEnvironment: "
  62                             + val);
  63         }
  64 
  65         Hashtable envParent = context().getEnvironment();
  66         Hashtable envChild = child.getEnvironment();
  67 
  68         DNSTestUtils.debug(child);
  69         DNSTestUtils.debug("Parent env: " + envParent);
  70         DNSTestUtils.debug("Child env: " + envChild);
  71 
  72         verifyEnvProperty(envParent, "com.sun.jndi.dns.recursion", "false");
  73         verifyEnvProperty(envParent, "some.irrelevant.property", "somevalue");
  74         verifyEnvProperty(envChild, "com.sun.jndi.dns.recursion", "false");
  75         verifyEnvProperty(envChild, "some.irrelevant.property", null);
  76     }
  77 
  78     private void initContext() throws NamingException {
  79         env().put("com.sun.jndi.dns.recursion", "false");
  80         env().put("some.irrelevant.property", "somevalue");
  81         setContext(new InitialDirContext(env()));
  82     }
  83 }
   1 /*
   2  * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  45 
  46     /*
  47      * Tests that when we remove environment properties from a child
  48      * context, its changes do not affect the environment properties of
  49      * the parent context.
  50      */
  51     @Override public void runTest() throws Exception {
  52         initContext();
  53 
  54         Context child = (Context) context().lookup(getKey());
  55 
  56         // some.irrelevant.property been set in initContext(), should not be null
  57         Object val = child.removeFromEnvironment("some.irrelevant.property");
  58 
  59         if (!"somevalue".equals(val)) {
  60             throw new RuntimeException(
  61                     "Failed: unexpected return value for removeFromEnvironment: "
  62                             + val);
  63         }
  64 
  65         Hashtable<?,?> envParent = context().getEnvironment();
  66         Hashtable<?,?> envChild = child.getEnvironment();
  67 
  68         DNSTestUtils.debug(child);
  69         DNSTestUtils.debug("Parent env: " + envParent);
  70         DNSTestUtils.debug("Child env: " + envChild);
  71 
  72         verifyEnvProperty(envParent, "com.sun.jndi.dns.recursion", "false");
  73         verifyEnvProperty(envParent, "some.irrelevant.property", "somevalue");
  74         verifyEnvProperty(envChild, "com.sun.jndi.dns.recursion", "false");
  75         verifyEnvProperty(envChild, "some.irrelevant.property", null);
  76     }
  77 
  78     private void initContext() throws NamingException {
  79         env().put("com.sun.jndi.dns.recursion", "false");
  80         env().put("some.irrelevant.property", "somevalue");
  81         setContext(new InitialDirContext(env()));
  82     }
  83 }
< prev index next >