Path: blob/master/test/jdk/com/sun/jndi/dns/EnvTests/AddOps.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 add the authoritative property to a context,27* that it affects subsequent context operations.28* @library ../lib/29* @modules java.base/sun.security.util30* @run main AddOps31*/3233import javax.naming.Context;34import javax.naming.NameNotFoundException;35import javax.naming.NamingException;36import javax.naming.directory.Attributes;37import javax.naming.directory.InitialDirContext;3839public class AddOps extends EnvTestBase {4041public static void main(String[] args) throws Exception {42new AddOps().run(args);43}4445/*46* Tests that when we add the authoritative property to a context,47* that it affects subsequent context operations.48*/49@Override public void runTest() throws Exception {50setContext(new InitialDirContext(env()));51addToEnvAndVerifyOldValIsNull(Context.AUTHORITATIVE, "true");52retrieveAndVerifyAuthData();53retrieveNonAuthData();54}5556private void retrieveAndVerifyAuthData() throws NamingException {57// Ensure that auth data retrieval is OK58retrieveAndVerifyData(getFqdnUrl(), new String[] { "*" });59}6061private void retrieveNonAuthData() throws NamingException {62try {63// Ensure that nonauth data retrieval cannot be retrieved64Attributes retAttrs = context()65.getAttributes(getForeignFqdnUrl(), new String[] { "*" });66DNSTestUtils.debug(context().getEnvironment());67DNSTestUtils.debug(retAttrs);68throw new RuntimeException(69"Failed: Expecting nonauth entry not found "70+ getForeignFqdnUrl());7172} catch (NameNotFoundException e) {73System.out.println("Got expected exception: " + e);74}75}76}777879