Path: blob/master/test/jdk/com/sun/jndi/dns/lib/TestBase.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*/2223/**24* The test base class for JNDI related tests.25*26* run() will be the entry to launch whole tests, base test sequence is27* initRes(), initTest(), setupTest() and launch().28*29* launch() will call real test logic runTest() which required to be implemented30* in test class.31*32* exception handling logic should be placed in handleException().33*34* cleanup related should be placed in cleanupTest which been called in finally35* block.36*/37public abstract class TestBase {3839/**40* The entry to the test.41*42* @param args given input arguments43* @throws Exception if any exception44*/45public void run(String[] args) throws Exception {46initRes();47initTest(args);48setupTest();49launch();50}5152/**53* Initial local resources, such as socket.54*55* @throws Exception if any exception56*/57public void initRes() throws Exception {58}5960/**61* Initial test with given arguments.62*63* @param args given arguments64*/65public void initTest(String[] args) {66}6768/**69* Setup test.70*/71public void setupTest() {72}7374/**75* Launch test.76*77* @throws Exception if any exception78*/79public void launch() throws Exception {80try {81runTest();82} catch (Exception e) {83if (!handleException(e)) {84throw e;85}86} finally {87cleanupTest();88}89}9091/**92* The real test logic to run, this required to be implemented in test class.93*94* @throws Exception if any exception95*/96public abstract void runTest() throws Exception;9798/**99* Handle test exception.100*101* @param e exception which been thrown during test runTest()102* @return <tt>true</tt> if given exception is expected103*/104public boolean handleException(Exception e) {105return false;106}107108/**109* Cleanup test.110*/111public abstract void cleanupTest();112}113114115