You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2005/08/12 17:23:08 UTC
svn commit: r232310 [69/92] - in /beehive/trunk/controls/test: common/
infra/gtlf/ infra/gtlf/xsl/ infra/mantis/ infra/tch/ infra/tch/messages/
infra/tch/runtime/ infra/tch/schema/ perf/ perf/bin/ perf/cases/
perf/ctlsrc/org/apache/beehive/controls/per...
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/JUnitRunner.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/JUnitRunner.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/JUnitRunner.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/JUnitRunner.java Fri Aug 12 08:12:28 2005
@@ -1,327 +1,327 @@
-package org.apache.beehive.test.tools.tch.extension.exectask.junit;
-
-import java.lang.reflect.Constructor;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Iterator;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestResult;
-import junit.framework.TestSuite;
-import junit.runner.BaseTestRunner;
-import junit.runner.TestRunListener;
-import org.apache.beehive.test.tools.tch.compose.TestAbortedException;
-import org.apache.beehive.test.tools.tch.extension.exectask.common.ResultLogger;
-
-/**
- */
-public class JUnitRunner extends BaseTestRunner
-{
- // These error messages should move into tch-error-messages.xml
- private static final String ASSIGNABLE_FROM_ERROR_MESSAGE =
- "Test must inherit from junit.framework.TestCase or TestSuite if you use "
- + "the optional method name argument";
- private static final String NO_CONS_ERROR_MESSAGE =
- "Test class must override String argument constructor from TestCase";
-
- // if methodnames attr is set, we make sure those methods exist
- // enabled by default
- private boolean validateTestMethodNames = true;
-
- // if an exception is thrown out of the junit test,
- // and its not a junit assertion failure, then we
- // log an ABORT for it, by default
- private boolean treatAllBadResultsAsFailure = false;
-
- private String runFailedMessage = null;
-
- private Test test = null;
- private ResultLogger logger = null;
- private Throwable filterThrowable = null;
-
- private Collection failedTests = null;
-
- public JUnitRunner(
- String inClassName,
- Collection inMethods,
- ResultLogger inLogger)
- {
- this(inClassName, inMethods, inLogger, true, false);
- }
-
- public JUnitRunner(
- String inClassName,
- Collection inMethods,
- ResultLogger inLogger,
- boolean inValidateTestMethodNames,
- boolean inTreatAllBadResultsAsFailure)
- {
- validateTestMethodNames = inValidateTestMethodNames;
- treatAllBadResultsAsFailure = inTreatAllBadResultsAsFailure;
- logger = inLogger;
- test = getJunitTest(inClassName, inMethods);
- }
-
- public void run()
- {
- TestResult jTestResult = new TestResult();
- jTestResult.addListener(this);
- filterThrowable = new Exception();
-
- if (runFailedMessage != null)
- throw new NestedJUnitInitializationRuntimeException(runFailedMessage);
-
- test.run(jTestResult);
- }
-
- // Callback implementations, work with junit 3.8.1
- // ===================================================
-
- public void testStarted(String testName)
- {
- logger.begin(getTestCaseName(testName));
-
- // This is a temporary hack for knex testing
- // A nice solution would be a published
- // callback interface for test events
- // thanks
- System.setProperty("jwsv9", "false");
- }
-
- public void testEnded(String testName)
- {
- String testCaseName = getTestCaseName(testName);
- // if this test did not fail, log an explicit success
- if (!loggedFailureFor(testCaseName))
- {
- // flush the stream so we get everything that the test has written out
- System.out.flush();
- logger.success("", getTestCaseName(testName));
- }
- }
-
- public void testFailed(int status, Test test, Throwable t)
- {
- String testCaseName = getTestCaseName(test);
- storeFailedTestCaseName(testCaseName);
- // flush the stream so we get everything that the test has written out
- System.out.flush();
- if (TestAbortedException.class.isAssignableFrom(t.getClass())
- || (!treatAllBadResultsAsFailure && status == TestRunListener.STATUS_ERROR))
- {
- // we do not pass a summary message
- logger.abort("", testCaseName, t, filterThrowable);
- }
- else
- {
- // we do not pass a summary message
- logger.failure("", testCaseName, t, filterThrowable);
- }
- }
-
- protected void runFailed(String message)
- {
- runFailedMessage = message;
- }
-
- // End junit 3.8.1 callback impls.
- // ===================================================
- // Callback implementations, additions for junt 3.7
- // ===================================================
-
- public void addError(Test test, Throwable th)
- {
- testFailed(TestRunListener.STATUS_ERROR, test, th);
- }
-
- public void addFailure(Test test, AssertionFailedError err)
- {
- testFailed(TestRunListener.STATUS_FAILURE, test, err);
- }
-
- public void endTest(Test test)
- {
- testEnded(test.toString());
- }
-
- public void startTest(Test test)
- {
- testStarted(test.toString());
- }
-
- // End junit 3.7 impls.
- // ===================================================
-
- public Collection getSubtestNames()
- {
- return getSubtestNames(test);
- }
-
- private Collection getSubtestNames(Test inTest)
- {
- Collection rtn = new ArrayList();
- if (TestSuite.class.isAssignableFrom(inTest.getClass()))
- {
- Enumeration e = ((TestSuite)inTest).tests();
- while (e.hasMoreElements())
- {
- //recusion. either this is a suite, or a test case.
- rtn.addAll(getSubtestNames((Test)e.nextElement()));
- }
- }
- else if (TestCase.class.isAssignableFrom(inTest.getClass()))
- {
- rtn.add(((TestCase)inTest).getName());
- }
- else
- {
- throw new NestedJUnitInitializationRuntimeException(
- "Could not determine test case names for " + inTest.toString());
- }
- return rtn;
- }
-
- public boolean hasProblem()
- {
- return getRunFailedMessage() != null;
- }
-
- public String getRunFailedMessage()
- {
- return runFailedMessage;
- }
-
- /* This is important - not setting this to false expilcitly
- * will cause Junit to create a new classloader instance for
- * every class it loads, causing a OOM sooner or later.
- *
- * @see junit.runner.BaseTestRunner#useReloadingTestSuiteLoader()
- */
- protected boolean useReloadingTestSuiteLoader()
- {
- return false;
- }
-
- private void storeFailedTestCaseName(String testCaseName)
- {
- getFailedTests().add(testCaseName);
- }
-
- private boolean loggedFailureFor(String testCaseName)
- {
- return getFailedTests().contains(testCaseName);
- }
-
- private String getTestCaseName(Test test)
- {
- return getTestCaseName(test.toString());
- }
-
- private Test getJunitTest(String testClassName, Collection testMethodNames)
- {
- if (testMethodNames == null || testMethodNames.isEmpty())
- return getTest(testClassName);
- Class testClass = null;
- try
- {
- testClass = loadSuiteClass(testClassName);
- }
- catch (Exception ex)
- {
- throw new NestedJUnitInitializationRuntimeException(ex);
- } // If the methodName has been specified, the test must inherit
- // from TestCase since we are expecting to use the TestCase(String)
- // constructor to load the correct test for us.
- if (!TestCase.class.isAssignableFrom(testClass)
- && !TestSuite.class.isAssignableFrom(testClass))
- {
- throw new NestedJUnitInitializationRuntimeException(ASSIGNABLE_FROM_ERROR_MESSAGE);
- }
-
- TestSuite suite = new TestSuite();
- // get the TestCase(String) constructor
- Class[] parameterTypes = new Class[1];
- parameterTypes[0] = String.class;
- Constructor cons = null;
- try
- {
- cons = testClass.getConstructor(parameterTypes);
- }
- catch (NoSuchMethodException ex)
- {
- throw new NestedJUnitInitializationRuntimeException(
- ex,
- NO_CONS_ERROR_MESSAGE);
- }
-
- if (validateTestMethodNames)
- {
- // this will throw an exception if any of the specified
- // methods do not exist
- checkTestMethodsExist(testClass, testMethodNames);
- }
-
- Object[] parameterObjs = new Object[1];
- for (Iterator iter = testMethodNames.iterator(); iter.hasNext();)
- {
- parameterObjs[0] = iter.next();
- try
- {
- Test t = (Test)cons.newInstance(parameterObjs);
- suite.addTest(t);
- }
- catch (Exception ex)
- {
- throw new NestedJUnitInitializationRuntimeException(
- ex,
- "Unable to instantiate test class");
- }
- }
- return suite;
- }
-
- // ugly string hacking for now, can we get this from JUnit?
- // or just use reflection?
- private String getTestCaseName(String fullTestName)
- {
- int parenIndex = fullTestName.indexOf('(');
- return fullTestName.substring(0, parenIndex);
- }
-
- private void checkTestMethodsExist(
- Class testClass,
- Collection testMethodNames)
- {
- Collection methodsNotFound = new HashSet();
- for (Iterator iter = testMethodNames.iterator(); iter.hasNext();)
- {
- String methodName = (String)iter.next();
- // make sure that method actually exists
- try
- {
- testClass.getMethod(methodName, null);
- }
- catch (NoSuchMethodException ex)
- {
- methodsNotFound.add(methodName);
- }
- }
- if (!methodsNotFound.isEmpty())
- {
- throw new NestedJUnitInitializationRuntimeException(
- "Could not find test method(s): " + methodsNotFound);
- }
- }
-
- //lazy instantiation
- private synchronized Collection getFailedTests()
- {
- if (failedTests == null)
- failedTests = new HashSet();
- return failedTests;
- }
-}
+package org.apache.beehive.test.tools.tch.extension.exectask.junit;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestResult;
+import junit.framework.TestSuite;
+import junit.runner.BaseTestRunner;
+import junit.runner.TestRunListener;
+import org.apache.beehive.test.tools.tch.compose.TestAbortedException;
+import org.apache.beehive.test.tools.tch.extension.exectask.common.ResultLogger;
+
+/**
+ */
+public class JUnitRunner extends BaseTestRunner
+{
+ // These error messages should move into tch-error-messages.xml
+ private static final String ASSIGNABLE_FROM_ERROR_MESSAGE =
+ "Test must inherit from junit.framework.TestCase or TestSuite if you use "
+ + "the optional method name argument";
+ private static final String NO_CONS_ERROR_MESSAGE =
+ "Test class must override String argument constructor from TestCase";
+
+ // if methodnames attr is set, we make sure those methods exist
+ // enabled by default
+ private boolean validateTestMethodNames = true;
+
+ // if an exception is thrown out of the junit test,
+ // and its not a junit assertion failure, then we
+ // log an ABORT for it, by default
+ private boolean treatAllBadResultsAsFailure = false;
+
+ private String runFailedMessage = null;
+
+ private Test test = null;
+ private ResultLogger logger = null;
+ private Throwable filterThrowable = null;
+
+ private Collection failedTests = null;
+
+ public JUnitRunner(
+ String inClassName,
+ Collection inMethods,
+ ResultLogger inLogger)
+ {
+ this(inClassName, inMethods, inLogger, true, false);
+ }
+
+ public JUnitRunner(
+ String inClassName,
+ Collection inMethods,
+ ResultLogger inLogger,
+ boolean inValidateTestMethodNames,
+ boolean inTreatAllBadResultsAsFailure)
+ {
+ validateTestMethodNames = inValidateTestMethodNames;
+ treatAllBadResultsAsFailure = inTreatAllBadResultsAsFailure;
+ logger = inLogger;
+ test = getJunitTest(inClassName, inMethods);
+ }
+
+ public void run()
+ {
+ TestResult jTestResult = new TestResult();
+ jTestResult.addListener(this);
+ filterThrowable = new Exception();
+
+ if (runFailedMessage != null)
+ throw new NestedJUnitInitializationRuntimeException(runFailedMessage);
+
+ test.run(jTestResult);
+ }
+
+ // Callback implementations, work with junit 3.8.1
+ // ===================================================
+
+ public void testStarted(String testName)
+ {
+ logger.begin(getTestCaseName(testName));
+
+ // This is a temporary hack for knex testing
+ // A nice solution would be a published
+ // callback interface for test events
+ // thanks
+ System.setProperty("jwsv9", "false");
+ }
+
+ public void testEnded(String testName)
+ {
+ String testCaseName = getTestCaseName(testName);
+ // if this test did not fail, log an explicit success
+ if (!loggedFailureFor(testCaseName))
+ {
+ // flush the stream so we get everything that the test has written out
+ System.out.flush();
+ logger.success("", getTestCaseName(testName));
+ }
+ }
+
+ public void testFailed(int status, Test test, Throwable t)
+ {
+ String testCaseName = getTestCaseName(test);
+ storeFailedTestCaseName(testCaseName);
+ // flush the stream so we get everything that the test has written out
+ System.out.flush();
+ if (TestAbortedException.class.isAssignableFrom(t.getClass())
+ || (!treatAllBadResultsAsFailure && status == TestRunListener.STATUS_ERROR))
+ {
+ // we do not pass a summary message
+ logger.abort("", testCaseName, t, filterThrowable);
+ }
+ else
+ {
+ // we do not pass a summary message
+ logger.failure("", testCaseName, t, filterThrowable);
+ }
+ }
+
+ protected void runFailed(String message)
+ {
+ runFailedMessage = message;
+ }
+
+ // End junit 3.8.1 callback impls.
+ // ===================================================
+ // Callback implementations, additions for junt 3.7
+ // ===================================================
+
+ public void addError(Test test, Throwable th)
+ {
+ testFailed(TestRunListener.STATUS_ERROR, test, th);
+ }
+
+ public void addFailure(Test test, AssertionFailedError err)
+ {
+ testFailed(TestRunListener.STATUS_FAILURE, test, err);
+ }
+
+ public void endTest(Test test)
+ {
+ testEnded(test.toString());
+ }
+
+ public void startTest(Test test)
+ {
+ testStarted(test.toString());
+ }
+
+ // End junit 3.7 impls.
+ // ===================================================
+
+ public Collection getSubtestNames()
+ {
+ return getSubtestNames(test);
+ }
+
+ private Collection getSubtestNames(Test inTest)
+ {
+ Collection rtn = new ArrayList();
+ if (TestSuite.class.isAssignableFrom(inTest.getClass()))
+ {
+ Enumeration e = ((TestSuite)inTest).tests();
+ while (e.hasMoreElements())
+ {
+ //recusion. either this is a suite, or a test case.
+ rtn.addAll(getSubtestNames((Test)e.nextElement()));
+ }
+ }
+ else if (TestCase.class.isAssignableFrom(inTest.getClass()))
+ {
+ rtn.add(((TestCase)inTest).getName());
+ }
+ else
+ {
+ throw new NestedJUnitInitializationRuntimeException(
+ "Could not determine test case names for " + inTest.toString());
+ }
+ return rtn;
+ }
+
+ public boolean hasProblem()
+ {
+ return getRunFailedMessage() != null;
+ }
+
+ public String getRunFailedMessage()
+ {
+ return runFailedMessage;
+ }
+
+ /* This is important - not setting this to false expilcitly
+ * will cause Junit to create a new classloader instance for
+ * every class it loads, causing a OOM sooner or later.
+ *
+ * @see junit.runner.BaseTestRunner#useReloadingTestSuiteLoader()
+ */
+ protected boolean useReloadingTestSuiteLoader()
+ {
+ return false;
+ }
+
+ private void storeFailedTestCaseName(String testCaseName)
+ {
+ getFailedTests().add(testCaseName);
+ }
+
+ private boolean loggedFailureFor(String testCaseName)
+ {
+ return getFailedTests().contains(testCaseName);
+ }
+
+ private String getTestCaseName(Test test)
+ {
+ return getTestCaseName(test.toString());
+ }
+
+ private Test getJunitTest(String testClassName, Collection testMethodNames)
+ {
+ if (testMethodNames == null || testMethodNames.isEmpty())
+ return getTest(testClassName);
+ Class testClass = null;
+ try
+ {
+ testClass = loadSuiteClass(testClassName);
+ }
+ catch (Exception ex)
+ {
+ throw new NestedJUnitInitializationRuntimeException(ex);
+ } // If the methodName has been specified, the test must inherit
+ // from TestCase since we are expecting to use the TestCase(String)
+ // constructor to load the correct test for us.
+ if (!TestCase.class.isAssignableFrom(testClass)
+ && !TestSuite.class.isAssignableFrom(testClass))
+ {
+ throw new NestedJUnitInitializationRuntimeException(ASSIGNABLE_FROM_ERROR_MESSAGE);
+ }
+
+ TestSuite suite = new TestSuite();
+ // get the TestCase(String) constructor
+ Class[] parameterTypes = new Class[1];
+ parameterTypes[0] = String.class;
+ Constructor cons = null;
+ try
+ {
+ cons = testClass.getConstructor(parameterTypes);
+ }
+ catch (NoSuchMethodException ex)
+ {
+ throw new NestedJUnitInitializationRuntimeException(
+ ex,
+ NO_CONS_ERROR_MESSAGE);
+ }
+
+ if (validateTestMethodNames)
+ {
+ // this will throw an exception if any of the specified
+ // methods do not exist
+ checkTestMethodsExist(testClass, testMethodNames);
+ }
+
+ Object[] parameterObjs = new Object[1];
+ for (Iterator iter = testMethodNames.iterator(); iter.hasNext();)
+ {
+ parameterObjs[0] = iter.next();
+ try
+ {
+ Test t = (Test)cons.newInstance(parameterObjs);
+ suite.addTest(t);
+ }
+ catch (Exception ex)
+ {
+ throw new NestedJUnitInitializationRuntimeException(
+ ex,
+ "Unable to instantiate test class");
+ }
+ }
+ return suite;
+ }
+
+ // ugly string hacking for now, can we get this from JUnit?
+ // or just use reflection?
+ private String getTestCaseName(String fullTestName)
+ {
+ int parenIndex = fullTestName.indexOf('(');
+ return fullTestName.substring(0, parenIndex);
+ }
+
+ private void checkTestMethodsExist(
+ Class testClass,
+ Collection testMethodNames)
+ {
+ Collection methodsNotFound = new HashSet();
+ for (Iterator iter = testMethodNames.iterator(); iter.hasNext();)
+ {
+ String methodName = (String)iter.next();
+ // make sure that method actually exists
+ try
+ {
+ testClass.getMethod(methodName, null);
+ }
+ catch (NoSuchMethodException ex)
+ {
+ methodsNotFound.add(methodName);
+ }
+ }
+ if (!methodsNotFound.isEmpty())
+ {
+ throw new NestedJUnitInitializationRuntimeException(
+ "Could not find test method(s): " + methodsNotFound);
+ }
+ }
+
+ //lazy instantiation
+ private synchronized Collection getFailedTests()
+ {
+ if (failedTests == null)
+ failedTests = new HashSet();
+ return failedTests;
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/JUnitRunner.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/JunitExecTask.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/JunitExecTask.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/JunitExecTask.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/JunitExecTask.java Fri Aug 12 08:12:28 2005
@@ -1,234 +1,234 @@
-package org.apache.beehive.test.tools.tch.extension.exectask.junit;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.apache.beehive.test.tools.tch.core.AbstractExecutionTask;
-import org.apache.beehive.test.tools.tch.core.AntProperties;
-import org.apache.beehive.test.tools.tch.core.ExecutionTaskValidationException;
-import org.apache.beehive.test.tools.tch.core.test.TestLogicTask;
-import org.apache.beehive.test.tools.tch.util.TchUtils;
-
-/**
- * Uses JUnitRunner to run a junit test.
- **/
-public class JunitExecTask extends AbstractExecutionTask
-{
- private static String ERROR_MESSAGE = "Could not instantiate junit test ",
- DELIMITER = ",",
- TEST_METHOD_PREFIX = "test",
- SUITE_METHOD_NAME = "suite";
-
- private String testClassName = null;
- private String methodNamesAttribute = null;
-
- // what we get after splitting up the methodNamesAttribute
- private Collection parsedMethodNames = null;
-
- // attribute setters
- public void setTestClass(String in)
- {
- testClassName = handleValue(in);
- }
-
- public void setMethodNames(String in)
- {
- methodNamesAttribute = handleValue(in);
- }
-
- // the testcase name only goes into the GTLF file
- // for now it will be class.method, as usual
- // not sure why we actually still care about it
- public String getTestCaseName()
- {
- int dotIndex = getTestClassName().lastIndexOf(".") + 1;
- return getTestClassName().substring(dotIndex);
- }
-
- public Collection getAllSubtestNames()
- {
- // if methodnames attribute is set, just return that
- if (methodNamesSet())
- return parseMethodNames();
-
- // if we don't have a "public static Test suite()" method
- // junit will give us all public void methods that start with test
- // just use reflection to figure out the names
- try
- {
- Class testClass =
- Class.forName(
- getTestClassName(),
- true,
- Thread.currentThread().getContextClassLoader());
- if (!hasStaticTestMethod(testClass))
- {
- return getTestMethodNames(testClass);
- }
- }
- catch (ClassNotFoundException ex)
- {
- // ignore, this is being handled by validate()
- }
-
- // else get names from JunitRunner (need to invoke suite() method)
- JUnitRunner runner = null;
- try
- {
- runner = getLocalJUnitRunner();
- }
- catch (Throwable th)
- {
- // ignore, if it happens, will be handled by validate
- }
- if (runner == null || runner.hasProblem())
- return null;
-
- return runner.getSubtestNames();
- }
-
- public void validate() throws ExecutionTaskValidationException
- {
- // running the commented out code causes
- // junit to instantiate the test class
- // but we'd like to avoid running the constructor
- // at init time since some people have some setup code there
- //JUnitRunner runner = getLocalJUnitRunner();
- //if (runner.hasProblem())
- // throw new ExecutionTaskValidationException(
- // ERROR_MESSAGE + runner.getRunFailedMessage());
-
- // instead, just check we can do a class.forName
-
- if (AntProperties.isJunitValidateClassEnabled())
- {
- try
- {
- Class.forName(
- getTestClassName(),
- true,
- Thread.currentThread().getContextClassLoader());
- }
- catch (Throwable th)
- {
- throw new ExecutionTaskValidationException(
- th,
- ERROR_MESSAGE + "Class.forName failed");
- }
- }
- }
-
- public TestLogicTask getTestLogicTask()
- {
- return new JunitTestLogicTask(
- getTestClassName(),
- getParameters(),
- getResultHandler(),
- getMethodNamesToRun(),
- AntProperties.isJunitValidateMethodNamesEnabled(),
- AntProperties.isJunitLogOnlyFailureEnabled());
- }
-
- /**
- * Returns the fully qualified junit test class name,
- * as specified in the test file.
- * @return String.
- */
- public String getTestClassName()
- {
- return testClassName;
- }
-
- /**
- * Returns the junit test methods to run, as specified
- * in the test file.
- * @return String, comma separated list
- * of methods to run
- */
- public String getMethodNames()
- {
- return methodNamesAttribute;
- }
-
- private boolean methodNamesSet()
- {
- return methodNamesAttribute != null;
- }
-
- private JUnitRunner getLocalJUnitRunner()
- {
- return new JUnitRunner(
- getTestClassName(),
- parseMethodNames(),
- null,
- AntProperties.isJunitValidateMethodNamesEnabled(),
- AntProperties.isJunitLogOnlyFailureEnabled());
- }
-
- private Collection getMethodNamesToRun()
- {
- if (forceSubtests())
- return getSubtestsConfiguredToRun();
- else
- return parseMethodNames();
- }
-
- private Collection parseMethodNames()
- {
- if (parsedMethodNames == null)
- {
- if (methodNamesSet())
- {
- parsedMethodNames = new ArrayList();
- TchUtils.parseStringToStrings(
- methodNamesAttribute,
- DELIMITER,
- parsedMethodNames);
- }
- }
- return parsedMethodNames;
- }
-
- /**
- * Returns a List of all the test method names in class.
- * (the public void testXXX methods)
- */
- private Collection getTestMethodNames(Class inClass)
- {
- try
- {
- Method[] methods = inClass.getMethods();
- Collection rtn = new ArrayList(methods.length);
- for (int i = 0; i < methods.length; i++)
- {
- Method m = methods[i];
- if ((m.getName().indexOf(TEST_METHOD_PREFIX) == 0)
- && (m.getParameterTypes().length == 0)
- && (m.getReturnType() == void.class))
- {
- rtn.add(methods[i].getName());
- }
- }
- return rtn;
- }
- catch (Exception ex)
- {
- return null;
- }
- }
-
- private boolean hasStaticTestMethod(Class inClass)
- {
- try
- {
- Method m = inClass.getMethod(SUITE_METHOD_NAME, null);
- return (Modifier.isStatic(m.getModifiers()));
- }
- catch (NoSuchMethodException ex)
- {
- return false;
- }
- }
-}
+package org.apache.beehive.test.tools.tch.extension.exectask.junit;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.beehive.test.tools.tch.core.AbstractExecutionTask;
+import org.apache.beehive.test.tools.tch.core.AntProperties;
+import org.apache.beehive.test.tools.tch.core.ExecutionTaskValidationException;
+import org.apache.beehive.test.tools.tch.core.test.TestLogicTask;
+import org.apache.beehive.test.tools.tch.util.TchUtils;
+
+/**
+ * Uses JUnitRunner to run a junit test.
+ **/
+public class JunitExecTask extends AbstractExecutionTask
+{
+ private static String ERROR_MESSAGE = "Could not instantiate junit test ",
+ DELIMITER = ",",
+ TEST_METHOD_PREFIX = "test",
+ SUITE_METHOD_NAME = "suite";
+
+ private String testClassName = null;
+ private String methodNamesAttribute = null;
+
+ // what we get after splitting up the methodNamesAttribute
+ private Collection parsedMethodNames = null;
+
+ // attribute setters
+ public void setTestClass(String in)
+ {
+ testClassName = handleValue(in);
+ }
+
+ public void setMethodNames(String in)
+ {
+ methodNamesAttribute = handleValue(in);
+ }
+
+ // the testcase name only goes into the GTLF file
+ // for now it will be class.method, as usual
+ // not sure why we actually still care about it
+ public String getTestCaseName()
+ {
+ int dotIndex = getTestClassName().lastIndexOf(".") + 1;
+ return getTestClassName().substring(dotIndex);
+ }
+
+ public Collection getAllSubtestNames()
+ {
+ // if methodnames attribute is set, just return that
+ if (methodNamesSet())
+ return parseMethodNames();
+
+ // if we don't have a "public static Test suite()" method
+ // junit will give us all public void methods that start with test
+ // just use reflection to figure out the names
+ try
+ {
+ Class testClass =
+ Class.forName(
+ getTestClassName(),
+ true,
+ Thread.currentThread().getContextClassLoader());
+ if (!hasStaticTestMethod(testClass))
+ {
+ return getTestMethodNames(testClass);
+ }
+ }
+ catch (ClassNotFoundException ex)
+ {
+ // ignore, this is being handled by validate()
+ }
+
+ // else get names from JunitRunner (need to invoke suite() method)
+ JUnitRunner runner = null;
+ try
+ {
+ runner = getLocalJUnitRunner();
+ }
+ catch (Throwable th)
+ {
+ // ignore, if it happens, will be handled by validate
+ }
+ if (runner == null || runner.hasProblem())
+ return null;
+
+ return runner.getSubtestNames();
+ }
+
+ public void validate() throws ExecutionTaskValidationException
+ {
+ // running the commented out code causes
+ // junit to instantiate the test class
+ // but we'd like to avoid running the constructor
+ // at init time since some people have some setup code there
+ //JUnitRunner runner = getLocalJUnitRunner();
+ //if (runner.hasProblem())
+ // throw new ExecutionTaskValidationException(
+ // ERROR_MESSAGE + runner.getRunFailedMessage());
+
+ // instead, just check we can do a class.forName
+
+ if (AntProperties.isJunitValidateClassEnabled())
+ {
+ try
+ {
+ Class.forName(
+ getTestClassName(),
+ true,
+ Thread.currentThread().getContextClassLoader());
+ }
+ catch (Throwable th)
+ {
+ throw new ExecutionTaskValidationException(
+ th,
+ ERROR_MESSAGE + "Class.forName failed");
+ }
+ }
+ }
+
+ public TestLogicTask getTestLogicTask()
+ {
+ return new JunitTestLogicTask(
+ getTestClassName(),
+ getParameters(),
+ getResultHandler(),
+ getMethodNamesToRun(),
+ AntProperties.isJunitValidateMethodNamesEnabled(),
+ AntProperties.isJunitLogOnlyFailureEnabled());
+ }
+
+ /**
+ * Returns the fully qualified junit test class name,
+ * as specified in the test file.
+ * @return String.
+ */
+ public String getTestClassName()
+ {
+ return testClassName;
+ }
+
+ /**
+ * Returns the junit test methods to run, as specified
+ * in the test file.
+ * @return String, comma separated list
+ * of methods to run
+ */
+ public String getMethodNames()
+ {
+ return methodNamesAttribute;
+ }
+
+ private boolean methodNamesSet()
+ {
+ return methodNamesAttribute != null;
+ }
+
+ private JUnitRunner getLocalJUnitRunner()
+ {
+ return new JUnitRunner(
+ getTestClassName(),
+ parseMethodNames(),
+ null,
+ AntProperties.isJunitValidateMethodNamesEnabled(),
+ AntProperties.isJunitLogOnlyFailureEnabled());
+ }
+
+ private Collection getMethodNamesToRun()
+ {
+ if (forceSubtests())
+ return getSubtestsConfiguredToRun();
+ else
+ return parseMethodNames();
+ }
+
+ private Collection parseMethodNames()
+ {
+ if (parsedMethodNames == null)
+ {
+ if (methodNamesSet())
+ {
+ parsedMethodNames = new ArrayList();
+ TchUtils.parseStringToStrings(
+ methodNamesAttribute,
+ DELIMITER,
+ parsedMethodNames);
+ }
+ }
+ return parsedMethodNames;
+ }
+
+ /**
+ * Returns a List of all the test method names in class.
+ * (the public void testXXX methods)
+ */
+ private Collection getTestMethodNames(Class inClass)
+ {
+ try
+ {
+ Method[] methods = inClass.getMethods();
+ Collection rtn = new ArrayList(methods.length);
+ for (int i = 0; i < methods.length; i++)
+ {
+ Method m = methods[i];
+ if ((m.getName().indexOf(TEST_METHOD_PREFIX) == 0)
+ && (m.getParameterTypes().length == 0)
+ && (m.getReturnType() == void.class))
+ {
+ rtn.add(methods[i].getName());
+ }
+ }
+ return rtn;
+ }
+ catch (Exception ex)
+ {
+ return null;
+ }
+ }
+
+ private boolean hasStaticTestMethod(Class inClass)
+ {
+ try
+ {
+ Method m = inClass.getMethod(SUITE_METHOD_NAME, null);
+ return (Modifier.isStatic(m.getModifiers()));
+ }
+ catch (NoSuchMethodException ex)
+ {
+ return false;
+ }
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/JunitExecTask.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/JunitTestLogicTask.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/JunitTestLogicTask.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/JunitTestLogicTask.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/JunitTestLogicTask.java Fri Aug 12 08:12:28 2005
@@ -1,107 +1,107 @@
-package org.apache.beehive.test.tools.tch.extension.exectask.junit;
-
-import java.io.ByteArrayOutputStream;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Properties;
-
-import org.apache.beehive.test.tools.tch.compose.Parameters;
-import org.apache.beehive.test.tools.tch.core.test.AbstractTestLogicTask;
-import org.apache.beehive.test.tools.tch.core.test.ResultHandler;
-import org.apache.beehive.test.tools.tch.extension.exectask.common.TestClassInfoResultHandler;
-import org.apache.beehive.test.tools.tch.task.TaskContext;
-import org.apache.beehive.test.tools.tch.util.io.CompositeOutputStream;
-
-/**
- */
-public class JunitTestLogicTask extends AbstractTestLogicTask
-{
- private String className = null;
- private Collection methods = null;
-
- private boolean modifiedSysProps = false;
- private boolean validateMethodNames = true;
- private boolean treatAllBadResultsAsFailure = false;
-
- private Properties testParameters = null;
-
- public JunitTestLogicTask(
- String inClassName,
- Parameters inParameters,
- ResultHandler inResultHandler,
- Collection inMethods,
- boolean inValidateMethodNames,
- boolean inTreatAllBadResultsAsFailure)
- {
- super("Junit Test Logic Task", inResultHandler);
- className = inClassName;
- methods = inMethods;
- testParameters = inParameters.getAll();
- validateMethodNames = inValidateMethodNames;
- treatAllBadResultsAsFailure = inTreatAllBadResultsAsFailure;
- }
-
- public TaskContext run(TaskContext in)
- {
- // save system properties, and add current test parameters
- addTestParameters();
-
- // decorate the result handler
- setResultHandler(
- new TestClassInfoResultHandler(getResultHandler(), className));
-
- // kick off the junit test(s)
- new JUnitRunner(
- className,
- methods,
- getResultLogger(),
- validateMethodNames,
- treatAllBadResultsAsFailure)
- .run();
-
- restoreSystemProps();
- return null;
- }
-
- private void restoreSystemProps()
- {
- if (modifiedSysProps)
- {
- for (Iterator iter = testParameters.keySet().iterator(); iter.hasNext();)
- {
- System.getProperties().remove(iter.next());
- }
- modifiedSysProps = false;
- }
- }
-
- public void notifyTimeout()
- {
- super.notifyTimeout();
- restoreSystemProps();
- }
-
- private void addTestParameters()
- {
- // if parallel tests have the same test parameter mapped,
- // but with a different value, this won't work
- // (will overwrite each other)
- if (!testParameters.isEmpty())
- {
- modifiedSysProps = true;
- System.getProperties().putAll(testParameters);
- }
- }
-
- public boolean isCanLogStdout()
- {
- return true;
- }
-
- public boolean isMustLogStdout()
- {
- return true;
- }
-}
+package org.apache.beehive.test.tools.tch.extension.exectask.junit;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Properties;
+
+import org.apache.beehive.test.tools.tch.compose.Parameters;
+import org.apache.beehive.test.tools.tch.core.test.AbstractTestLogicTask;
+import org.apache.beehive.test.tools.tch.core.test.ResultHandler;
+import org.apache.beehive.test.tools.tch.extension.exectask.common.TestClassInfoResultHandler;
+import org.apache.beehive.test.tools.tch.task.TaskContext;
+import org.apache.beehive.test.tools.tch.util.io.CompositeOutputStream;
+
+/**
+ */
+public class JunitTestLogicTask extends AbstractTestLogicTask
+{
+ private String className = null;
+ private Collection methods = null;
+
+ private boolean modifiedSysProps = false;
+ private boolean validateMethodNames = true;
+ private boolean treatAllBadResultsAsFailure = false;
+
+ private Properties testParameters = null;
+
+ public JunitTestLogicTask(
+ String inClassName,
+ Parameters inParameters,
+ ResultHandler inResultHandler,
+ Collection inMethods,
+ boolean inValidateMethodNames,
+ boolean inTreatAllBadResultsAsFailure)
+ {
+ super("Junit Test Logic Task", inResultHandler);
+ className = inClassName;
+ methods = inMethods;
+ testParameters = inParameters.getAll();
+ validateMethodNames = inValidateMethodNames;
+ treatAllBadResultsAsFailure = inTreatAllBadResultsAsFailure;
+ }
+
+ public TaskContext run(TaskContext in)
+ {
+ // save system properties, and add current test parameters
+ addTestParameters();
+
+ // decorate the result handler
+ setResultHandler(
+ new TestClassInfoResultHandler(getResultHandler(), className));
+
+ // kick off the junit test(s)
+ new JUnitRunner(
+ className,
+ methods,
+ getResultLogger(),
+ validateMethodNames,
+ treatAllBadResultsAsFailure)
+ .run();
+
+ restoreSystemProps();
+ return null;
+ }
+
+ private void restoreSystemProps()
+ {
+ if (modifiedSysProps)
+ {
+ for (Iterator iter = testParameters.keySet().iterator(); iter.hasNext();)
+ {
+ System.getProperties().remove(iter.next());
+ }
+ modifiedSysProps = false;
+ }
+ }
+
+ public void notifyTimeout()
+ {
+ super.notifyTimeout();
+ restoreSystemProps();
+ }
+
+ private void addTestParameters()
+ {
+ // if parallel tests have the same test parameter mapped,
+ // but with a different value, this won't work
+ // (will overwrite each other)
+ if (!testParameters.isEmpty())
+ {
+ modifiedSysProps = true;
+ System.getProperties().putAll(testParameters);
+ }
+ }
+
+ public boolean isCanLogStdout()
+ {
+ return true;
+ }
+
+ public boolean isMustLogStdout()
+ {
+ return true;
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/JunitTestLogicTask.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/NestedJUnitInitializationRuntimeException.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/NestedJUnitInitializationRuntimeException.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/NestedJUnitInitializationRuntimeException.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/NestedJUnitInitializationRuntimeException.java Fri Aug 12 08:12:28 2005
@@ -1,26 +1,26 @@
-package org.apache.beehive.test.tools.tch.extension.exectask.junit;
-
-import org.apache.beehive.test.tools.tch.util.NestedRuntimeException;
-
-/**
- */
-public class NestedJUnitInitializationRuntimeException
- extends NestedRuntimeException
-{
- public NestedJUnitInitializationRuntimeException(String message)
- {
- super(message);
- }
-
- public NestedJUnitInitializationRuntimeException(Throwable th)
- {
- super(th);
- }
-
- public NestedJUnitInitializationRuntimeException(
- Throwable th,
- String message)
- {
- super(th, message);
- }
-}
+package org.apache.beehive.test.tools.tch.extension.exectask.junit;
+
+import org.apache.beehive.test.tools.tch.util.NestedRuntimeException;
+
+/**
+ */
+public class NestedJUnitInitializationRuntimeException
+ extends NestedRuntimeException
+{
+ public NestedJUnitInitializationRuntimeException(String message)
+ {
+ super(message);
+ }
+
+ public NestedJUnitInitializationRuntimeException(Throwable th)
+ {
+ super(th);
+ }
+
+ public NestedJUnitInitializationRuntimeException(
+ Throwable th,
+ String message)
+ {
+ super(th, message);
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/NestedJUnitInitializationRuntimeException.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/OutputAddingResultHandler.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/OutputAddingResultHandler.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/OutputAddingResultHandler.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/OutputAddingResultHandler.java Fri Aug 12 08:12:28 2005
@@ -1,110 +1,110 @@
-package org.apache.beehive.test.tools.tch.extension.exectask.junit;
-
-import java.io.ByteArrayOutputStream;
-
-import org.apache.beehive.test.tools.tch.core.test.ResultHandler;
-import org.apache.beehive.test.tools.tch.util.TchConstants;
-import org.apache.beehive.test.tools.tch.util.GeneralUtil;
-import org.apache.beehive.test.tools.tch.util.TestResult;
-import org.apache.beehive.test.tools.tch.util.TestResultBean;
-
-/**
- * Decorator.
- *
- * This result handler adds the content of its ByteArrayOutputStream to the
- * "details" of all "outcome" results.
- * It also captures anything that has been written before the first BEGIN result,
- * (so this would be output from running the test class constructor)
- * and adds this to every test "detail", as "pre-test" output.
- *
- * So far this is only used to add anything that was written to standard out
- * during the test to the result object.
- *
- */
-public class OutputAddingResultHandler implements ResultHandler
-{
- private static final String sep = System.getProperty("line.separator");
-
- private static final String PRE_TEST_STDOUT_START_MESSAGE =
- "[Start pre-test stdout]";
-
- private static final String PRE_TEST_STDOUT_END_MESSAGE =
- "[End pre-test stdout]";
-
- private static final String TEST_STDOUT_START_MESSAGE = "[Start test stdout]";
-
- private static final String TEST_STDOUT_END_MESSAGE = "[End test stdout]";
-
- private ByteArrayOutputStream baos = null;
- private ResultHandler baseResultHandler = null;
-
- private String preTestOutput = null;
- private boolean encounteredBeginResult = false;
-
- public OutputAddingResultHandler(
- ResultHandler inResultHandler,
- ByteArrayOutputStream inBaos)
- {
- baos = inBaos;
- baseResultHandler = inResultHandler;
- }
-
- public void submitResult(TestResultBean tr)
- {
- addOutputAndReset(tr);
- baseResultHandler.submitResult(tr);
- }
-
- public void submitResult(TestResultBean tr, String resultName)
- {
- addOutputAndReset(tr);
- baseResultHandler.submitResult(tr, resultName);
- }
-
- private void addOutputAndReset(TestResultBean tr)
- {
- if (baos.size() == 0)
- return;
-
- if (isFirstBegin(tr))
- {
- preTestOutput = GeneralUtil.emptyStringOrNullToNull(baos.toString());
- baos.reset();
- }
- else if (tr.isOutcome())
- {
- StringBuffer stdout = new StringBuffer();
- if (preTestOutput != null)
- {
- stdout
- .append(PRE_TEST_STDOUT_START_MESSAGE)
- .append(sep)
- .append(preTestOutput)
- .append(sep)
- .append(PRE_TEST_STDOUT_END_MESSAGE)
- .append(sep);
- }
- stdout
- .append(sep)
- .append(TEST_STDOUT_START_MESSAGE)
- .append(sep)
- .append(baos.toString())
- .append(sep)
- .append(TEST_STDOUT_END_MESSAGE);
-
- tr.setDetails(stdout.toString());
- baos.reset();
- }
- }
-
- private boolean isFirstBegin(TestResult tr)
- {
- if (tr.getType() == TchConstants.BEGIN_LEVEL_INT
- && !encounteredBeginResult)
- {
- encounteredBeginResult = true;
- return true;
- }
- return false;
- }
-}
+package org.apache.beehive.test.tools.tch.extension.exectask.junit;
+
+import java.io.ByteArrayOutputStream;
+
+import org.apache.beehive.test.tools.tch.core.test.ResultHandler;
+import org.apache.beehive.test.tools.tch.util.TchConstants;
+import org.apache.beehive.test.tools.tch.util.GeneralUtil;
+import org.apache.beehive.test.tools.tch.util.TestResult;
+import org.apache.beehive.test.tools.tch.util.TestResultBean;
+
+/**
+ * Decorator.
+ *
+ * This result handler adds the content of its ByteArrayOutputStream to the
+ * "details" of all "outcome" results.
+ * It also captures anything that has been written before the first BEGIN result,
+ * (so this would be output from running the test class constructor)
+ * and adds this to every test "detail", as "pre-test" output.
+ *
+ * So far this is only used to add anything that was written to standard out
+ * during the test to the result object.
+ *
+ */
+public class OutputAddingResultHandler implements ResultHandler
+{
+ private static final String sep = System.getProperty("line.separator");
+
+ private static final String PRE_TEST_STDOUT_START_MESSAGE =
+ "[Start pre-test stdout]";
+
+ private static final String PRE_TEST_STDOUT_END_MESSAGE =
+ "[End pre-test stdout]";
+
+ private static final String TEST_STDOUT_START_MESSAGE = "[Start test stdout]";
+
+ private static final String TEST_STDOUT_END_MESSAGE = "[End test stdout]";
+
+ private ByteArrayOutputStream baos = null;
+ private ResultHandler baseResultHandler = null;
+
+ private String preTestOutput = null;
+ private boolean encounteredBeginResult = false;
+
+ public OutputAddingResultHandler(
+ ResultHandler inResultHandler,
+ ByteArrayOutputStream inBaos)
+ {
+ baos = inBaos;
+ baseResultHandler = inResultHandler;
+ }
+
+ public void submitResult(TestResultBean tr)
+ {
+ addOutputAndReset(tr);
+ baseResultHandler.submitResult(tr);
+ }
+
+ public void submitResult(TestResultBean tr, String resultName)
+ {
+ addOutputAndReset(tr);
+ baseResultHandler.submitResult(tr, resultName);
+ }
+
+ private void addOutputAndReset(TestResultBean tr)
+ {
+ if (baos.size() == 0)
+ return;
+
+ if (isFirstBegin(tr))
+ {
+ preTestOutput = GeneralUtil.emptyStringOrNullToNull(baos.toString());
+ baos.reset();
+ }
+ else if (tr.isOutcome())
+ {
+ StringBuffer stdout = new StringBuffer();
+ if (preTestOutput != null)
+ {
+ stdout
+ .append(PRE_TEST_STDOUT_START_MESSAGE)
+ .append(sep)
+ .append(preTestOutput)
+ .append(sep)
+ .append(PRE_TEST_STDOUT_END_MESSAGE)
+ .append(sep);
+ }
+ stdout
+ .append(sep)
+ .append(TEST_STDOUT_START_MESSAGE)
+ .append(sep)
+ .append(baos.toString())
+ .append(sep)
+ .append(TEST_STDOUT_END_MESSAGE);
+
+ tr.setDetails(stdout.toString());
+ baos.reset();
+ }
+ }
+
+ private boolean isFirstBegin(TestResult tr)
+ {
+ if (tr.getType() == TchConstants.BEGIN_LEVEL_INT
+ && !encounteredBeginResult)
+ {
+ encounteredBeginResult = true;
+ return true;
+ }
+ return false;
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/junit/OutputAddingResultHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/self/TchExecTask.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/self/TchExecTask.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/self/TchExecTask.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/self/TchExecTask.java Fri Aug 12 08:12:28 2005
@@ -1,249 +1,249 @@
-package org.apache.beehive.test.tools.tch.extension.exectask.self;
-
-import java.io.File;
-
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.taskdefs.Property;
-import org.apache.tools.ant.types.Commandline;
-import org.apache.tools.ant.types.Path;
-
-import org.apache.beehive.test.tools.tch.TchVMTask;
-import org.apache.beehive.test.tools.tch.api.CommandLineRunner;
-import org.apache.beehive.test.tools.tch.core.AbstractExecutionTask;
-import org.apache.beehive.test.tools.tch.core.AntProperties;
-import org.apache.beehive.test.tools.tch.core.ExecutionTaskValidationException;
-import org.apache.beehive.test.tools.tch.core.PropertyNames;
-import org.apache.beehive.test.tools.tch.core.test.AbstractTestLogicTask;
-import org.apache.beehive.test.tools.tch.core.test.ResultHandler;
-import org.apache.beehive.test.tools.tch.core.test.TestLogicTask;
-import org.apache.beehive.test.tools.tch.task.TaskContext;
-import org.apache.beehive.test.tools.tch.util.AntUtils;
-import org.apache.beehive.test.tools.tch.util.TchUtils;
-import org.apache.beehive.test.tools.tch.util.env.EnvVarResolutionException;
-import org.apache.beehive.test.tools.tch.util.env.Environment;
-
-/**
- */
-public class TchExecTask extends AbstractExecutionTask
-{
- private static final String CLF_EXTENSION = ".clf",
- DEFAULT_BASE_FILE = "base" + CLF_EXTENSION,
- DEFAULT_PROPS_FILE = "props",
- DEFAULT_BASE_LOG_NAME = "testlog";
-
- // the name of the props file to use
- private String propsFileName = DEFAULT_PROPS_FILE;
-
- // the name of the base .clf file to compare to
- private String baseFileName = DEFAULT_BASE_FILE;
-
- // the log base file names
- private String baseLogName = DEFAULT_BASE_LOG_NAME;
-
- public void validate() throws ExecutionTaskValidationException
- {
- File base = new File(getTestDir(), getBaseFileName());
- if (!base.exists())
- throw new ExecutionTaskValidationException(
- "Cannot find base " + base.getAbsolutePath());
- }
-
- public void setBaseLogName(String in)
- {
- baseLogName = handleValue(in);
- }
-
- public void setPropsFile(String in)
- {
- propsFileName = handleValue(in);
- }
-
- public void setBaseFile(String in)
- {
- baseFileName = handleValue(in);
- }
-
- private String getPropsFileName()
- {
- return propsFileName;
- }
-
- private String getBaseFileName()
- {
- return baseFileName;
- }
-
- private String getBaseLogName()
- {
- return baseLogName;
- }
-
- public String getName()
- {
- return "tch-execution-task";
- }
-
- public TestLogicTask getTestLogicTask()
- {
- return new TchTestLogicTask(getResultHandler());
- }
-
- private class TchTestLogicTask extends AbstractTestLogicTask
- {
- public TchTestLogicTask(ResultHandler in)
- {
- super("tch-test-logic-task", in);
- }
-
- public TaskContext run(TaskContext inContext)
- {
- setup();
- Task tchTask = createTchTask();
- try
- {
- tchTask.perform();
- } catch (Throwable th)
- {
- logFailure("Failed to run tch", th);
- return null;
- }
-
- // now run the diff
- String diffOutput =
- diff(
- new File(getBaseFileName()),
- new File(getBaseLogName() + CLF_EXTENSION));
- if (diffOutput == null)
- logSuccess("Output matches " + getBaseFileName());
- else
- {
- File propsFile = new File(getTestDir(), getPropsFileName());
- logFailure(
- "Content of base \""
- + getBaseFileName()
- + "\" and \""
- + getBaseLogName()
- + CLF_EXTENSION
- + "\" did not match\n",
- "The props file is \""
- + propsFile.getName()
- + "\"\nIt contains:\n"
- + TchUtils.getContentsAsString(propsFile)
- + "\nDiff is:\n\n"
- + diffOutput);
- }
- return null;
- }
-
- private void setup()
- {
- // if there's an old .clf file hanging around, delete it
- File f = new File(getBaseLogName() + CLF_EXTENSION);
- if (f.exists())
- {
- logDebug("Removing old " + CLF_EXTENSION + " file: " + f.getName());
- f.delete();
- }
- }
-
- private Task createTchTask()
- {
- TchVMTask task = new TchVMTask();
- // for now
- AntUtils.cloneTaskData(getParentTask(), task);
- String home = AntProperties.getHomeDir();
- logDebug("tch.home is " + home);
- task.setTchHome(home);
- task.setTaskName("tch");
- task.setFork(true);
-
- // use same classpath as this vm
- // this will require re-generating all base files
- // Path classpath = new Path(getProject(), System.getProperty("java.class.path"));
- // task.setClasspath(classpath);
-
- // set base log name
- addTchProperty(
- task,
- PropertyNames.TCH_LOG_NAME_PROPERTY,
- getBaseLogName());
- // disable GTLF logging
- addTchProperty(
- task,
- PropertyNames.TCH_LOG_GTLF_PROPERTY,
- "false");
- // disable debug-all logging
- addTchProperty(
- task,
- PropertyNames.TCH_LOG_VERBOSE_DEBUG_PROPERTY,
- "false");
- // disable stdout logging
- addTchProperty(
- task,
- PropertyNames.TCH_LOG_TO_STDOUT_PROPERTY,
- "false");
- addTchProperty(
- task,
- PropertyNames.TCH_LOG_BANNERS_PROPERTY,
- "false");
- // disable ant file gen
- addTchProperty(task, PropertyNames.TCH_ANT_FILE_GEN, "false");
- // enable log comparison logger
- addTchProperty(
- task,
- PropertyNames.TCH_LOG_COMPARISON_PROPERTY,
- "true");
- // enbable prop val substitution
- addTchProperty(
- task,
- PropertyNames.TCH_PROP_VAL_SUBSTITUTION,
- "true");
- // run from directory the suite is in
- task.setDir(getTestDir());
-
- File absPathToProps = new File(getTestDir(), getPropsFileName());
- Commandline.Argument arg = task.createArg();
- arg.setLine("-propertyfile " + absPathToProps.getAbsolutePath());
- return task;
- }
-
- private void addTchProperty(
- TchVMTask task,
- String name,
- String value)
- {
- Property prop = task.createProperty();
- prop.setName(PropertyNames.TCH_PREFIX + name);
- prop.setValue(value);
- }
-
- private String diff(File f1, File f2)
- {
- String command = "diff " + f1 + " " + f2;
- logDebug(
- "running diff command "
- + command
- + " in "
- + getTestDir().getAbsolutePath());
- CommandLineRunner runner = new CommandLineRunner(command, getTestDir());
- runner.run();
- while (!runner.processTerminated())
- sleep(2);
- String processOutput = runner.getProcessOutput();
- if (processOutput.trim().length() == 0)
- return null;
- else
- return processOutput;
- }
-
- private void sleep(int numSeconds)
- {
- try
- {
- Thread.sleep(numSeconds * 1000);
- } catch (InterruptedException ex)
- {
- }
- }
- }
-}
+package org.apache.beehive.test.tools.tch.extension.exectask.self;
+
+import java.io.File;
+
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.Property;
+import org.apache.tools.ant.types.Commandline;
+import org.apache.tools.ant.types.Path;
+
+import org.apache.beehive.test.tools.tch.TchVMTask;
+import org.apache.beehive.test.tools.tch.api.CommandLineRunner;
+import org.apache.beehive.test.tools.tch.core.AbstractExecutionTask;
+import org.apache.beehive.test.tools.tch.core.AntProperties;
+import org.apache.beehive.test.tools.tch.core.ExecutionTaskValidationException;
+import org.apache.beehive.test.tools.tch.core.PropertyNames;
+import org.apache.beehive.test.tools.tch.core.test.AbstractTestLogicTask;
+import org.apache.beehive.test.tools.tch.core.test.ResultHandler;
+import org.apache.beehive.test.tools.tch.core.test.TestLogicTask;
+import org.apache.beehive.test.tools.tch.task.TaskContext;
+import org.apache.beehive.test.tools.tch.util.AntUtils;
+import org.apache.beehive.test.tools.tch.util.TchUtils;
+import org.apache.beehive.test.tools.tch.util.env.EnvVarResolutionException;
+import org.apache.beehive.test.tools.tch.util.env.Environment;
+
+/**
+ */
+public class TchExecTask extends AbstractExecutionTask
+{
+ private static final String CLF_EXTENSION = ".clf",
+ DEFAULT_BASE_FILE = "base" + CLF_EXTENSION,
+ DEFAULT_PROPS_FILE = "props",
+ DEFAULT_BASE_LOG_NAME = "testlog";
+
+ // the name of the props file to use
+ private String propsFileName = DEFAULT_PROPS_FILE;
+
+ // the name of the base .clf file to compare to
+ private String baseFileName = DEFAULT_BASE_FILE;
+
+ // the log base file names
+ private String baseLogName = DEFAULT_BASE_LOG_NAME;
+
+ public void validate() throws ExecutionTaskValidationException
+ {
+ File base = new File(getTestDir(), getBaseFileName());
+ if (!base.exists())
+ throw new ExecutionTaskValidationException(
+ "Cannot find base " + base.getAbsolutePath());
+ }
+
+ public void setBaseLogName(String in)
+ {
+ baseLogName = handleValue(in);
+ }
+
+ public void setPropsFile(String in)
+ {
+ propsFileName = handleValue(in);
+ }
+
+ public void setBaseFile(String in)
+ {
+ baseFileName = handleValue(in);
+ }
+
+ private String getPropsFileName()
+ {
+ return propsFileName;
+ }
+
+ private String getBaseFileName()
+ {
+ return baseFileName;
+ }
+
+ private String getBaseLogName()
+ {
+ return baseLogName;
+ }
+
+ public String getName()
+ {
+ return "tch-execution-task";
+ }
+
+ public TestLogicTask getTestLogicTask()
+ {
+ return new TchTestLogicTask(getResultHandler());
+ }
+
+ private class TchTestLogicTask extends AbstractTestLogicTask
+ {
+ public TchTestLogicTask(ResultHandler in)
+ {
+ super("tch-test-logic-task", in);
+ }
+
+ public TaskContext run(TaskContext inContext)
+ {
+ setup();
+ Task tchTask = createTchTask();
+ try
+ {
+ tchTask.perform();
+ } catch (Throwable th)
+ {
+ logFailure("Failed to run tch", th);
+ return null;
+ }
+
+ // now run the diff
+ String diffOutput =
+ diff(
+ new File(getBaseFileName()),
+ new File(getBaseLogName() + CLF_EXTENSION));
+ if (diffOutput == null)
+ logSuccess("Output matches " + getBaseFileName());
+ else
+ {
+ File propsFile = new File(getTestDir(), getPropsFileName());
+ logFailure(
+ "Content of base \""
+ + getBaseFileName()
+ + "\" and \""
+ + getBaseLogName()
+ + CLF_EXTENSION
+ + "\" did not match\n",
+ "The props file is \""
+ + propsFile.getName()
+ + "\"\nIt contains:\n"
+ + TchUtils.getContentsAsString(propsFile)
+ + "\nDiff is:\n\n"
+ + diffOutput);
+ }
+ return null;
+ }
+
+ private void setup()
+ {
+ // if there's an old .clf file hanging around, delete it
+ File f = new File(getBaseLogName() + CLF_EXTENSION);
+ if (f.exists())
+ {
+ logDebug("Removing old " + CLF_EXTENSION + " file: " + f.getName());
+ f.delete();
+ }
+ }
+
+ private Task createTchTask()
+ {
+ TchVMTask task = new TchVMTask();
+ // for now
+ AntUtils.cloneTaskData(getParentTask(), task);
+ String home = AntProperties.getHomeDir();
+ logDebug("tch.home is " + home);
+ task.setTchHome(home);
+ task.setTaskName("tch");
+ task.setFork(true);
+
+ // use same classpath as this vm
+ // this will require re-generating all base files
+ // Path classpath = new Path(getProject(), System.getProperty("java.class.path"));
+ // task.setClasspath(classpath);
+
+ // set base log name
+ addTchProperty(
+ task,
+ PropertyNames.TCH_LOG_NAME_PROPERTY,
+ getBaseLogName());
+ // disable GTLF logging
+ addTchProperty(
+ task,
+ PropertyNames.TCH_LOG_GTLF_PROPERTY,
+ "false");
+ // disable debug-all logging
+ addTchProperty(
+ task,
+ PropertyNames.TCH_LOG_VERBOSE_DEBUG_PROPERTY,
+ "false");
+ // disable stdout logging
+ addTchProperty(
+ task,
+ PropertyNames.TCH_LOG_TO_STDOUT_PROPERTY,
+ "false");
+ addTchProperty(
+ task,
+ PropertyNames.TCH_LOG_BANNERS_PROPERTY,
+ "false");
+ // disable ant file gen
+ addTchProperty(task, PropertyNames.TCH_ANT_FILE_GEN, "false");
+ // enable log comparison logger
+ addTchProperty(
+ task,
+ PropertyNames.TCH_LOG_COMPARISON_PROPERTY,
+ "true");
+ // enbable prop val substitution
+ addTchProperty(
+ task,
+ PropertyNames.TCH_PROP_VAL_SUBSTITUTION,
+ "true");
+ // run from directory the suite is in
+ task.setDir(getTestDir());
+
+ File absPathToProps = new File(getTestDir(), getPropsFileName());
+ Commandline.Argument arg = task.createArg();
+ arg.setLine("-propertyfile " + absPathToProps.getAbsolutePath());
+ return task;
+ }
+
+ private void addTchProperty(
+ TchVMTask task,
+ String name,
+ String value)
+ {
+ Property prop = task.createProperty();
+ prop.setName(PropertyNames.TCH_PREFIX + name);
+ prop.setValue(value);
+ }
+
+ private String diff(File f1, File f2)
+ {
+ String command = "diff " + f1 + " " + f2;
+ logDebug(
+ "running diff command "
+ + command
+ + " in "
+ + getTestDir().getAbsolutePath());
+ CommandLineRunner runner = new CommandLineRunner(command, getTestDir());
+ runner.run();
+ while (!runner.processTerminated())
+ sleep(2);
+ String processOutput = runner.getProcessOutput();
+ if (processOutput.trim().length() == 0)
+ return null;
+ else
+ return processOutput;
+ }
+
+ private void sleep(int numSeconds)
+ {
+ try
+ {
+ Thread.sleep(numSeconds * 1000);
+ } catch (InterruptedException ex)
+ {
+ }
+ }
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/self/TchExecTask.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/wstest/WSTestContext.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/wstest/WSTestContext.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/wstest/WSTestContext.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/wstest/WSTestContext.java Fri Aug 12 08:12:28 2005
@@ -1,20 +1,20 @@
-package org.apache.beehive.test.tools.tch.extension.exectask.wstest;
-
-import java.util.Collection;
-
-import org.apache.beehive.test.tools.tch.compose.internal.context.AtomicTestContext;
-import org.apache.beehive.test.tools.tch.compose.Parameters;
-
-
-public class WSTestContext extends AtomicTestContext implements Runnable
-{
-
- public WSTestContext(String inClassName,Parameters inParams,Collection inTestMethods) {
- super(inClassName,inParams,inTestMethods);
- }
-
- public void run() {
- super.run();
- }
-
-}
+package org.apache.beehive.test.tools.tch.extension.exectask.wstest;
+
+import java.util.Collection;
+
+import org.apache.beehive.test.tools.tch.compose.internal.context.AtomicTestContext;
+import org.apache.beehive.test.tools.tch.compose.Parameters;
+
+
+public class WSTestContext extends AtomicTestContext implements Runnable
+{
+
+ public WSTestContext(String inClassName,Parameters inParams,Collection inTestMethods) {
+ super(inClassName,inParams,inTestMethods);
+ }
+
+ public void run() {
+ super.run();
+ }
+
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/wstest/WSTestContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/wstest/WSTestSettingsXMLReader.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/wstest/WSTestSettingsXMLReader.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/wstest/WSTestSettingsXMLReader.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/wstest/WSTestSettingsXMLReader.java Fri Aug 12 08:12:28 2005
@@ -1,129 +1,129 @@
-package org.apache.beehive.test.tools.tch.extension.exectask.wstest;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import org.apache.beehive.test.tools.tch.core.AntProperties;
-import org.apache.beehive.test.tools.tch.util.xml.DomUtils;
-
-
-public class WSTestSettingsXMLReader
-{
-
- static final public WSTestSettingsXMLReader wsSettings = new WSTestSettingsXMLReader();
- static private boolean bInitComplete=false;
- static private HashMap settings = null;
- static private HashMap defaults = new HashMap();
- static private ArrayList wsList = new ArrayList();
-
- private WSTestSettingsXMLReader() {}
-
- public static WSTestSettingsXMLReader getInstance() throws Exception {
- if (!bInitComplete) {
- initWebServerSettings();
- bInitComplete=true;
- }
- return wsSettings;
- }
-
- public String getValue(String webserver, String key) {
- if (settings==null) return null; //impossible
- HashMap map = (HashMap) settings.get(webserver);
- return (String) map.get(key);
- }
-
- public ArrayList getWebServerList() {
- return wsList;
- }
-
- public HashMap getWebServerSettings(String webserver) {
- if (settings==null) return new HashMap(); //impossible
- return (HashMap) settings.get(webserver);
- }
-
- public HashMap getDefaults() {
- return defaults;
- }
-
- private synchronized static void initWebServerSettings() throws Exception {
- if (settings!=null)
- return;
- settings = new HashMap();
- InputStream is = null;
- BufferedInputStream bis = null;
- try {
- File wsf = AntProperties.getWsTestSettings();
- is = new FileInputStream (wsf);
- bis = new BufferedInputStream (is);
- Document root = DomUtils.instantiateDom(is, false);
-
- //read in web server settings:
- //name and port number get added to the test's internal parameters
- //as well as any other web server specific value provided
- NodeList nl = root.getElementsByTagName("webServer");
- if (nl==null)
- return; //improper setup: no web servers
- for (int i = 0, iL = nl.getLength(); i < iL; i++)
- {
- Node currentInNode = nl.item(i);
- HashMap map = new HashMap();
- DomUtils.treeAttributesToMap(currentInNode, map);
- String wsName = (String)map.get("name");
- if (wsName!=null && map.get("enable")!=null) {
- String enable=((String) map.get("enable")).trim();
- if (enable.equals("true")) { //only include enabled web servers
- wsList.add(wsName);
- map.remove("enable"); //enable is not a test runtime setting
- settings.put(wsName,map);
- }
- }
- }
-
- //read in additional default properties, if any
- NodeList dnl = root.getElementsByTagName("defaultproperty");
- if (dnl==null)
- return;
- for (int i = 0, iL = dnl.getLength(); i < iL; i++)
- {
- Node currentInNode = dnl.item(i);
- String name = getAttributeValue(currentInNode, "name");
- if (name==null || name.length()==0)
- continue;
- defaults.put(name, getAttributeValue(currentInNode, "value"));
- }
-
- }
- finally {
- try {if (bis!=null) bis.close();} catch(Exception e) {}
- try {if (is!=null) is.close(); } catch(Exception e) {}
- }
-
- }
-
-
- private static String getAttributeValue(Node n, String attrName)
- {
- String value = null;
- NamedNodeMap attributes = n.getAttributes();
- Node valueNode = attributes.getNamedItem(attrName);
- if (valueNode != null)
- {
- value = valueNode.getNodeValue();
- }
- if (value!=null)
- value=value.trim();
- return value;
- }
-
-
-}
+package org.apache.beehive.test.tools.tch.extension.exectask.wstest;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.apache.beehive.test.tools.tch.core.AntProperties;
+import org.apache.beehive.test.tools.tch.util.xml.DomUtils;
+
+
+public class WSTestSettingsXMLReader
+{
+
+ static final public WSTestSettingsXMLReader wsSettings = new WSTestSettingsXMLReader();
+ static private boolean bInitComplete=false;
+ static private HashMap settings = null;
+ static private HashMap defaults = new HashMap();
+ static private ArrayList wsList = new ArrayList();
+
+ private WSTestSettingsXMLReader() {}
+
+ public static WSTestSettingsXMLReader getInstance() throws Exception {
+ if (!bInitComplete) {
+ initWebServerSettings();
+ bInitComplete=true;
+ }
+ return wsSettings;
+ }
+
+ public String getValue(String webserver, String key) {
+ if (settings==null) return null; //impossible
+ HashMap map = (HashMap) settings.get(webserver);
+ return (String) map.get(key);
+ }
+
+ public ArrayList getWebServerList() {
+ return wsList;
+ }
+
+ public HashMap getWebServerSettings(String webserver) {
+ if (settings==null) return new HashMap(); //impossible
+ return (HashMap) settings.get(webserver);
+ }
+
+ public HashMap getDefaults() {
+ return defaults;
+ }
+
+ private synchronized static void initWebServerSettings() throws Exception {
+ if (settings!=null)
+ return;
+ settings = new HashMap();
+ InputStream is = null;
+ BufferedInputStream bis = null;
+ try {
+ File wsf = AntProperties.getWsTestSettings();
+ is = new FileInputStream (wsf);
+ bis = new BufferedInputStream (is);
+ Document root = DomUtils.instantiateDom(is, false);
+
+ //read in web server settings:
+ //name and port number get added to the test's internal parameters
+ //as well as any other web server specific value provided
+ NodeList nl = root.getElementsByTagName("webServer");
+ if (nl==null)
+ return; //improper setup: no web servers
+ for (int i = 0, iL = nl.getLength(); i < iL; i++)
+ {
+ Node currentInNode = nl.item(i);
+ HashMap map = new HashMap();
+ DomUtils.treeAttributesToMap(currentInNode, map);
+ String wsName = (String)map.get("name");
+ if (wsName!=null && map.get("enable")!=null) {
+ String enable=((String) map.get("enable")).trim();
+ if (enable.equals("true")) { //only include enabled web servers
+ wsList.add(wsName);
+ map.remove("enable"); //enable is not a test runtime setting
+ settings.put(wsName,map);
+ }
+ }
+ }
+
+ //read in additional default properties, if any
+ NodeList dnl = root.getElementsByTagName("defaultproperty");
+ if (dnl==null)
+ return;
+ for (int i = 0, iL = dnl.getLength(); i < iL; i++)
+ {
+ Node currentInNode = dnl.item(i);
+ String name = getAttributeValue(currentInNode, "name");
+ if (name==null || name.length()==0)
+ continue;
+ defaults.put(name, getAttributeValue(currentInNode, "value"));
+ }
+
+ }
+ finally {
+ try {if (bis!=null) bis.close();} catch(Exception e) {}
+ try {if (is!=null) is.close(); } catch(Exception e) {}
+ }
+
+ }
+
+
+ private static String getAttributeValue(Node n, String attrName)
+ {
+ String value = null;
+ NamedNodeMap attributes = n.getAttributes();
+ Node valueNode = attributes.getNamedItem(attrName);
+ if (valueNode != null)
+ {
+ value = valueNode.getNodeValue();
+ }
+ if (value!=null)
+ value=value.trim();
+ return value;
+ }
+
+
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/extension/exectask/wstest/WSTestSettingsXMLReader.java
------------------------------------------------------------------------------
svn:eol-style = native