distributedtestsuite.java.svn-base

来自「cqME :java framework for TCK test.」· SVN-BASE 代码 · 共 419 行 · 第 1/2 页

SVN-BASE
419
字号
/* * $Id$ * * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. * */package com.sun.tck.j2me.javatest;import java.io.File;import java.net.URL;import java.util.Map;import java.util.logging.Logger;import com.sun.javatest.Harness;import com.sun.javatest.TestDescription;import com.sun.javatest.TestEnvironment;import com.sun.javatest.TestSuite;import com.sun.javatest.util.I18NResourceBundle;import com.sun.tck.j2me.services.LifeCycleAware;import com.sun.tck.j2me.services.ServiceFault;import com.sun.tck.j2me.services.commService.CommTestSuiteService;import com.sun.tck.j2me.services.messagingService.MessagingTestSuiteService;import com.sun.tck.j2me.services.passiveAgentService.PassiveAgentTestSuiteService;import com.sun.tck.j2me.utils.Utils;import com.sun.tck.j2me.services.LifeCycleAwareManager;/** * This is an extension to CldcTCKBaseTestSuite, that provides * additional services needed by distributed tests framework (DTF). It * reads DTF-related environment entries, creates a list of needed JAR * files, checks that all the JAR files exist, and controls various * services needed by DTF. * <p> * The distributed tests support can be enabled or disabled either * programmatically, by overriding {@link #shouldEnableDistrTests()}, * or declaratively in the <code>testsuite.jtt</code> file, see * {@link #init(String[])} and {@link #shouldEnableDistrTests()} for * more details. * <p> * By default, the distributed tests support is enabled, for * compatibility reasons. * * @see #DTF_SUPPORT * @see #init(String[]) * @see #shouldEnableDistrTests() */public class DistributedTestSuite extends ExportTestSuite {    class ExtraServices extends TestSuiteService {        public ExtraServices(Harness harness) {            super(harness);        }                public synchronized final void start() throws ServiceFault {            try {                startExtraServices(getHarness());            } catch (TestSuite.Fault fault) {                log.fine(fault.getMessage());                throw new TestSuiteServiceFault(i18n, "ts.errorStart", fault);            }        }                public synchronized final void stop() {            stopExtraServices();        }    };    /**     * Compatibility wrapper around the standard passive agent service.     * Provides compatibility behavior so that test suites that used to     * override start/stopPassiveAgent methods will continue to work as     * expected. For example, if some test suite used to override     * startPassiveAgent() in order to disable the passive agent altogether,     * the behavior should be preserved once the test suite is migrated     * to newer Framework.     */    private class CompatibilityPassiveAgentService            implements LifeCycleAware {        private PassiveAgentTestSuiteService baseService;        private Harness harness;        CompatibilityPassiveAgentService(Harness harness,                PassiveAgentTestSuiteService baseService) {            this.harness = harness;            this.baseService = baseService;        }        public void start() throws ServiceFault {            try {                useStandardPassiveAgent = false;                // Intentional side-effect here,                // the method might change useStandardPassiveAgent flag                startPassiveAgent(harness);                if (useStandardPassiveAgent) {                    baseService.start();                }            } catch (Fault e) {                throw new ServiceFault(                        "Cannot start passive agent: "                        + e.getMessage());            }        }        public void stop() throws ServiceFault {            stopPassiveAgent();            if (useStandardPassiveAgent) {                baseService.stop();            }        }    }    /**     * Name of JavaTest environment variable which designate the path of jar file     * of CommService client     */        public static final String COMMSERVICE_CLIENT_JAR = "commService.client.jar";    /**     * Name of JavaTest environment variable which designate the path to      * j2me_communication.jar     */    public static final String COMMSERVICE_J2ME_JAR = "commService.j2me.jar";    /**     * Name of JavaTest environment variable which designate the path to      * j2me_messaging.jar     */    public static final String MSGSERVICE_J2ME_JAR = "msgService.j2me.jar";    private boolean export = false;    private static String[] distrTestExtraJars;    private static final I18NResourceBundle i18n =         I18NResourceBundle.getBundleForClass(DistributedTestSuite.class);    private static final Logger log = Logger.getLogger(            DistributedTestSuite.class.getName());        /**     * Creates a TestSuite object.     * @param root The root file for this test suite.     * @param tsInfo Test suite properties, typically read from the test suite properties file     * @param cl A class loader to be used to load additional classes as required     * @throws TestSuite.Fault if a problem occurs while creating this test suite.     */    public DistributedTestSuite(File root, Map tsInfo, ClassLoader cl)            throws Fault {        super(root, tsInfo, cl);        setEnablePassiveAgent(true);    }        private static String getJarNameFromEnv(TestEnvironment env, String key) throws Fault {        try {            return Utils.getJarNameFromEnv(env, key);        } catch (TestEnvironment.Fault fault) {            throw new Fault(i18n, "dts.lookupError", key);        } catch (IllegalArgumentException e) {            throw new Fault(i18n, "dts.cannotReadFile", e.getMessage());        } catch (NullPointerException e) {            throw new Fault(i18n, "dts.jarUndefined", key);        }    }            /**     * This test suite understands a single parameter     * {@link #DTF_SUPPORT}. The parameter controls whether the     * distributed tests support is enabled or disabled. Set it to     * <code>true</code> to enable the distributed tests support or     * set it to <code>false</code> to disable the support.     * <p>     * Note: The args are typically read from a     * <code>testsuite.jtt</code> file, <code>testsuite</code> entry.     *     * @see #DTF_SUPPORT     * @see #shouldEnableDistrTests()     */    protected void init(String[] args) throws Fault {        if (args == null || args.length != 1 || args[0] == null) {            // report error            super.init(args);            return;        }        String singleArg = args[0];        assert singleArg != null;        if (singleArg.startsWith(DTF_SUPPORT)                && singleArg.length() > DTF_SUPPORT.length()) {            enableDTF = Boolean.getBoolean(                    singleArg.substring(DTF_SUPPORT.length()));

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?