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 [83/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/util/TchUtils.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/TchUtils.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/TchUtils.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/TchUtils.java Fri Aug 12 08:12:28 2005
@@ -1,689 +1,689 @@
-package org.apache.beehive.test.tools.tch.util;
-
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.LineNumberReader;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.lang.reflect.Method;
-import java.net.InetAddress;
-import java.text.SimpleDateFormat;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Random;
-import java.util.StringTokenizer;
-
-import org.apache.beehive.test.tools.tch.core.AntProperties;
-import org.apache.beehive.test.tools.tch.core.TestSuiteChild;
-import org.apache.beehive.test.tools.tch.core.configuration.NonfatalValidationException;
-
-/**
- * Holds different utility methods, some of them Tch specific.
- */
-public final class TchUtils implements TchConstants
-{
-  private static final Date logdate = new Date();
-
-  private static final SimpleDateFormat logdateFmt =
-    new SimpleDateFormat("HH:mm:ss:SSS");
-
-  private static final SimpleDateFormat uniqueRunIdFmt =
-    new SimpleDateFormat("_yy_MMM_d_H_mm_ss_S");
-  private static final Random uniqueRunIdRand = new Random();
-
-  // remove this handle since there may be more than one process config file
-  //private static File configFileParentDir = null;
-
-  /**
-   * Logs a message to the PrintWriter specified
-   * If msg is a throwable, it prints the stack trace to the printwriter
-   */
-  public static void log(Object msg, PrintWriter pw)
-  {
-    logdate.setTime(System.currentTimeMillis());
-    pw.println("[" + logdateFmt.format(logdate) + "] " + msg);
-    if (msg instanceof Throwable)
-    {
-      Throwable exc = (Throwable)msg;
-      pw.print(" --> ");
-      exc.printStackTrace(pw);
-    }
-    pw.flush();
-  }
-
-  /**
-   * Logs a message to the PrintStream specified
-   * If msg is a throwable, it also prints the stack trace to the PrintStream
-   */
-  public static void log(Object msg, PrintStream ps)
-  {
-    PrintWriter pw = new PrintWriter(ps);
-    log(msg, pw);
-  }
-
-  /**
-   * Same as calling log (msg, System.out);
-   */
-  public static void log(Object msg)
-  {
-    log(msg, System.out);
-  }
-
-  /**
-   * Returns the stack trace for a Throwable.
-   *
-   * @param th               Throwable
-   * @return                 String representation of its stack trace
-   */
-  public static String throwable2StackTrace(Throwable th)
-  {
-    ByteArrayOutputStream ostr = new ByteArrayOutputStream();
-    th.printStackTrace(new PrintStream(ostr));
-    return ostr.toString();
-  }
-
-  public static String getFilteredStackTrace(Throwable th)
-  {
-    String oldStack = throwable2StackTrace(th);
-    return getFilteredStackTrace(oldStack);
-  }
-
-  public static Map runAllNoArgGetters(Object o)
-  {
-    return runAllNoArgGetters(o, "", false, false);
-  }
-  public static Map runAllNoArgGetters(
-    Object o,
-    String namePrefix,
-    boolean toLowercase,
-    boolean ignoreExceptions)
-  {
-    Map rtn = new HashMap();
-    Collection methods = getAllGetterMethods(o.getClass());
-    for (Iterator iter = methods.iterator(); iter.hasNext();)
-    {
-      Method method = (Method)iter.next();
-      try
-      {
-        String methodRtn = String.valueOf(method.invoke(o, null));
-        rtn.put(
-          (namePrefix
-            + method.getName().substring(GET_PREFIX.length()).toLowerCase()),
-          methodRtn);
-      }
-      catch (Exception ex)
-      {
-        if (!ignoreExceptions)
-          throw new NestedRuntimeException(ex);
-      }
-    }
-    return rtn;
-  }
-
-  private static final String GET_PREFIX = "get";
-  public static Collection getAllGetterMethods(Class c)
-  {
-    // for now we'll just return getters for the following return types:
-    // String
-    // Integer/int
-    Class[] returnTypes =
-      new Class[] { String.class, Integer.class, int.class };
-
-    Collection rtn = new HashSet();
-    Method[] methods = c.getMethods();
-    for (int i = 0; i < methods.length; i++)
-      if (methods[i].getName().startsWith(GET_PREFIX))
-        for (int j = 0; j < returnTypes.length; j++)
-          if (methods[i].getReturnType().equals(returnTypes[j]))
-            rtn.add(methods[i]);
-    return rtn;
-  }
-
-  public static String[] getWindowSyntaxArray(String windowName)
-  {
-    String[] ret = new String[6];
-    ret[0] = "cmd";
-    ret[1] = "/c";
-    ret[2] = "start";
-    ret[3] = "\"" + windowName + "\"";
-    ret[4] = "cmd";
-    ret[5] = "/k";
-    return ret;
-  }
-
-  public static String getWindowSyntaxString(String windowName)
-  {
-    return arrayToString(getWindowSyntaxArray(windowName), " ");
-  }
-
-  public static String getFilteredStackTrace(String oldStack)
-  {
-    try
-    {
-      LineNumberReader r = new LineNumberReader(new StringReader(oldStack));
-
-      StringBuffer sb = new StringBuffer();
-
-      String topLine = r.readLine();
-      if (topLine != null)
-      {
-        sb.append(topLine).append('\n'); //Don't filter the first line
-
-        for (String line = r.readLine(); line != null; line = r.readLine())
-        {
-          if (line.indexOf("org.apache.beehive.test.tools.tch.test") != -1)
-            sb.append(line).append('\n');
-          else if (line.indexOf("org.apache.beehive.test.tools.tch") == -1)
-            sb.append(line).append('\n');
-        }
-      }
-      return sb.toString();
-    }
-    catch (IOException ex)
-    {
-      ex.printStackTrace();
-      return null;
-    }
-  }
-
-  public static String filterStack(Throwable outer, Throwable inner)
-  {
-    String outerStack = throwable2StackTrace(outer);
-    String topOuterStack;
-    String bottomOuterStack;
-    String innerStack = throwable2StackTrace(inner);
-
-    // If the exception is caught and rethrown, we need to do the filter only
-    // to the top section
-    int topindex = outerStack.indexOf("Caused by: ");
-    if (topindex != -1)
-    {
-      topOuterStack = outerStack.substring(0, topindex);
-      bottomOuterStack = outerStack.substring(topindex, outerStack.length());
-    }
-    else
-    {
-      topOuterStack = outerStack;
-      bottomOuterStack = "";
-    }
-    int length =
-      topOuterStack.length() - innerStack.length() + innerStack.indexOf("\n");
-    if (length > 0)
-      return (topOuterStack.substring(0, length + 1) + bottomOuterStack);
-    else
-      return (topOuterStack + bottomOuterStack);
-  }
-
-  private static Integer[] INT_CACHE;
-  /** 
-   * returns an integer representation of a value, from a cache if possible
-   */
-  public static Integer asInteger(int i)
-  {
-    if (INT_CACHE == null)
-    {
-      INT_CACHE = new Integer[14];
-      for (int j = 0; j < INT_CACHE.length; j++)
-      {
-        INT_CACHE[j] = new Integer(j - 1);
-      }
-    }
-    Integer rtnI = null;
-    if (i >= -1 && i <= 12)
-      rtnI = INT_CACHE[i + 1];
-    else
-      rtnI = new Integer(i);
-    return rtnI;
-  }
-
-  // return the directory containing the process config file.
-  public static synchronized File getConfigFileParentDir(String processConfigFile)
-  {
-    // No longer read this from the tch property since there may be more
-    // than one process config
-    //      configFileParentDir =
-    //        new File(AntProperties.getProcessConfigName())
-    //          .getAbsoluteFile()
-    //         .getParentFile();
-    File configFileParentDir =
-      new File(processConfigFile).getAbsoluteFile().getParentFile();
-    return configFileParentDir;
-  }
-
-  public static String getCanonicalPath(String inPath)
-  {
-    return getCanonicalPath(new File(inPath));
-  }
-
-  public static String getCanonicalPath(File inPath)
-  {
-    try
-    {
-      return inPath.getCanonicalPath();
-    }
-    catch (IOException ex)
-    {
-      throw new NestedRuntimeException(ex);
-    }
-  }
-
-  public static File getCanonicalFile(File inPath)
-  {
-    try
-    {
-      return inPath.getCanonicalFile();
-    }
-    catch (IOException ex)
-    {
-      throw new NestedRuntimeException(ex);
-    }
-  }
-
-  /** 
-   * Gets a unique run id.
-   * This is also used as an import number, following the GTLF contract.
-   */
-  public static synchronized String getUniqueRunID() throws Exception
-  {
-    String hostid = InetAddress.getLocalHost().getHostName();
-    int indexOfDot = hostid.indexOf(".");
-    if (indexOfDot != -1)
-      hostid = hostid.substring(0, indexOfDot);
-
-    if (hostid.length() > 15)
-      hostid = hostid.substring(0, 15);
-
-    String time = uniqueRunIdFmt.format(new Date());
-
-    StringBuffer importnum = new StringBuffer();
-    importnum.append(hostid);
-    importnum.append(time);
-    importnum.append("_R");
-    importnum.append(uniqueRunIdRand.nextInt(999));
-    return importnum.toString();
-  }
-
-  /**
-   * Get a random integer between 2 numbers
-   */
-  public static int getRandomInt(int lowPort, int highPort)
-  {
-    int diff = highPort - lowPort;
-    Random rand = new Random();
-    int port = -1;
-    double nextrand = rand.nextDouble();
-    port = ((int) (nextrand * diff)) + lowPort;
-    return port;
-  }
-
-  public static String getContentsAsString(File f)
-  {
-    try
-    {
-      StringWriter bos = new StringWriter();
-      FileReader fr = new FileReader(f);
-      char[] buffer = new char[1024];
-      int readCount = 0;
-      while ((readCount = fr.read(buffer)) > 0)
-      {
-        bos.write(buffer, 0, readCount);
-      }
-      fr.close();
-      return bos.toString();
-    }
-    catch (Exception exc)
-    {
-      TchUtils.log("Error reading file: " + f);
-    }
-    return null;
-  }
-
-  /**
-   * Writes String to file.
-   */
-  public static void writeToFile(String content, File f) throws IOException
-  {
-    PrintWriter pw =
-      new PrintWriter(new BufferedOutputStream(new FileOutputStream(f)));
-    pw.write(content);
-    pw.close();
-  }
-
-  /**
-   * Simple Copy.
-   */
-  public static void copyFile(File src, File dest) throws IOException
-  {
-    byte[] buffer = new byte[1024];
-    int readCount = 0;
-    FileInputStream fis = new FileInputStream(src);
-    FileOutputStream fos = new FileOutputStream(dest);
-    while ((readCount = fis.read(buffer)) > 0)
-    {
-      fos.write(buffer, 0, readCount);
-    }
-    fis.close();
-    fos.close();
-  }
-
-  public static String collectionToString(Collection col, String sep)
-  {
-    StringBuffer sb = new StringBuffer();
-    for (Iterator iter = col.iterator(); iter.hasNext();)
-    {
-      String s = (String)iter.next();
-      sb.append(s);
-      if (iter.hasNext())
-        sb.append(sep);
-    }
-    return sb.toString();
-  }
-
-  /**
-   * Splits string using delimiter, returns String array.
-   */
-  public static String[] parseString(String source, String delimiter)
-  {
-    StringTokenizer st = new StringTokenizer(source, delimiter);
-    String[] rtn = new String[st.countTokens()];
-    for (int count = 0; st.hasMoreTokens(); count++)
-    {
-      rtn[count] = st.nextToken().trim();
-    }
-    return rtn;
-  }
-
-  /**
-   * Splits string using delimiter, returns Collection of Integers
-   */
-  public static void parseStringToIntegers(
-    String source,
-    String delimiter,
-    Collection inColl)
-  {
-    String[] arr = TchUtils.parseString(source, delimiter);
-    for (int i = 0; i < arr.length; i++)
-    {
-      inColl.add(new Integer(Integer.parseInt(arr[i])));
-    }
-  }
-
-  /**
-   * Splits string using delimiter, returns Collection of Strings
-   */
-  public static void parseStringToStrings(
-    String source,
-    String delimiter,
-    Collection inColl)
-  {
-    String[] arr = TchUtils.parseString(source, delimiter);
-    for (int i = 0; i < arr.length; i++)
-    {
-      inColl.add(arr[i]);
-    }
-  }
-
-  /**
-  * This is a somewhat specialized method for doing a string replacement on
-  * a name=value pair in a string. This is used when we don't care about the value, but want to
-  * replace the name/value regardless of what the value is. Would be nice if it took a
-  * value as well, but currently we don't need it to.
-  * It will take quotes into consideration when determining
-  * what's considered a value.
-  * Note: We could just use String replaceAll() here, but we want to remain
-  * buildable under JDK 1.3
-  *
-  * @param origstring original value to do search and replace on
-  * @param name name of the property we want to replace
-  * @param replaceText string to replace the name, value pair with
-  */
-  public static String replaceNameValuePair(
-    String origstring,
-    String name,
-    String replaceText)
-  {
-    if (origstring == null)
-      return null;
-    String search_content = name + "=";
-    int content_length = search_content.length();
-    int start_index = origstring.indexOf(search_content);
-    if (start_index == -1)
-    {
-      // name wasn't found so just return original string
-      return origstring;
-    }
-
-    boolean in_quote = false;
-    int end_index;
-    for (end_index = (start_index + content_length);
-      end_index < origstring.length();
-      ++end_index)
-    {
-      char c = origstring.charAt(end_index);
-      if (c == '"')
-      {
-        if (in_quote)
-          in_quote = false;
-        else
-          in_quote = true;
-      }
-      else if (c == ' ')
-      {
-        if (in_quote == false)
-          break;
-      }
-    }
-    // end_index should contain the proper end index now
-    StringBuffer sb = new StringBuffer();
-    if (start_index > 0)
-    {
-      sb.append(origstring.substring(0, start_index));
-    }
-    sb.append(replaceText);
-    if (end_index < origstring.length())
-    {
-      sb.append(origstring.substring(end_index, origstring.length()));
-    }
-    return sb.toString();
-  }
-
-  public static String arrayToString(Object[] ar, String sep)
-  {
-    StringBuffer sb = new StringBuffer();
-    for (int i = 0; i < ar.length; i++)
-    {
-      if (i != 0)
-        sb.append(sep);
-      sb.append(ar[i]);
-    }
-    return sb.toString();
-  }
-
-  /**
-   *
-   */
-  public static String searchAndReplace(
-    String original,
-    String findthis,
-    String replacewith)
-  {
-    if (original == null || findthis == null || findthis.equals(""))
-      return original; // null check
-    if (replacewith == null)
-      replacewith = "";
-
-    int offset = 0;
-    int pointer = original.indexOf(findthis);
-
-    int findthislength = findthis.length();
-
-    if (pointer < 0)
-      return original; // short circuit
-
-    StringBuffer replaced = new StringBuffer();
-    String firstpart = "";
-
-    while (pointer >= 0)
-    {
-      firstpart = original.substring(offset, pointer);
-      replaced.append(firstpart);
-      replaced.append(replacewith);
-
-      // next iteration
-      offset = pointer + findthislength;
-      pointer = original.indexOf(findthis, offset);
-    }
-
-    String lastpart = original.substring(offset, original.length());
-    replaced.append(lastpart);
-
-    return replaced.toString();
-  }
-
-  public static String getRelativePath(String baseDir, String file)
-  {
-    //FIXME:  THis is just nasty code that works.  Must be cleaned up at some point (right... :)
-
-    String[] fileArr = TchUtils.parseString(file, "\\" + "/");
-
-    baseDir = baseDir.trim();
-    if (baseDir.endsWith("\\.") || baseDir.endsWith("/."))
-      baseDir = baseDir.substring(0, baseDir.length() - 2);
-    //trim off the last 2 chars
-
-    String[] baseDirArr = TchUtils.parseString(baseDir, "\\" + "/");
-
-    StringBuffer sb = new StringBuffer();
-    boolean split = false;
-    //assume (to start) that the file is under the dir somewhere
-    boolean justSplit = true;
-    boolean dirDone = false; //Still stuff in the baseDir array
-    boolean uhyeah = true;
-    for (int i = 0; i < fileArr.length; i++)
-    {
-      if (!dirDone && i > baseDirArr.length - 1) //no more baseDir elements
-        dirDone = true;
-
-      if (!dirDone)
-      {
-        if (!split && !fileArr[i].equals(baseDirArr[i])) //elements diverge
-          split = true;
-
-        if (split)
-        {
-          String front = "..";
-          if (!justSplit)
-            front = front + "/";
-          sb.insert(0, front);
-          sb.append("/" + fileArr[i]);
-          justSplit = false;
-        }
-        else
-        {
-          //do nothing, dupes
-        }
-      }
-      else
-      {
-        String s = fileArr[i];
-        if (split || !uhyeah)
-        {
-          s = "/" + s;
-        }
-        if (uhyeah)
-        {
-          uhyeah = false;
-        }
-        sb.append(s);
-      }
-      //System.out.println("Step "+i+":  "+sb.toString()+" uhyeah="+uhyeah+" split="+split);
-    }
-    return sb.toString();
-  }
-
-  public static boolean isAbsolutePath(String pathname)
-  {
-    return pathname.startsWith("/") || //Unix
-    pathname.indexOf(":") != -1; //Windows
-  }
-
-  public static String getDirectoryPath(String pathname)
-  {
-    int backwardInd = pathname.lastIndexOf("\\");
-    int forwardInd = pathname.lastIndexOf("/");
-    return pathname.substring(0, Math.max(backwardInd, forwardInd) + 1);
-  }
-
-  /**
-   * Validate a test-unit or test name by checking for illegal characters.
-   * Currently, no spaces or dots are allowed in the name.
-   * 
-   * @param nameToValidate test or test-unit name to validate
-   * @throws NonfatalValidationException exception thrown when validation fails
-   */
-  public static void validateName(String nameToValidate)
-    throws NonfatalValidationException
-  {
-    boolean foundProblem = false;
-    String[] illegalChars = TchConstants.ILLEGAL_NAME_CHARS;
-    StringBuffer invalidCharsMsg = null;
-    for (int i = 0; i < illegalChars.length; i += 2)
-    {
-      if (nameToValidate.indexOf(illegalChars[i]) != -1)
-      {
-        if (foundProblem) // so this is not the first problem we find
-          invalidCharsMsg.append(","); // for nicer formatting
-
-        if (!foundProblem)
-        {
-          invalidCharsMsg = new StringBuffer();
-          foundProblem = true;
-        }
-        invalidCharsMsg
-          .append(" '")
-          .append(illegalChars[i])
-          .append("' (")
-          .append(illegalChars[i + 1])
-          .append(")");
-      }
-    }
-    if (foundProblem)
-    {
-      //VALIDATION ERROR
-      //throw new NonfatalValidationException(errorMessage.toString());
-      Map params = new HashMap(2);
-      params.put(ErrorMessageConstants.NAME, nameToValidate);
-      params.put(
-        ErrorMessageConstants.ILLEGALCHARS,
-        invalidCharsMsg.toString());
-      throw new NonfatalValidationException(
-        ErrorMessageConstants.VALIDATE_NAME_ERROR_CODE,
-        params);
-    }
-  }
-
-  public static void main(String[] args)
-  {
-  }
-
-  public static boolean sameSuite(Object test1, Object test2)
-  {
-    if (test1 instanceof TestSuiteChild && test2 instanceof TestSuiteChild)
-      return ((TestSuiteChild)test1).getTestSuiteTask()
-        == ((TestSuiteChild)test2).getTestSuiteTask();
-    else
-      return false;
-  }
-
-}
+package org.apache.beehive.test.tools.tch.util;
+
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.lang.reflect.Method;
+import java.net.InetAddress;
+import java.text.SimpleDateFormat;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Random;
+import java.util.StringTokenizer;
+
+import org.apache.beehive.test.tools.tch.core.AntProperties;
+import org.apache.beehive.test.tools.tch.core.TestSuiteChild;
+import org.apache.beehive.test.tools.tch.core.configuration.NonfatalValidationException;
+
+/**
+ * Holds different utility methods, some of them Tch specific.
+ */
+public final class TchUtils implements TchConstants
+{
+  private static final Date logdate = new Date();
+
+  private static final SimpleDateFormat logdateFmt =
+    new SimpleDateFormat("HH:mm:ss:SSS");
+
+  private static final SimpleDateFormat uniqueRunIdFmt =
+    new SimpleDateFormat("_yy_MMM_d_H_mm_ss_S");
+  private static final Random uniqueRunIdRand = new Random();
+
+  // remove this handle since there may be more than one process config file
+  //private static File configFileParentDir = null;
+
+  /**
+   * Logs a message to the PrintWriter specified
+   * If msg is a throwable, it prints the stack trace to the printwriter
+   */
+  public static void log(Object msg, PrintWriter pw)
+  {
+    logdate.setTime(System.currentTimeMillis());
+    pw.println("[" + logdateFmt.format(logdate) + "] " + msg);
+    if (msg instanceof Throwable)
+    {
+      Throwable exc = (Throwable)msg;
+      pw.print(" --> ");
+      exc.printStackTrace(pw);
+    }
+    pw.flush();
+  }
+
+  /**
+   * Logs a message to the PrintStream specified
+   * If msg is a throwable, it also prints the stack trace to the PrintStream
+   */
+  public static void log(Object msg, PrintStream ps)
+  {
+    PrintWriter pw = new PrintWriter(ps);
+    log(msg, pw);
+  }
+
+  /**
+   * Same as calling log (msg, System.out);
+   */
+  public static void log(Object msg)
+  {
+    log(msg, System.out);
+  }
+
+  /**
+   * Returns the stack trace for a Throwable.
+   *
+   * @param th               Throwable
+   * @return                 String representation of its stack trace
+   */
+  public static String throwable2StackTrace(Throwable th)
+  {
+    ByteArrayOutputStream ostr = new ByteArrayOutputStream();
+    th.printStackTrace(new PrintStream(ostr));
+    return ostr.toString();
+  }
+
+  public static String getFilteredStackTrace(Throwable th)
+  {
+    String oldStack = throwable2StackTrace(th);
+    return getFilteredStackTrace(oldStack);
+  }
+
+  public static Map runAllNoArgGetters(Object o)
+  {
+    return runAllNoArgGetters(o, "", false, false);
+  }
+  public static Map runAllNoArgGetters(
+    Object o,
+    String namePrefix,
+    boolean toLowercase,
+    boolean ignoreExceptions)
+  {
+    Map rtn = new HashMap();
+    Collection methods = getAllGetterMethods(o.getClass());
+    for (Iterator iter = methods.iterator(); iter.hasNext();)
+    {
+      Method method = (Method)iter.next();
+      try
+      {
+        String methodRtn = String.valueOf(method.invoke(o, null));
+        rtn.put(
+          (namePrefix
+            + method.getName().substring(GET_PREFIX.length()).toLowerCase()),
+          methodRtn);
+      }
+      catch (Exception ex)
+      {
+        if (!ignoreExceptions)
+          throw new NestedRuntimeException(ex);
+      }
+    }
+    return rtn;
+  }
+
+  private static final String GET_PREFIX = "get";
+  public static Collection getAllGetterMethods(Class c)
+  {
+    // for now we'll just return getters for the following return types:
+    // String
+    // Integer/int
+    Class[] returnTypes =
+      new Class[] { String.class, Integer.class, int.class };
+
+    Collection rtn = new HashSet();
+    Method[] methods = c.getMethods();
+    for (int i = 0; i < methods.length; i++)
+      if (methods[i].getName().startsWith(GET_PREFIX))
+        for (int j = 0; j < returnTypes.length; j++)
+          if (methods[i].getReturnType().equals(returnTypes[j]))
+            rtn.add(methods[i]);
+    return rtn;
+  }
+
+  public static String[] getWindowSyntaxArray(String windowName)
+  {
+    String[] ret = new String[6];
+    ret[0] = "cmd";
+    ret[1] = "/c";
+    ret[2] = "start";
+    ret[3] = "\"" + windowName + "\"";
+    ret[4] = "cmd";
+    ret[5] = "/k";
+    return ret;
+  }
+
+  public static String getWindowSyntaxString(String windowName)
+  {
+    return arrayToString(getWindowSyntaxArray(windowName), " ");
+  }
+
+  public static String getFilteredStackTrace(String oldStack)
+  {
+    try
+    {
+      LineNumberReader r = new LineNumberReader(new StringReader(oldStack));
+
+      StringBuffer sb = new StringBuffer();
+
+      String topLine = r.readLine();
+      if (topLine != null)
+      {
+        sb.append(topLine).append('\n'); //Don't filter the first line
+
+        for (String line = r.readLine(); line != null; line = r.readLine())
+        {
+          if (line.indexOf("org.apache.beehive.test.tools.tch.test") != -1)
+            sb.append(line).append('\n');
+          else if (line.indexOf("org.apache.beehive.test.tools.tch") == -1)
+            sb.append(line).append('\n');
+        }
+      }
+      return sb.toString();
+    }
+    catch (IOException ex)
+    {
+      ex.printStackTrace();
+      return null;
+    }
+  }
+
+  public static String filterStack(Throwable outer, Throwable inner)
+  {
+    String outerStack = throwable2StackTrace(outer);
+    String topOuterStack;
+    String bottomOuterStack;
+    String innerStack = throwable2StackTrace(inner);
+
+    // If the exception is caught and rethrown, we need to do the filter only
+    // to the top section
+    int topindex = outerStack.indexOf("Caused by: ");
+    if (topindex != -1)
+    {
+      topOuterStack = outerStack.substring(0, topindex);
+      bottomOuterStack = outerStack.substring(topindex, outerStack.length());
+    }
+    else
+    {
+      topOuterStack = outerStack;
+      bottomOuterStack = "";
+    }
+    int length =
+      topOuterStack.length() - innerStack.length() + innerStack.indexOf("\n");
+    if (length > 0)
+      return (topOuterStack.substring(0, length + 1) + bottomOuterStack);
+    else
+      return (topOuterStack + bottomOuterStack);
+  }
+
+  private static Integer[] INT_CACHE;
+  /** 
+   * returns an integer representation of a value, from a cache if possible
+   */
+  public static Integer asInteger(int i)
+  {
+    if (INT_CACHE == null)
+    {
+      INT_CACHE = new Integer[14];
+      for (int j = 0; j < INT_CACHE.length; j++)
+      {
+        INT_CACHE[j] = new Integer(j - 1);
+      }
+    }
+    Integer rtnI = null;
+    if (i >= -1 && i <= 12)
+      rtnI = INT_CACHE[i + 1];
+    else
+      rtnI = new Integer(i);
+    return rtnI;
+  }
+
+  // return the directory containing the process config file.
+  public static synchronized File getConfigFileParentDir(String processConfigFile)
+  {
+    // No longer read this from the tch property since there may be more
+    // than one process config
+    //      configFileParentDir =
+    //        new File(AntProperties.getProcessConfigName())
+    //          .getAbsoluteFile()
+    //         .getParentFile();
+    File configFileParentDir =
+      new File(processConfigFile).getAbsoluteFile().getParentFile();
+    return configFileParentDir;
+  }
+
+  public static String getCanonicalPath(String inPath)
+  {
+    return getCanonicalPath(new File(inPath));
+  }
+
+  public static String getCanonicalPath(File inPath)
+  {
+    try
+    {
+      return inPath.getCanonicalPath();
+    }
+    catch (IOException ex)
+    {
+      throw new NestedRuntimeException(ex);
+    }
+  }
+
+  public static File getCanonicalFile(File inPath)
+  {
+    try
+    {
+      return inPath.getCanonicalFile();
+    }
+    catch (IOException ex)
+    {
+      throw new NestedRuntimeException(ex);
+    }
+  }
+
+  /** 
+   * Gets a unique run id.
+   * This is also used as an import number, following the GTLF contract.
+   */
+  public static synchronized String getUniqueRunID() throws Exception
+  {
+    String hostid = InetAddress.getLocalHost().getHostName();
+    int indexOfDot = hostid.indexOf(".");
+    if (indexOfDot != -1)
+      hostid = hostid.substring(0, indexOfDot);
+
+    if (hostid.length() > 15)
+      hostid = hostid.substring(0, 15);
+
+    String time = uniqueRunIdFmt.format(new Date());
+
+    StringBuffer importnum = new StringBuffer();
+    importnum.append(hostid);
+    importnum.append(time);
+    importnum.append("_R");
+    importnum.append(uniqueRunIdRand.nextInt(999));
+    return importnum.toString();
+  }
+
+  /**
+   * Get a random integer between 2 numbers
+   */
+  public static int getRandomInt(int lowPort, int highPort)
+  {
+    int diff = highPort - lowPort;
+    Random rand = new Random();
+    int port = -1;
+    double nextrand = rand.nextDouble();
+    port = ((int) (nextrand * diff)) + lowPort;
+    return port;
+  }
+
+  public static String getContentsAsString(File f)
+  {
+    try
+    {
+      StringWriter bos = new StringWriter();
+      FileReader fr = new FileReader(f);
+      char[] buffer = new char[1024];
+      int readCount = 0;
+      while ((readCount = fr.read(buffer)) > 0)
+      {
+        bos.write(buffer, 0, readCount);
+      }
+      fr.close();
+      return bos.toString();
+    }
+    catch (Exception exc)
+    {
+      TchUtils.log("Error reading file: " + f);
+    }
+    return null;
+  }
+
+  /**
+   * Writes String to file.
+   */
+  public static void writeToFile(String content, File f) throws IOException
+  {
+    PrintWriter pw =
+      new PrintWriter(new BufferedOutputStream(new FileOutputStream(f)));
+    pw.write(content);
+    pw.close();
+  }
+
+  /**
+   * Simple Copy.
+   */
+  public static void copyFile(File src, File dest) throws IOException
+  {
+    byte[] buffer = new byte[1024];
+    int readCount = 0;
+    FileInputStream fis = new FileInputStream(src);
+    FileOutputStream fos = new FileOutputStream(dest);
+    while ((readCount = fis.read(buffer)) > 0)
+    {
+      fos.write(buffer, 0, readCount);
+    }
+    fis.close();
+    fos.close();
+  }
+
+  public static String collectionToString(Collection col, String sep)
+  {
+    StringBuffer sb = new StringBuffer();
+    for (Iterator iter = col.iterator(); iter.hasNext();)
+    {
+      String s = (String)iter.next();
+      sb.append(s);
+      if (iter.hasNext())
+        sb.append(sep);
+    }
+    return sb.toString();
+  }
+
+  /**
+   * Splits string using delimiter, returns String array.
+   */
+  public static String[] parseString(String source, String delimiter)
+  {
+    StringTokenizer st = new StringTokenizer(source, delimiter);
+    String[] rtn = new String[st.countTokens()];
+    for (int count = 0; st.hasMoreTokens(); count++)
+    {
+      rtn[count] = st.nextToken().trim();
+    }
+    return rtn;
+  }
+
+  /**
+   * Splits string using delimiter, returns Collection of Integers
+   */
+  public static void parseStringToIntegers(
+    String source,
+    String delimiter,
+    Collection inColl)
+  {
+    String[] arr = TchUtils.parseString(source, delimiter);
+    for (int i = 0; i < arr.length; i++)
+    {
+      inColl.add(new Integer(Integer.parseInt(arr[i])));
+    }
+  }
+
+  /**
+   * Splits string using delimiter, returns Collection of Strings
+   */
+  public static void parseStringToStrings(
+    String source,
+    String delimiter,
+    Collection inColl)
+  {
+    String[] arr = TchUtils.parseString(source, delimiter);
+    for (int i = 0; i < arr.length; i++)
+    {
+      inColl.add(arr[i]);
+    }
+  }
+
+  /**
+  * This is a somewhat specialized method for doing a string replacement on
+  * a name=value pair in a string. This is used when we don't care about the value, but want to
+  * replace the name/value regardless of what the value is. Would be nice if it took a
+  * value as well, but currently we don't need it to.
+  * It will take quotes into consideration when determining
+  * what's considered a value.
+  * Note: We could just use String replaceAll() here, but we want to remain
+  * buildable under JDK 1.3
+  *
+  * @param origstring original value to do search and replace on
+  * @param name name of the property we want to replace
+  * @param replaceText string to replace the name, value pair with
+  */
+  public static String replaceNameValuePair(
+    String origstring,
+    String name,
+    String replaceText)
+  {
+    if (origstring == null)
+      return null;
+    String search_content = name + "=";
+    int content_length = search_content.length();
+    int start_index = origstring.indexOf(search_content);
+    if (start_index == -1)
+    {
+      // name wasn't found so just return original string
+      return origstring;
+    }
+
+    boolean in_quote = false;
+    int end_index;
+    for (end_index = (start_index + content_length);
+      end_index < origstring.length();
+      ++end_index)
+    {
+      char c = origstring.charAt(end_index);
+      if (c == '"')
+      {
+        if (in_quote)
+          in_quote = false;
+        else
+          in_quote = true;
+      }
+      else if (c == ' ')
+      {
+        if (in_quote == false)
+          break;
+      }
+    }
+    // end_index should contain the proper end index now
+    StringBuffer sb = new StringBuffer();
+    if (start_index > 0)
+    {
+      sb.append(origstring.substring(0, start_index));
+    }
+    sb.append(replaceText);
+    if (end_index < origstring.length())
+    {
+      sb.append(origstring.substring(end_index, origstring.length()));
+    }
+    return sb.toString();
+  }
+
+  public static String arrayToString(Object[] ar, String sep)
+  {
+    StringBuffer sb = new StringBuffer();
+    for (int i = 0; i < ar.length; i++)
+    {
+      if (i != 0)
+        sb.append(sep);
+      sb.append(ar[i]);
+    }
+    return sb.toString();
+  }
+
+  /**
+   *
+   */
+  public static String searchAndReplace(
+    String original,
+    String findthis,
+    String replacewith)
+  {
+    if (original == null || findthis == null || findthis.equals(""))
+      return original; // null check
+    if (replacewith == null)
+      replacewith = "";
+
+    int offset = 0;
+    int pointer = original.indexOf(findthis);
+
+    int findthislength = findthis.length();
+
+    if (pointer < 0)
+      return original; // short circuit
+
+    StringBuffer replaced = new StringBuffer();
+    String firstpart = "";
+
+    while (pointer >= 0)
+    {
+      firstpart = original.substring(offset, pointer);
+      replaced.append(firstpart);
+      replaced.append(replacewith);
+
+      // next iteration
+      offset = pointer + findthislength;
+      pointer = original.indexOf(findthis, offset);
+    }
+
+    String lastpart = original.substring(offset, original.length());
+    replaced.append(lastpart);
+
+    return replaced.toString();
+  }
+
+  public static String getRelativePath(String baseDir, String file)
+  {
+    //FIXME:  THis is just nasty code that works.  Must be cleaned up at some point (right... :)
+
+    String[] fileArr = TchUtils.parseString(file, "\\" + "/");
+
+    baseDir = baseDir.trim();
+    if (baseDir.endsWith("\\.") || baseDir.endsWith("/."))
+      baseDir = baseDir.substring(0, baseDir.length() - 2);
+    //trim off the last 2 chars
+
+    String[] baseDirArr = TchUtils.parseString(baseDir, "\\" + "/");
+
+    StringBuffer sb = new StringBuffer();
+    boolean split = false;
+    //assume (to start) that the file is under the dir somewhere
+    boolean justSplit = true;
+    boolean dirDone = false; //Still stuff in the baseDir array
+    boolean uhyeah = true;
+    for (int i = 0; i < fileArr.length; i++)
+    {
+      if (!dirDone && i > baseDirArr.length - 1) //no more baseDir elements
+        dirDone = true;
+
+      if (!dirDone)
+      {
+        if (!split && !fileArr[i].equals(baseDirArr[i])) //elements diverge
+          split = true;
+
+        if (split)
+        {
+          String front = "..";
+          if (!justSplit)
+            front = front + "/";
+          sb.insert(0, front);
+          sb.append("/" + fileArr[i]);
+          justSplit = false;
+        }
+        else
+        {
+          //do nothing, dupes
+        }
+      }
+      else
+      {
+        String s = fileArr[i];
+        if (split || !uhyeah)
+        {
+          s = "/" + s;
+        }
+        if (uhyeah)
+        {
+          uhyeah = false;
+        }
+        sb.append(s);
+      }
+      //System.out.println("Step "+i+":  "+sb.toString()+" uhyeah="+uhyeah+" split="+split);
+    }
+    return sb.toString();
+  }
+
+  public static boolean isAbsolutePath(String pathname)
+  {
+    return pathname.startsWith("/") || //Unix
+    pathname.indexOf(":") != -1; //Windows
+  }
+
+  public static String getDirectoryPath(String pathname)
+  {
+    int backwardInd = pathname.lastIndexOf("\\");
+    int forwardInd = pathname.lastIndexOf("/");
+    return pathname.substring(0, Math.max(backwardInd, forwardInd) + 1);
+  }
+
+  /**
+   * Validate a test-unit or test name by checking for illegal characters.
+   * Currently, no spaces or dots are allowed in the name.
+   * 
+   * @param nameToValidate test or test-unit name to validate
+   * @throws NonfatalValidationException exception thrown when validation fails
+   */
+  public static void validateName(String nameToValidate)
+    throws NonfatalValidationException
+  {
+    boolean foundProblem = false;
+    String[] illegalChars = TchConstants.ILLEGAL_NAME_CHARS;
+    StringBuffer invalidCharsMsg = null;
+    for (int i = 0; i < illegalChars.length; i += 2)
+    {
+      if (nameToValidate.indexOf(illegalChars[i]) != -1)
+      {
+        if (foundProblem) // so this is not the first problem we find
+          invalidCharsMsg.append(","); // for nicer formatting
+
+        if (!foundProblem)
+        {
+          invalidCharsMsg = new StringBuffer();
+          foundProblem = true;
+        }
+        invalidCharsMsg
+          .append(" '")
+          .append(illegalChars[i])
+          .append("' (")
+          .append(illegalChars[i + 1])
+          .append(")");
+      }
+    }
+    if (foundProblem)
+    {
+      //VALIDATION ERROR
+      //throw new NonfatalValidationException(errorMessage.toString());
+      Map params = new HashMap(2);
+      params.put(ErrorMessageConstants.NAME, nameToValidate);
+      params.put(
+        ErrorMessageConstants.ILLEGALCHARS,
+        invalidCharsMsg.toString());
+      throw new NonfatalValidationException(
+        ErrorMessageConstants.VALIDATE_NAME_ERROR_CODE,
+        params);
+    }
+  }
+
+  public static void main(String[] args)
+  {
+  }
+
+  public static boolean sameSuite(Object test1, Object test2)
+  {
+    if (test1 instanceof TestSuiteChild && test2 instanceof TestSuiteChild)
+      return ((TestSuiteChild)test1).getTestSuiteTask()
+        == ((TestSuiteChild)test2).getTestSuiteTask();
+    else
+      return false;
+  }
+
+}

Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/TchUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/TestResult.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/TestResult.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/TestResult.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/TestResult.java Fri Aug 12 08:12:28 2005
@@ -1,152 +1,152 @@
-package org.apache.beehive.test.tools.tch.util;
-
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * Holds TestResult information.
- * <p>
- * This only contains the getter() methods.
- * 
- * @version 1.0, Mar 3, 2001
- */
-public interface TestResult
-  extends TchConstants, Serializable, TestResultType
-{
-  /** Tells if the TestResult has a Throwable contained in it */
-  public boolean hasThrowable();
-
-  /**
-   * Returns the first throwable associated with this result.
-   */
-  public Throwable getThrowable();
-
-  /**
-   * A result may be associated with more than one Throwable.
-   */
-  public Throwable[] getThrowableArray();
-
-  /**
-   * return the String for the stack trace of the throwable, null if none.
-   * This might be filtered by the filter Throwable, if given
-   */
-  public String getStackTrace();
-
-  /**
-   * Returns stacktraces for all stores Throwables, in order.
-   * @return String
-   */
-  public String getStackTraces();
-
-  public Throwable getFilterThrowable();
-
-  /** 
-   * Tells if the TestResult is an inform.
-   */
-  public boolean isInform();
-
-  /** 
-   * Tells if the TestResult is an outcome. An outcome is the last
-   * result which is returned by a Test. E.g. 
-   * ABORT, SKIP, SUCCESS, FAILURE 
-   */
-  public boolean isOutcome();
-
-  /** 
-   * Tells if the TestResult is a timeout.
-   */
-  public boolean isTimeout();
-
-  /** return true if this result represents something bad,
-   * FAILURE, SKIP, ABORT, SCRATCH, TIMEOUT, FRAMEABORT
-   */
-  public boolean isProblem();
-
-  /** 
-   * return true if this result or any inner results represent something bad,
-   * FAILURE, ABORT, SCRATCH, TIMEOUT, FRAMEABORT
-   */
-  public boolean isOrContainsProblems();
-
-  /** 
-   * return true if this is a SUCCESS result.
-   */
-  public boolean hasSucceeded();
-
-  /** return the timestamp */
-  public Date getTimeStamp();
-
-  /** return the duration */
-  public Long getDuration();
-
-  /** return the output message */
-  public String getOutputMessage();
-
-  /** return a more detailed output message, if available */
-  public String getDetails();
-
-  /** return the result info -- additional info about the result other
-      than its success/failure*/
-  public String getResultInfo();
-
-  /** return the path of the test */
-  public String getSourcePath();
-
-  public String getCustomPath();
-
-  /** return the test unit name */
-  public String getTestUnitName();
-
-  public String getCallingChain();
-
-  /** return the test name (test-point) */
-  public String getName();
-
-  /** return the test case name */
-  public String getTestCaseName();
-
-  public String getSubtestName();
-
-  /** return the review state this test is in */
-  public String getReviewState();
-  /** return the bug id associated with this test */
-  public String getBugID();
-  /** return the comments for this test */
-  public String getComments();
-  /** return the parameters accessed by this test */
-  public Map getParameters();
-  /** return an iterator of all the testresults contained in here */
-  public Iterator getInnerResultsIterator();
-
-  public String getErrorName();
-
-  //public Map getProcessOutput();
-  public Map getProcessSummaryMap();
-
-  public Collection getMappedProcessNames();
-
-  public String getCommandLine();
-
-  /**
-   * @return Windows specific command line, if different from 
-   * regular command line. 
-   */
-  public String getWinCommandLine();
-
-  public String getVerboseCommandLine();
-
-  /**
-   * @return Windows specific command line, if different from
-   * regular command line. 
-   */
-  public String getVerboseWinCommandLine();
-
-  public String getReplicationInfo();
-
-  public String getFailureReplicationAntFile();
-
-  public int getDebugLevel();
-}
+package org.apache.beehive.test.tools.tch.util;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Holds TestResult information.
+ * <p>
+ * This only contains the getter() methods.
+ * 
+ * @version 1.0, Mar 3, 2001
+ */
+public interface TestResult
+  extends TchConstants, Serializable, TestResultType
+{
+  /** Tells if the TestResult has a Throwable contained in it */
+  public boolean hasThrowable();
+
+  /**
+   * Returns the first throwable associated with this result.
+   */
+  public Throwable getThrowable();
+
+  /**
+   * A result may be associated with more than one Throwable.
+   */
+  public Throwable[] getThrowableArray();
+
+  /**
+   * return the String for the stack trace of the throwable, null if none.
+   * This might be filtered by the filter Throwable, if given
+   */
+  public String getStackTrace();
+
+  /**
+   * Returns stacktraces for all stores Throwables, in order.
+   * @return String
+   */
+  public String getStackTraces();
+
+  public Throwable getFilterThrowable();
+
+  /** 
+   * Tells if the TestResult is an inform.
+   */
+  public boolean isInform();
+
+  /** 
+   * Tells if the TestResult is an outcome. An outcome is the last
+   * result which is returned by a Test. E.g. 
+   * ABORT, SKIP, SUCCESS, FAILURE 
+   */
+  public boolean isOutcome();
+
+  /** 
+   * Tells if the TestResult is a timeout.
+   */
+  public boolean isTimeout();
+
+  /** return true if this result represents something bad,
+   * FAILURE, SKIP, ABORT, SCRATCH, TIMEOUT, FRAMEABORT
+   */
+  public boolean isProblem();
+
+  /** 
+   * return true if this result or any inner results represent something bad,
+   * FAILURE, ABORT, SCRATCH, TIMEOUT, FRAMEABORT
+   */
+  public boolean isOrContainsProblems();
+
+  /** 
+   * return true if this is a SUCCESS result.
+   */
+  public boolean hasSucceeded();
+
+  /** return the timestamp */
+  public Date getTimeStamp();
+
+  /** return the duration */
+  public Long getDuration();
+
+  /** return the output message */
+  public String getOutputMessage();
+
+  /** return a more detailed output message, if available */
+  public String getDetails();
+
+  /** return the result info -- additional info about the result other
+      than its success/failure*/
+  public String getResultInfo();
+
+  /** return the path of the test */
+  public String getSourcePath();
+
+  public String getCustomPath();
+
+  /** return the test unit name */
+  public String getTestUnitName();
+
+  public String getCallingChain();
+
+  /** return the test name (test-point) */
+  public String getName();
+
+  /** return the test case name */
+  public String getTestCaseName();
+
+  public String getSubtestName();
+
+  /** return the review state this test is in */
+  public String getReviewState();
+  /** return the bug id associated with this test */
+  public String getBugID();
+  /** return the comments for this test */
+  public String getComments();
+  /** return the parameters accessed by this test */
+  public Map getParameters();
+  /** return an iterator of all the testresults contained in here */
+  public Iterator getInnerResultsIterator();
+
+  public String getErrorName();
+
+  //public Map getProcessOutput();
+  public Map getProcessSummaryMap();
+
+  public Collection getMappedProcessNames();
+
+  public String getCommandLine();
+
+  /**
+   * @return Windows specific command line, if different from 
+   * regular command line. 
+   */
+  public String getWinCommandLine();
+
+  public String getVerboseCommandLine();
+
+  /**
+   * @return Windows specific command line, if different from
+   * regular command line. 
+   */
+  public String getVerboseWinCommandLine();
+
+  public String getReplicationInfo();
+
+  public String getFailureReplicationAntFile();
+
+  public int getDebugLevel();
+}

Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/TestResult.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/TestResultAdapter.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/TestResultAdapter.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/TestResultAdapter.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/TestResultAdapter.java Fri Aug 12 08:12:28 2005
@@ -1,757 +1,757 @@
-package org.apache.beehive.test.tools.tch.util;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.beehive.test.tools.tch.core.AntProperties;
-import org.apache.beehive.test.tools.tch.core.remote.ProcessSummary;
-import org.apache.beehive.test.tools.tch.logger.LoggerUtils;
-
-/**
- * Dumb data container for a single test result and all associated metadata. 
- * 
- * @version 1.0, Mar 3, 2001
- */
-public class TestResultAdapter implements TestResultBean
-{
-  private static final String sep = System.getProperty("line.separator");
-
-  private String replicationAntFile = null;
-  private List innerResults = null;
-  private Throwable[] thr = null;
-  private Throwable filter = null;
-  private boolean outcome = false;
-  private int type;
-
-  // an optional result value for additional data such as timing results
-  private String resultInfo;
-
-  private int debugLevel;
-
-  private Date timeStamp = null;
-
-  // the path to the test-file
-  // (in the BH context, this is Ant's Location)
-  private String sourcePath = null;
-
-  // optional additional path information
-  // (for example, for javatest this would be the fully qualified classname,
-  // cause that is useful information to see in the logs)
-  private String customPath = null;
-
-  // summary like information, goes into the .log
-  private String outputMsg = null;
-
-  // any additional info that would be helpful
-  // this is only displayed for problem results right now
-  private String additionalInformation = null;
-
-  private String testUnitName = null;
-  private String callingChain = null;
-
-  private String errorName = null;
-
-  // this is the test-point name
-  private String name = null;
-
-  // this is the test name, an abstract entity
-  // we can have many test-points of the same test case
-  private String testCaseName = null;
-
-  // this is used for a test that submits more than a single results 
-  // these subresults are identified by the subtest name
-  private String subtestName = null;
-
-  // command line related info
-  private String commandLine = null;
-  private String winCommandLine = null;
-
-  private String verboseCommandLine = null;
-  private String verboseWinCommandLine = null;
-
-  // generic information we print along with each 
-  // command line
-  private String replicationInfo = null;
-
-  // output processes under tests
-  // String (process name) --> ProcessSummary
-  private Map processInfo = null;
-
-  private String reviewState = null;
-  private String bugID = null;
-  private String comments = null;
-  private Map params = null;
-  private Long duration = null;
-
-  public TestResultAdapter()
-  {
-  }
-
-  public TestResultAdapter(int inType)
-  {
-    this(inType, null, null, null, null);
-  }
-
-  public TestResultAdapter(int inType, String inName)
-  {
-    this(inType, inName, null, null, null);
-  }
-
-  public TestResultAdapter(int inType, String inName, String inOutputMsg)
-  {
-    this(inType, inName, inOutputMsg, null, null);
-  }
-
-  public TestResultAdapter(
-    int inType,
-    String inName,
-    String inOutputMsg,
-    String resultInfo)
-  {
-    this(inType, inName, inOutputMsg, resultInfo, null);
-  }
-
-  public TestResultAdapter(
-    int inType,
-    String inName,
-    String inOutputMsg,
-    Throwable inThr)
-  {
-    this(inType, inName, inOutputMsg, null, inThr);
-  }
-
-  protected TestResultAdapter(
-    int inType,
-    String inName,
-    String inOutputMsg,
-    String inResultInfo,
-    Throwable inThr)
-  {
-    clearNonNull();
-    type = inType;
-    name = inName;
-    outputMsg = inOutputMsg;
-    resultInfo = inResultInfo;
-
-    if (inThr != null)
-      thr = new Throwable[] { inThr };
-    else
-      thr = null;
-
-    setOutcome();
-
-    if (isOutcome())
-    {
-      Boolean rc = null;
-      try
-      {
-
-        rc =
-          (Boolean) (Class
-            .forName("org.apache.beehive.test.tools.tch.core.AntProperties")
-            .getMethod("isStaggerResultTimeEnabled", null)
-            .invoke(null, null));
-      }
-      catch (Exception ex)
-      {
-        // if there's an exception just treat as if not set
-      }
-
-      if ((rc != null) && (rc.booleanValue() == true))
-      {
-        try
-        {
-          Thread.sleep(1);
-          timeStamp = new Date();
-        }
-        catch (InterruptedException ex)
-        {
-        }
-      }
-    }
-  }
-
-  public boolean hasThrowable()
-  {
-    return getThrowable() != null;
-  }
-
-  public boolean hasSucceeded()
-  {
-    return (getType() == TchConstants.SUCCESS_LEVEL_INT);
-  }
-
-  public boolean isProblem()
-  {
-    return (
-      getType() == TchConstants.FAILURE_LEVEL_INT
-        || getType() == TchConstants.ABORT_LEVEL_INT
-        || getType() == TchConstants.TIMEOUT_LEVEL_INT
-        || getType() == TchConstants.INVALIDATION_BATCH_LEVEL_INT
-        || getType() == TchConstants.SCRATCH_LEVEL_INT
-        || getType() == TchConstants.FRAMEABORT_LEVEL_INT);
-  }
-
-  public boolean isOrContainsProblems()
-  {
-    if (isProblem())
-      return true;
-    if (innerResults != null)
-    {
-      for (Iterator iter = getInnerResultsIterator(); iter.hasNext();)
-      {
-        if (((TestResult)iter.next()).isOrContainsProblems())
-        {
-          return true;
-        }
-      }
-    }
-    return false;
-  }
-
-  public boolean isOutcome()
-  {
-    return outcome;
-  }
-
-  public boolean isInform()
-  {
-    if (type == INFORM_LEVEL_INT)
-      return true;
-    else
-      return false;
-  }
-
-  public boolean isTimeout()
-  {
-    if (type == TIMEOUT_LEVEL_INT)
-      return true;
-    else
-      return false;
-  }
-  
-  public boolean isSkip()
-  {
-  	switch(type)
-  	{
-  		case SKIP_LEVEL_INT:
-  		case VALIDATION_SKIP_LEVEL_INT:
-  		case NESTED_SKIP_LEVEL_INT:
-  			return true;
-  		default:
-  			return false;
-  	}
-  }
-
-  public Throwable getThrowable()
-  {
-    if (thr == null || thr.length == 0)
-      return null;
-    return thr[0];
-  }
-
-  public Throwable[] getThrowableArray()
-  {
-    return thr;
-  }
-
-  public String getWinCommandLine()
-  {
-    return winCommandLine;
-  }
-
-  public String getCommandLine()
-  {
-    return commandLine;
-  }
-
-  public String getVerboseWinCommandLine()
-  {
-    return verboseWinCommandLine;
-  }
-
-  public String getVerboseCommandLine()
-  {
-    return verboseCommandLine;
-  }
-
-  public String getReplicationInfo()
-  {
-    return replicationInfo;
-  }
-
-  public int getType()
-  {
-    return type;
-  }
-
-  public String getTypeAsString()
-  {
-    return LoggerUtils.asLogLevelString(getType());
-  }
-
-  public String getResultInfo()
-  {
-    return resultInfo;
-  }
-
-  public Date getTimeStamp()
-  {
-    if (timeStamp == null)
-      timeStamp = new Date();
-    return timeStamp;
-  }
-
-  public void setResultInfo(String in)
-  {
-    this.resultInfo = in;
-  }
-
-  public void setTestCaseName(String in)
-  {
-    testCaseName = in;
-  }
-
-  public String getTestCaseName()
-  {
-    return testCaseName;
-  }
-
-  public void setSubtestName(String in)
-  {
-    subtestName = in;
-  }
-
-  public String getSubtestName()
-  {
-    return subtestName;
-  }
-
-  public void setProcessSummary(
-    String processName,
-    ProcessSummary processSummary)
-  {
-    if (processInfo == null)
-      processInfo = new HashMap();
-    processInfo.put(processName, processSummary);
-  }
-
-  public Map getProcessSummaryMap()
-  {
-    if (processInfo == null)
-      return null;
-    return Collections.unmodifiableMap(processInfo);
-  }
-
-  public Collection getMappedProcessNames()
-  {
-    if (processInfo == null)
-      return null;
-    return Collections.unmodifiableCollection(processInfo.keySet());
-  }
-
-  public Long getDuration()
-  {
-    return duration;
-  }
-
-  public String getOutputMessage()
-  {
-    return outputMsg;
-  }
-
-  public String getDetails()
-  {
-    return additionalInformation;
-  }
-
-  public void setDetails(String s)
-  {
-    additionalInformation = s;
-  }
-
-  public String getSourcePath()
-  {
-    return sourcePath;
-  }
-
-  public String getCustomPath()
-  {
-    return customPath;
-  }
-
-  public String getCallingChain()
-  {
-    return callingChain;
-  }
-
-  public String getTestUnitName()
-  {
-    return testUnitName;
-  }
-
-  public String getName()
-  {
-    return name;
-  }
-
-  public String getReviewState()
-  {
-    return reviewState;
-  }
-
-  public String getBugID()
-  {
-    return bugID;
-  }
-
-  public String getComments()
-  {
-    return comments;
-  }
-
-  public Map getParameters()
-  {
-    return params;
-  }
-
-  public Iterator getInnerResultsIterator()
-  {
-    if (innerResults != null)
-      return innerResults.iterator();
-    return null;
-  }
-
-  // methods from TestResultBean
-
-  public void setCommandLine(String in)
-  {
-    commandLine = in;
-  }
-
-  public void setWinCommandLine(String in)
-  {
-    winCommandLine = in;
-  }
-
-  public void setVerboseCommandLine(String in)
-  {
-    verboseCommandLine = in;
-  }
-
-  public void setVerboseWinCommandLine(String in)
-  {
-    verboseWinCommandLine = in;
-  }
-
-  public void setReplicationInfo(String in)
-  {
-    replicationInfo = in;
-  }
-
-  public void setThrowable(Throwable thr)
-  {
-    this.thr = new Throwable[] { thr };
-  }
-
-  public void setThrowableArray(Throwable[] in)
-  {
-    thr = in;
-  }
-
-  /**
-   * Set a Throwable on the test result. A filter can also be specified to filter out the portion
-   * of the Throwable's stack trace which we don't care about. Generally, this will filter out the
-   * portion of the stack trace which is internal to Tch. The user will generally not care about
-   * this.
-   * 
-   * @param thr A Throwable associated with the test result. Usually this will be an abort or failure result
-   * @param filter A Throwable containing a stack trace that should be a subset of the main Throwable's stack
-   * trace. This will be the portion that will be filtered out of the final stack trace output.
-   */
-  public void setThrowableWithFilter(Throwable thr, Throwable filter)
-  {
-    this.thr = new Throwable[] { thr };
-    this.filter = filter;
-  }
-
-  public void setFilterThrowable(Throwable filter)
-  {
-    this.filter = filter;
-  }
-
-  public Throwable getFilterThrowable()
-  {
-    return filter;
-  }
-
-  public String getStackTraces()
-  {
-    if (hasThrowable())
-    {
-      StringBuffer rtn = new StringBuffer();
-      for (int i = 0; i < thr.length; i++)
-      {
-        if (thr[i] != null)
-          rtn.append(getStackTraceInternal(thr[i]));
-        if (i < thr.length - 1)
-          rtn.append(sep).append(sep);
-      }
-      return rtn.toString();
-    }
-    else
-      return null;
-  }
-
-  public String getStackTrace()
-  {
-    return getStackTraceInternal(getThrowable());
-  }
-
-  private String getStackTraceInternal(Throwable inTh)
-  {
-    if (inTh != null)
-    {
-      if (filter != null)
-        return TchUtils.filterStack(inTh, filter);
-      else
-        return TchUtils.throwable2StackTrace(inTh);
-    }
-    else
-      return null;
-  }
-
-  public void setType(int type)
-  {
-    this.type = type;
-    setOutcome();
-  }
-
-  public void setOutcome(boolean outcome)
-  {
-    this.outcome = outcome;
-  }
-
-  public void setTimeStamp(Date d)
-  {
-    this.timeStamp = d;
-  }
-
-  public void setSourcePath(String s)
-  {
-    this.sourcePath = s;
-  }
-
-  public void setCustomPath(String s)
-  {
-    this.customPath = s;
-  }
-
-  public void setCallingChain(String s)
-  {
-    this.callingChain = s;
-  }
-
-  public void setOutputMsg(String s)
-  {
-    this.outputMsg = s;
-  }
-
-  public void setTestUnitName(String s)
-  {
-    this.testUnitName = s;
-  }
-
-  public void setName(String s)
-  {
-    this.name = s;
-  }
-
-  public void setReviewState(String s)
-  {
-    reviewState = s;
-  }
-
-  public void setBugID(String s)
-  {
-    bugID = s;
-  }
-
-  public void setComments(String s)
-  {
-    comments = s;
-  }
-
-  public void setParameters(Map m)
-  {
-    this.params = m;
-  }
-
-  public void addParameters(Map m)
-  {
-    if (m == null || m.keySet().isEmpty())
-      return;
-    if (params == null)
-      params = new HashMap();
-    params.putAll(m);
-  }
-
-  public void setDuration(Long l)
-  {
-    this.duration = l;
-  }
-
-  public void addInnerResult(TestResult res)
-  {
-    if (innerResults == null)
-      innerResults = new ArrayList();
-    innerResults.add(res);
-  }
-
-  /* 
-   * @see org.apache.beehive.test.tools.tch.util.TestResultBean#setErrorName(java.lang.String)
-   */
-  public void setErrorName(String in)
-  {
-    errorName = in;
-  }
-
-  /* 
-   * @see org.apache.beehive.test.tools.tch.util.TestResult#getErrorName()
-   */
-  public String getErrorName()
-  {
-    return errorName;
-
-  }
-
-  public void clear()
-  {
-    innerResults = null;
-    thr = null;
-    outcome = false;
-    type = -1;
-    debugLevel = -1;
-    timeStamp = null;
-    sourcePath = null;
-    customPath = null;
-    outputMsg = null;
-    testUnitName = null;
-    name = null;
-    reviewState = null;
-    bugID = null;
-    comments = null;
-    params = null;
-    duration = null;
-  }
-
-  // FIXME - get rid of this method, its confusing and meaningless
-  public void clearNonNull()
-  {
-    innerResults = new ArrayList();
-    thr = new Throwable[] { new Exception()};
-    outcome = false;
-    type = -1;
-    debugLevel = -1;
-    timeStamp = new Date();
-    sourcePath = "";
-    customPath = "";
-    outputMsg = "";
-    additionalInformation = "";
-    testUnitName = "";
-    name = "";
-    reviewState = "";
-    bugID = "";
-    comments = "";
-    params = new HashMap();
-    replicationAntFile = "";
-    commandLine = "";
-    winCommandLine = "";
-    verboseCommandLine = "";
-    verboseWinCommandLine = "";
-    replicationInfo = "";
-
-    // does not make sense to set this to a random number
-    duration = null;
-  }
-
-  // methods inherited from Object    
-
-  public String toString()
-  {
-    StringBuffer sb = new StringBuffer();
-    sb
-      .append("Name: ")
-      .append(getName())
-      .append("; ")
-      .append("Testunit: ")
-      .append(getTestUnitName())
-      .append("; ")
-      .append("Result: ")
-      .append(LoggerUtils.asLogLevelString(getType()))
-      .append("; ")
-      .append("Output: ")
-      .append(getOutputMessage())
-      .append("; ");
-    int numInner = (innerResults == null ? 0 : innerResults.size());
-    sb
-      .append("Num inner results: ")
-      .append(numInner)
-      .append("; ")
-      .append("is/HasProblems: ")
-      .append(isOrContainsProblems())
-      .append(";");
-    return sb.toString();
-  }
-
-  /**
-   * Depending on this results type, set the outcome boolean.
-   * Currently, successes, failures, aborts, skips, validation skips, timeouts, and
-   * test-not-found results are considered outcomes. Everything else (informs, scratches,
-   * etc.) are not considered outcomes.
-   */
-  private void setOutcome()
-  {
-    switch (type)
-    {
-      case SUCCESS_LEVEL_INT :
-      case FAILURE_LEVEL_INT :
-      case ABORT_LEVEL_INT :
-      case SKIP_LEVEL_INT :
-      case VALIDATION_SKIP_LEVEL_INT :
-      case TIMEOUT_LEVEL_INT :
-      case TEST_NOT_FOUND_INT :
-        outcome = true;
-        break;
-      default :
-        outcome = false;
-        break;
-    }
-  }
-
-  public String getFailureReplicationAntFile()
-  {
-    return replicationAntFile;
-  }
-
-  public void setFailureReplicationAntFile(String in)
-  {
-    replicationAntFile = in;
-  }
-
-  public int getDebugLevel()
-  {
-    return debugLevel;
-  }
-
-  public void setDebugLevel(int level)
-  {
-    debugLevel = level;
-  }
-}
+package org.apache.beehive.test.tools.tch.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.beehive.test.tools.tch.core.AntProperties;
+import org.apache.beehive.test.tools.tch.core.remote.ProcessSummary;
+import org.apache.beehive.test.tools.tch.logger.LoggerUtils;
+
+/**
+ * Dumb data container for a single test result and all associated metadata. 
+ * 
+ * @version 1.0, Mar 3, 2001
+ */
+public class TestResultAdapter implements TestResultBean
+{
+  private static final String sep = System.getProperty("line.separator");
+
+  private String replicationAntFile = null;
+  private List innerResults = null;
+  private Throwable[] thr = null;
+  private Throwable filter = null;
+  private boolean outcome = false;
+  private int type;
+
+  // an optional result value for additional data such as timing results
+  private String resultInfo;
+
+  private int debugLevel;
+
+  private Date timeStamp = null;
+
+  // the path to the test-file
+  // (in the BH context, this is Ant's Location)
+  private String sourcePath = null;
+
+  // optional additional path information
+  // (for example, for javatest this would be the fully qualified classname,
+  // cause that is useful information to see in the logs)
+  private String customPath = null;
+
+  // summary like information, goes into the .log
+  private String outputMsg = null;
+
+  // any additional info that would be helpful
+  // this is only displayed for problem results right now
+  private String additionalInformation = null;
+
+  private String testUnitName = null;
+  private String callingChain = null;
+
+  private String errorName = null;
+
+  // this is the test-point name
+  private String name = null;
+
+  // this is the test name, an abstract entity
+  // we can have many test-points of the same test case
+  private String testCaseName = null;
+
+  // this is used for a test that submits more than a single results 
+  // these subresults are identified by the subtest name
+  private String subtestName = null;
+
+  // command line related info
+  private String commandLine = null;
+  private String winCommandLine = null;
+
+  private String verboseCommandLine = null;
+  private String verboseWinCommandLine = null;
+
+  // generic information we print along with each 
+  // command line
+  private String replicationInfo = null;
+
+  // output processes under tests
+  // String (process name) --> ProcessSummary
+  private Map processInfo = null;
+
+  private String reviewState = null;
+  private String bugID = null;
+  private String comments = null;
+  private Map params = null;
+  private Long duration = null;
+
+  public TestResultAdapter()
+  {
+  }
+
+  public TestResultAdapter(int inType)
+  {
+    this(inType, null, null, null, null);
+  }
+
+  public TestResultAdapter(int inType, String inName)
+  {
+    this(inType, inName, null, null, null);
+  }
+
+  public TestResultAdapter(int inType, String inName, String inOutputMsg)
+  {
+    this(inType, inName, inOutputMsg, null, null);
+  }
+
+  public TestResultAdapter(
+    int inType,
+    String inName,
+    String inOutputMsg,
+    String resultInfo)
+  {
+    this(inType, inName, inOutputMsg, resultInfo, null);
+  }
+
+  public TestResultAdapter(
+    int inType,
+    String inName,
+    String inOutputMsg,
+    Throwable inThr)
+  {
+    this(inType, inName, inOutputMsg, null, inThr);
+  }
+
+  protected TestResultAdapter(
+    int inType,
+    String inName,
+    String inOutputMsg,
+    String inResultInfo,
+    Throwable inThr)
+  {
+    clearNonNull();
+    type = inType;
+    name = inName;
+    outputMsg = inOutputMsg;
+    resultInfo = inResultInfo;
+
+    if (inThr != null)
+      thr = new Throwable[] { inThr };
+    else
+      thr = null;
+
+    setOutcome();
+
+    if (isOutcome())
+    {
+      Boolean rc = null;
+      try
+      {
+
+        rc =
+          (Boolean) (Class
+            .forName("org.apache.beehive.test.tools.tch.core.AntProperties")
+            .getMethod("isStaggerResultTimeEnabled", null)
+            .invoke(null, null));
+      }
+      catch (Exception ex)
+      {
+        // if there's an exception just treat as if not set
+      }
+
+      if ((rc != null) && (rc.booleanValue() == true))
+      {
+        try
+        {
+          Thread.sleep(1);
+          timeStamp = new Date();
+        }
+        catch (InterruptedException ex)
+        {
+        }
+      }
+    }
+  }
+
+  public boolean hasThrowable()
+  {
+    return getThrowable() != null;
+  }
+
+  public boolean hasSucceeded()
+  {
+    return (getType() == TchConstants.SUCCESS_LEVEL_INT);
+  }
+
+  public boolean isProblem()
+  {
+    return (
+      getType() == TchConstants.FAILURE_LEVEL_INT
+        || getType() == TchConstants.ABORT_LEVEL_INT
+        || getType() == TchConstants.TIMEOUT_LEVEL_INT
+        || getType() == TchConstants.INVALIDATION_BATCH_LEVEL_INT
+        || getType() == TchConstants.SCRATCH_LEVEL_INT
+        || getType() == TchConstants.FRAMEABORT_LEVEL_INT);
+  }
+
+  public boolean isOrContainsProblems()
+  {
+    if (isProblem())
+      return true;
+    if (innerResults != null)
+    {
+      for (Iterator iter = getInnerResultsIterator(); iter.hasNext();)
+      {
+        if (((TestResult)iter.next()).isOrContainsProblems())
+        {
+          return true;
+        }
+      }
+    }
+    return false;
+  }
+
+  public boolean isOutcome()
+  {
+    return outcome;
+  }
+
+  public boolean isInform()
+  {
+    if (type == INFORM_LEVEL_INT)
+      return true;
+    else
+      return false;
+  }
+
+  public boolean isTimeout()
+  {
+    if (type == TIMEOUT_LEVEL_INT)
+      return true;
+    else
+      return false;
+  }
+  
+  public boolean isSkip()
+  {
+  	switch(type)
+  	{
+  		case SKIP_LEVEL_INT:
+  		case VALIDATION_SKIP_LEVEL_INT:
+  		case NESTED_SKIP_LEVEL_INT:
+  			return true;
+  		default:
+  			return false;
+  	}
+  }
+
+  public Throwable getThrowable()
+  {
+    if (thr == null || thr.length == 0)
+      return null;
+    return thr[0];
+  }
+
+  public Throwable[] getThrowableArray()
+  {
+    return thr;
+  }
+
+  public String getWinCommandLine()
+  {
+    return winCommandLine;
+  }
+
+  public String getCommandLine()
+  {
+    return commandLine;
+  }
+
+  public String getVerboseWinCommandLine()
+  {
+    return verboseWinCommandLine;
+  }
+
+  public String getVerboseCommandLine()
+  {
+    return verboseCommandLine;
+  }
+
+  public String getReplicationInfo()
+  {
+    return replicationInfo;
+  }
+
+  public int getType()
+  {
+    return type;
+  }
+
+  public String getTypeAsString()
+  {
+    return LoggerUtils.asLogLevelString(getType());
+  }
+
+  public String getResultInfo()
+  {
+    return resultInfo;
+  }
+
+  public Date getTimeStamp()
+  {
+    if (timeStamp == null)
+      timeStamp = new Date();
+    return timeStamp;
+  }
+
+  public void setResultInfo(String in)
+  {
+    this.resultInfo = in;
+  }
+
+  public void setTestCaseName(String in)
+  {
+    testCaseName = in;
+  }
+
+  public String getTestCaseName()
+  {
+    return testCaseName;
+  }
+
+  public void setSubtestName(String in)
+  {
+    subtestName = in;
+  }
+
+  public String getSubtestName()
+  {
+    return subtestName;
+  }
+
+  public void setProcessSummary(
+    String processName,
+    ProcessSummary processSummary)
+  {
+    if (processInfo == null)
+      processInfo = new HashMap();
+    processInfo.put(processName, processSummary);
+  }
+
+  public Map getProcessSummaryMap()
+  {
+    if (processInfo == null)
+      return null;
+    return Collections.unmodifiableMap(processInfo);
+  }
+
+  public Collection getMappedProcessNames()
+  {
+    if (processInfo == null)
+      return null;
+    return Collections.unmodifiableCollection(processInfo.keySet());
+  }
+
+  public Long getDuration()
+  {
+    return duration;
+  }
+
+  public String getOutputMessage()
+  {
+    return outputMsg;
+  }
+
+  public String getDetails()
+  {
+    return additionalInformation;
+  }
+
+  public void setDetails(String s)
+  {
+    additionalInformation = s;
+  }
+
+  public String getSourcePath()
+  {
+    return sourcePath;
+  }
+
+  public String getCustomPath()
+  {
+    return customPath;
+  }
+
+  public String getCallingChain()
+  {
+    return callingChain;
+  }
+
+  public String getTestUnitName()
+  {
+    return testUnitName;
+  }
+
+  public String getName()
+  {
+    return name;
+  }
+
+  public String getReviewState()
+  {
+    return reviewState;
+  }
+
+  public String getBugID()
+  {
+    return bugID;
+  }
+
+  public String getComments()
+  {
+    return comments;
+  }
+
+  public Map getParameters()
+  {
+    return params;
+  }
+
+  public Iterator getInnerResultsIterator()
+  {
+    if (innerResults != null)
+      return innerResults.iterator();
+    return null;
+  }
+
+  // methods from TestResultBean
+
+  public void setCommandLine(String in)
+  {
+    commandLine = in;
+  }
+
+  public void setWinCommandLine(String in)
+  {
+    winCommandLine = in;
+  }
+
+  public void setVerboseCommandLine(String in)
+  {
+    verboseCommandLine = in;
+  }
+
+  public void setVerboseWinCommandLine(String in)
+  {
+    verboseWinCommandLine = in;
+  }
+
+  public void setReplicationInfo(String in)
+  {
+    replicationInfo = in;
+  }
+
+  public void setThrowable(Throwable thr)
+  {
+    this.thr = new Throwable[] { thr };
+  }
+
+  public void setThrowableArray(Throwable[] in)
+  {
+    thr = in;
+  }
+
+  /**
+   * Set a Throwable on the test result. A filter can also be specified to filter out the portion
+   * of the Throwable's stack trace which we don't care about. Generally, this will filter out the
+   * portion of the stack trace which is internal to Tch. The user will generally not care about
+   * this.
+   * 
+   * @param thr A Throwable associated with the test result. Usually this will be an abort or failure result
+   * @param filter A Throwable containing a stack trace that should be a subset of the main Throwable's stack
+   * trace. This will be the portion that will be filtered out of the final stack trace output.
+   */
+  public void setThrowableWithFilter(Throwable thr, Throwable filter)
+  {
+    this.thr = new Throwable[] { thr };
+    this.filter = filter;
+  }
+
+  public void setFilterThrowable(Throwable filter)
+  {
+    this.filter = filter;
+  }
+
+  public Throwable getFilterThrowable()
+  {
+    return filter;
+  }
+
+  public String getStackTraces()
+  {
+    if (hasThrowable())
+    {
+      StringBuffer rtn = new StringBuffer();
+      for (int i = 0; i < thr.length; i++)
+      {
+        if (thr[i] != null)
+          rtn.append(getStackTraceInternal(thr[i]));
+        if (i < thr.length - 1)
+          rtn.append(sep).append(sep);
+      }
+      return rtn.toString();
+    }
+    else
+      return null;
+  }
+
+  public String getStackTrace()
+  {
+    return getStackTraceInternal(getThrowable());
+  }
+
+  private String getStackTraceInternal(Throwable inTh)
+  {
+    if (inTh != null)
+    {
+      if (filter != null)
+        return TchUtils.filterStack(inTh, filter);
+      else
+        return TchUtils.throwable2StackTrace(inTh);
+    }
+    else
+      return null;
+  }
+
+  public void setType(int type)
+  {
+    this.type = type;
+    setOutcome();
+  }
+
+  public void setOutcome(boolean outcome)
+  {
+    this.outcome = outcome;
+  }
+
+  public void setTimeStamp(Date d)
+  {
+    this.timeStamp = d;
+  }
+
+  public void setSourcePath(String s)
+  {
+    this.sourcePath = s;
+  }
+
+  public void setCustomPath(String s)
+  {
+    this.customPath = s;
+  }
+
+  public void setCallingChain(String s)
+  {
+    this.callingChain = s;
+  }
+
+  public void setOutputMsg(String s)
+  {
+    this.outputMsg = s;
+  }
+
+  public void setTestUnitName(String s)
+  {
+    this.testUnitName = s;
+  }
+
+  public void setName(String s)
+  {
+    this.name = s;
+  }
+
+  public void setReviewState(String s)
+  {
+    reviewState = s;
+  }
+
+  public void setBugID(String s)
+  {
+    bugID = s;
+  }
+
+  public void setComments(String s)
+  {
+    comments = s;
+  }
+
+  public void setParameters(Map m)
+  {
+    this.params = m;
+  }
+
+  public void addParameters(Map m)
+  {
+    if (m == null || m.keySet().isEmpty())
+      return;
+    if (params == null)
+      params = new HashMap();
+    params.putAll(m);
+  }
+
+  public void setDuration(Long l)
+  {
+    this.duration = l;
+  }
+
+  public void addInnerResult(TestResult res)
+  {
+    if (innerResults == null)
+      innerResults = new ArrayList();
+    innerResults.add(res);
+  }
+
+  /* 
+   * @see org.apache.beehive.test.tools.tch.util.TestResultBean#setErrorName(java.lang.String)
+   */
+  public void setErrorName(String in)
+  {
+    errorName = in;
+  }
+
+  /* 
+   * @see org.apache.beehive.test.tools.tch.util.TestResult#getErrorName()
+   */
+  public String getErrorName()
+  {
+    return errorName;
+
+  }
+
+  public void clear()
+  {
+    innerResults = null;
+    thr = null;
+    outcome = false;
+    type = -1;
+    debugLevel = -1;
+    timeStamp = null;
+    sourcePath = null;
+    customPath = null;
+    outputMsg = null;
+    testUnitName = null;
+    name = null;
+    reviewState = null;
+    bugID = null;
+    comments = null;
+    params = null;
+    duration = null;
+  }
+
+  // FIXME - get rid of this method, its confusing and meaningless
+  public void clearNonNull()
+  {
+    innerResults = new ArrayList();
+    thr = new Throwable[] { new Exception()};
+    outcome = false;
+    type = -1;
+    debugLevel = -1;
+    timeStamp = new Date();
+    sourcePath = "";
+    customPath = "";
+    outputMsg = "";
+    additionalInformation = "";
+    testUnitName = "";
+    name = "";
+    reviewState = "";
+    bugID = "";
+    comments = "";
+    params = new HashMap();
+    replicationAntFile = "";
+    commandLine = "";
+    winCommandLine = "";
+    verboseCommandLine = "";
+    verboseWinCommandLine = "";
+    replicationInfo = "";
+
+    // does not make sense to set this to a random number
+    duration = null;
+  }
+
+  // methods inherited from Object    
+
+  public String toString()
+  {
+    StringBuffer sb = new StringBuffer();
+    sb
+      .append("Name: ")
+      .append(getName())
+      .append("; ")
+      .append("Testunit: ")
+      .append(getTestUnitName())
+      .append("; ")
+      .append("Result: ")
+      .append(LoggerUtils.asLogLevelString(getType()))
+      .append("; ")
+      .append("Output: ")
+      .append(getOutputMessage())
+      .append("; ");
+    int numInner = (innerResults == null ? 0 : innerResults.size());
+    sb
+      .append("Num inner results: ")
+      .append(numInner)
+      .append("; ")
+      .append("is/HasProblems: ")
+      .append(isOrContainsProblems())
+      .append(";");
+    return sb.toString();
+  }
+
+  /**
+   * Depending on this results type, set the outcome boolean.
+   * Currently, successes, failures, aborts, skips, validation skips, timeouts, and
+   * test-not-found results are considered outcomes. Everything else (informs, scratches,
+   * etc.) are not considered outcomes.
+   */
+  private void setOutcome()
+  {
+    switch (type)
+    {
+      case SUCCESS_LEVEL_INT :
+      case FAILURE_LEVEL_INT :
+      case ABORT_LEVEL_INT :
+      case SKIP_LEVEL_INT :
+      case VALIDATION_SKIP_LEVEL_INT :
+      case TIMEOUT_LEVEL_INT :
+      case TEST_NOT_FOUND_INT :
+        outcome = true;
+        break;
+      default :
+        outcome = false;
+        break;
+    }
+  }
+
+  public String getFailureReplicationAntFile()
+  {
+    return replicationAntFile;
+  }
+
+  public void setFailureReplicationAntFile(String in)
+  {
+    replicationAntFile = in;
+  }
+
+  public int getDebugLevel()
+  {
+    return debugLevel;
+  }
+
+  public void setDebugLevel(int level)
+  {
+    debugLevel = level;
+  }
+}

Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/TestResultAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/TestResultBean.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/TestResultBean.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/TestResultBean.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/TestResultBean.java Fri Aug 12 08:12:28 2005
@@ -1,102 +1,102 @@
-package org.apache.beehive.test.tools.tch.util;
-
-import java.util.Date;
-import java.util.Map;
-
-import org.apache.beehive.test.tools.tch.core.remote.ProcessSummary;
-
-/**
- * Holds TestResult information.
- * <p>
- * This only contains the setter() methods,
- * and extends TestResult to get the getter() methods.
- * 
- * @version 1.0, Mar 3, 2001
- */
-public interface TestResultBean extends TestResult
-{
-  /** sets the Throwable contained in it */
-  public void setThrowable(Throwable thr);
-  
-  public void setThrowableArray(Throwable[] in);
-
-  /** sets the Throwable contained in it, plus the Throwable to filter out the bottom of the stack trace */
-  public void setThrowableWithFilter(Throwable thr, Throwable filter);
-
-  public void setFilterThrowable(Throwable filter);
-
-  /** sets the type of the result */
-  public void setType(int type);
-
-  /** sets whether this is an outcome result or not */
-  public void setOutcome(boolean outcome);
-
-  /** sets the timestamp */
-  public void setTimeStamp(Date d);
-
-  /** sets the path of the test */
-  public void setSourcePath(String s);
-
-  /** sets the path of the test */
-  public void setCustomPath(String s);
-
-  /** Summary message that explains this result */
-  public void setOutputMsg(String s);
-  
-  /** Any additional information that is useful to keep */
-  public void setDetails(String s);
-
-  public void setResultInfo(String s);
-
-  /** sets the test unit name */
-  public void setTestUnitName(String s);
-
-//  public void setProcessOutput(String processName, String processOutput);
-
-  public void setProcessSummary(String processName, ProcessSummary processSummary);
-
-  public void setSubtestName(String s);
-
-  public void setCallingChain(String s);
-
-  /** sets the test name (test-point name) */
-  public void setName(String s);
-
-  /** sets the test case name */
-  public void setTestCaseName(String s);
-
-  /** sets the review state this test is in */
-  public void setReviewState(String s);
-
-  /** sets the bug id associated with this test */
-  public void setBugID(String s);
-
-  /** sets comments for this test */
-  public void setComments(String s);
-
-  /** sets the parameters accessed by this test */
-  public void setParameters(Map m);
-
-  /** adds to the parameters accessed by this test */
-  public void addParameters(Map m);
-
-  /** sets the duration */
-  public void setDuration(Long l);
-
-  /** add an inner result */
-  public void addInnerResult(TestResult tres);
-
-  public void setErrorName(String in);
-
-  public void clear();
-  public void clearNonNull();
-
-  public void setCommandLine(String in);
-  public void setWinCommandLine(String in);
-  public void setVerboseCommandLine(String in);
-  public void setVerboseWinCommandLine(String in);
-  
-  public void setReplicationInfo(String in);
-  
-  public void setFailureReplicationAntFile(String in);
-}
+package org.apache.beehive.test.tools.tch.util;
+
+import java.util.Date;
+import java.util.Map;
+
+import org.apache.beehive.test.tools.tch.core.remote.ProcessSummary;
+
+/**
+ * Holds TestResult information.
+ * <p>
+ * This only contains the setter() methods,
+ * and extends TestResult to get the getter() methods.
+ * 
+ * @version 1.0, Mar 3, 2001
+ */
+public interface TestResultBean extends TestResult
+{
+  /** sets the Throwable contained in it */
+  public void setThrowable(Throwable thr);
+  
+  public void setThrowableArray(Throwable[] in);
+
+  /** sets the Throwable contained in it, plus the Throwable to filter out the bottom of the stack trace */
+  public void setThrowableWithFilter(Throwable thr, Throwable filter);
+
+  public void setFilterThrowable(Throwable filter);
+
+  /** sets the type of the result */
+  public void setType(int type);
+
+  /** sets whether this is an outcome result or not */
+  public void setOutcome(boolean outcome);
+
+  /** sets the timestamp */
+  public void setTimeStamp(Date d);
+
+  /** sets the path of the test */
+  public void setSourcePath(String s);
+
+  /** sets the path of the test */
+  public void setCustomPath(String s);
+
+  /** Summary message that explains this result */
+  public void setOutputMsg(String s);
+  
+  /** Any additional information that is useful to keep */
+  public void setDetails(String s);
+
+  public void setResultInfo(String s);
+
+  /** sets the test unit name */
+  public void setTestUnitName(String s);
+
+//  public void setProcessOutput(String processName, String processOutput);
+
+  public void setProcessSummary(String processName, ProcessSummary processSummary);
+
+  public void setSubtestName(String s);
+
+  public void setCallingChain(String s);
+
+  /** sets the test name (test-point name) */
+  public void setName(String s);
+
+  /** sets the test case name */
+  public void setTestCaseName(String s);
+
+  /** sets the review state this test is in */
+  public void setReviewState(String s);
+
+  /** sets the bug id associated with this test */
+  public void setBugID(String s);
+
+  /** sets comments for this test */
+  public void setComments(String s);
+
+  /** sets the parameters accessed by this test */
+  public void setParameters(Map m);
+
+  /** adds to the parameters accessed by this test */
+  public void addParameters(Map m);
+
+  /** sets the duration */
+  public void setDuration(Long l);
+
+  /** add an inner result */
+  public void addInnerResult(TestResult tres);
+
+  public void setErrorName(String in);
+
+  public void clear();
+  public void clearNonNull();
+
+  public void setCommandLine(String in);
+  public void setWinCommandLine(String in);
+  public void setVerboseCommandLine(String in);
+  public void setVerboseWinCommandLine(String in);
+  
+  public void setReplicationInfo(String in);
+  
+  public void setFailureReplicationAntFile(String in);
+}

Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/TestResultBean.java
------------------------------------------------------------------------------
    svn:eol-style = native