Path: blob/master/test/jdk/com/sun/jndi/dns/EnvTests/RemoveOps.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*/2223/*24* @test25* @bug 820827926* @summary Tests that when we remove the authoritative property from a context,27* that it affects subsequent context operations.28* @library ../lib/29* @modules java.base/sun.security.util30* @run main RemoveOps31*/3233import javax.naming.Context;34import javax.naming.NameNotFoundException;35import javax.naming.NamingException;36import javax.naming.directory.Attributes;37import javax.naming.directory.InitialDirContext;3839public class RemoveOps extends EnvTestBase {4041public static void main(String[] args) throws Exception {42new RemoveOps().run(args);43}4445/*46* Tests that when we remove the authoritative property from a context,47* that it affects subsequent context operations.48*/49@Override public void runTest() throws Exception {50initContext();5152// Context.AUTHORITATIVE been set in initContext(), should not be null53Object val = context().removeFromEnvironment(Context.AUTHORITATIVE);5455if (!"true".equals(val)) {56throw new RuntimeException(57"Failed: unexpected return value for removeFromEnvironment: "58+ val);59}6061retrieveAndVerifyAuthData();62retrieveNonAuthData();63}6465private void initContext() throws NamingException {66// Make authoritative67env().put(Context.AUTHORITATIVE, "true");68setContext(new InitialDirContext(env()));69}7071private void retrieveAndVerifyAuthData() throws NamingException {72// Ensure that auth data retrieval is OK73retrieveAndVerifyData(getFqdnUrl(), new String[] { "*" });74}7576private void retrieveNonAuthData() throws NamingException {77try {78// Ensure that nonauth data retrieval succeeds79Attributes retAttrs = context()80.getAttributes(getForeignFqdnUrl(), new String[] { "*" });81DNSTestUtils.debug(context().getEnvironment());82DNSTestUtils.debug(retAttrs);8384} catch (NameNotFoundException e) {85throw new RuntimeException(86"Failed: Expecting nonauthoritative entry found: "87+ getForeignFqdnUrl(), e);88}89}90}919293