Path: blob/master/test/jdk/com/sun/jndi/dns/lib/DNSTestBase.java
41155 views
/*1* Copyright (c) 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*/2223import javax.naming.directory.DirContext;24import java.util.Hashtable;2526/**27* The test base class for DNS related tests, extends TestBase.28*29* This class override some methods of supper class to provide DNS tests shared30* base logic.31*32* @see TestBase33*/34public abstract class DNSTestBase extends TestBase {35private Hashtable<Object, Object> env;36private DirContext ctx;37private boolean localServer;3839public DNSTestBase() {40// set default, we will run with local server playback by default41setLocalServer(true);42}4344@Override public void initTest(String[] args) {45// init env which will used later to initial dir context46env = DNSTestUtils47.initEnv(localServer, this.getClass().getName(), args);48}4950@Override public void cleanupTest() {51// cleanup dir context52DNSTestUtils.cleanup(ctx);53// stop local server if there is54Server server = (Server) env.get(DNSTestUtils.TEST_DNS_SERVER_THREAD);55if (server != null) {56server.stopServer();57}58}5960public Hashtable<Object, Object> env() {61if (env == null) {62throw new RuntimeException("Test had not been initialized");63}6465return env;66}6768public DirContext context() {69if (ctx == null) {70throw new RuntimeException("Context had not been initialized");71}7273return ctx;74}7576public void setContext(DirContext context) {77ctx = context;78}7980public void setLocalServer(boolean isRequired) {81this.localServer = isRequired;82}83}848586