ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sbaill...@apache.org
Subject cvs commit: jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit TestRunListener.java
Date Wed, 30 Jan 2002 21:05:53 GMT
sbailliez    02/01/30 13:05:53

  Modified:    proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter
                        BaseFormatter.java BriefFormatter.java
                        FilterFormatter.java FilterStackFormatter.java
                        PlainFormatter.java XMLFormatter.java
               proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote
                        MessageReader.java Server.java TestRunner.java
               proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit
                        TestRunListener.java
  Log:
  Prepare for listener changes and event types.
  
  Revision  Changes    Path
  1.6       +16 -18    jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/BaseFormatter.java
  
  Index: BaseFormatter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/BaseFormatter.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BaseFormatter.java	27 Jan 2002 02:11:59 -0000	1.5
  +++ BaseFormatter.java	30 Jan 2002 21:05:52 -0000	1.6
  @@ -56,6 +56,7 @@
   import java.util.Properties;
   
   import org.apache.tools.ant.BuildException;
  +import org.apache.tools.ant.taskdefs.optional.junit.remote.TestRunEvent;
   
   /**
    * Provide a common set of attributes and methods to factorize
  @@ -81,42 +82,39 @@
           close();
       }
   
  -    public void onTestStdOutLine(String testname, String line) {
  +    public void onTestStarted(TestRunEvent evt) {
  +        runCount++;
       }
   
  -    public void onTestStdErrLine(String testname, String line) {
  +    public void onTestEnded(TestRunEvent evt) {
       }
   
  -    public void onTestRunSystemProperties(Properties props) {
  +    public void onTestFailure(TestRunEvent evt) {
  +        failureCount++;
       }
   
  -    public void onTestStarted(String testname) {
  +    public void onTestError(TestRunEvent evt) {
  +        errorCount++;
       }
   
  -    public void onTestEnded(String testname) {
  +    public void onSuiteStarted(TestRunEvent evt) {
       }
   
  -    public void onTestFailed(int status, String testname, String trace) {
  -        if (status == STATUS_ERROR) {
  -            errorCount++;
  -        } else if (status == STATUS_FAILURE) {
  -            failureCount++;
  -        }
  +    public void onSuiteEnded(TestRunEvent evt) {
       }
   
  -    public void onTestRunStarted(int testcount) {
  -        runCount = testcount;
  +    public void onRunStarted(TestRunEvent evt) {
       }
   
  -    public void onTestRunEnded(long elapsedtime) {
  -        finished(elapsedtime);
  +    public void onRunEnded(TestRunEvent evt) {
  +        finished();
       }
   
  -    public void onTestRunStopped(long elapsedtime) {
  -        finished(elapsedtime);
  +    public void onRunStopped(TestRunEvent evt) {
  +        finished();
       }
   
  -    protected void finished(long elapsedtime) {
  +    protected void finished() {
           close();
       }
   
  
  
  
  1.7       +9 -8      jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/BriefFormatter.java
  
  Index: BriefFormatter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/BriefFormatter.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- BriefFormatter.java	27 Jan 2002 02:11:59 -0000	1.6
  +++ BriefFormatter.java	30 Jan 2002 21:05:52 -0000	1.7
  @@ -55,6 +55,7 @@
   
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  +import org.apache.tools.ant.taskdefs.optional.junit.remote.TestRunEvent;
   
   /**
    * Display additional messages from a <tt>SummaryFormatter</tt>
  @@ -67,15 +68,15 @@
       private final static Resources RES =
               ResourceManager.getPackageResources(BriefFormatter.class);
   
  -    public void onTestFailed(int status, String testname, String trace) {
  -        String msg = null;
  -        if (status == STATUS_ERROR) {
  -            msg = RES.getString("brief.status-error.msg", testname, trace);
  -        } else {
  -            msg = RES.getString("brief.status-failure.msg", testname, trace);
  -        }
  +    public void onTestFailure(TestRunEvent evt) {
  +        String msg = RES.getString("brief.status-failure.msg", evt.getName(), evt.getStackTrace());
           getWriter().println(msg);
  -        super.onTestFailed(status, testname, trace);
  +        super.onTestFailure(evt);
       }
   
  +    public void onTestError(TestRunEvent evt) {
  +        String msg = RES.getString("brief.status-error.msg", evt.getName(), evt.getStackTrace());
  +        getWriter().println(msg);
  +        super.onTestError(evt);
  +    }
   }
  
  
  
  1.6       +19 -18    jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/FilterFormatter.java
  
  Index: FilterFormatter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/FilterFormatter.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FilterFormatter.java	27 Jan 2002 02:11:59 -0000	1.5
  +++ FilterFormatter.java	30 Jan 2002 21:05:52 -0000	1.6
  @@ -56,6 +56,7 @@
   import java.util.Properties;
   
   import org.apache.tools.ant.BuildException;
  +import org.apache.tools.ant.taskdefs.optional.junit.remote.TestRunEvent;
   
   /**
    * A base class that can be used to filter data.
  @@ -75,40 +76,40 @@
           formatter.init(props);
       }
   
  -    public void onTestStdOutLine(String testname, String line) {
  -        formatter.onTestStdOutLine(testname, line);
  +    public void onSuiteStarted(TestRunEvent evt) {
  +        formatter.onSuiteStarted(evt);
       }
   
  -    public void onTestStdErrLine(String testname, String line) {
  -        formatter.onTestStdErrLine(testname, line);
  +    public void onSuiteEnded(TestRunEvent evt) {
  +        formatter.onSuiteEnded(evt);
       }
   
  -    public void onTestStarted(String testname) {
  -        formatter.onTestStarted(testname);
  +    public void onTestStarted(TestRunEvent evt) {
  +        formatter.onTestStarted(evt);
       }
   
  -    public void onTestEnded(String testname) {
  -        formatter.onTestEnded(testname);
  +    public void onTestEnded(TestRunEvent evt) {
  +        formatter.onTestEnded(evt);
       }
   
  -    public void onTestFailed(int status, String testname, String trace) {
  -        formatter.onTestFailed(status, testname, trace);
  +    public void onTestFailure(TestRunEvent evt) {
  +        formatter.onTestFailure(evt);
       }
   
  -    public void onTestRunSystemProperties(Properties props) {
  -        formatter.onTestRunSystemProperties(props);
  +    public void onTestError(TestRunEvent evt) {
  +        formatter.onTestError(evt);
       }
   
  -    public void onTestRunStarted(int testcount) {
  -        formatter.onTestRunStarted(testcount);
  +    public void onRunStarted(TestRunEvent evt) {
  +        formatter.onRunStarted(evt);
       }
   
  -    public void onTestRunEnded(long elapsedtime) {
  -        formatter.onTestRunEnded(elapsedtime);
  +    public void onRunEnded(TestRunEvent evt) {
  +        formatter.onRunEnded(evt);
       }
   
  -    public void onTestRunStopped(long elapsedtime) {
  -        formatter.onTestRunEnded(elapsedtime);
  +    public void onRunStopped(TestRunEvent evt) {
  +        formatter.onRunEnded(evt);
       }
   
       /** set the wrapped formatter */
  
  
  
  1.5       +15 -3     jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/FilterStackFormatter.java
  
  Index: FilterStackFormatter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/FilterStackFormatter.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FilterStackFormatter.java	13 Jan 2002 23:40:11 -0000	1.4
  +++ FilterStackFormatter.java	30 Jan 2002 21:05:52 -0000	1.5
  @@ -56,6 +56,7 @@
   import java.util.StringTokenizer;
   
   import org.apache.tools.ant.util.StringUtils;
  +import org.apache.tools.ant.taskdefs.optional.junit.remote.TestRunEvent;
   
   /**
    * Filtered Formatter that strips out unwanted stack frames from the full
  @@ -99,7 +100,19 @@
           super(formatter);
       }
   
  -    public void onTestFailed(int status, String testname, String trace) {
  +    public void onTestFailure(TestRunEvent evt) {
  +        String filteredTrace = filter(evt.getStackTrace());
  +        evt.setStackTrace(filteredTrace);
  +        super.onTestFailure(evt);
  +    }
  +
  +    public void onTestError(TestRunEvent evt) {
  +        String filteredTrace = filter(evt.getStackTrace());
  +        evt.setStackTrace(filteredTrace);
  +        super.onTestFailure(evt);
  +    }
  +
  +    protected String filter(String trace){
           StringTokenizer st = new StringTokenizer(trace, "\r\n");
           StringBuffer buf = new StringBuffer(trace.length());
           while (st.hasMoreTokens()) {
  @@ -108,9 +121,8 @@
                   buf.append(line).append(StringUtils.LINE_SEP);
               }
           }
  -        super.onTestFailed(status, testname, buf.toString());
  +        return buf.toString();
       }
  -
       /**
        * Check whether or not the line should be accepted.
        * @param the line to be check for acceptance.
  
  
  
  1.2       +22 -19    jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/PlainFormatter.java
  
  Index: PlainFormatter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/PlainFormatter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PlainFormatter.java	27 Jan 2002 02:11:59 -0000	1.1
  +++ PlainFormatter.java	30 Jan 2002 21:05:52 -0000	1.2
  @@ -55,6 +55,8 @@
   
   import java.util.Properties;
   
  +import org.apache.tools.ant.taskdefs.optional.junit.remote.TestRunEvent;
  +
   /**
    * Default formatter to text.
    *
  @@ -62,38 +64,39 @@
    */
   public class PlainFormatter extends BaseStreamFormatter {
   
  -    public void onTestStarted(String testname) {
  -        getWriter().println("Started " + testname);
  -    }
  -
  -    public void onTestEnded(String testname) {
  -        getWriter().println("Ended " + testname);
  +    public void onSuiteStarted(TestRunEvent evt) {
  +        getWriter().println("  suite: " + evt.getName());
  +        super.onSuiteStarted(evt);
       }
   
  -    public void onTestFailed(int status, String testname, String trace) {
  -        getWriter().println(testname + " failed with status " + status);
  -        getWriter().println(trace);
  +    public void onSuiteEnded(TestRunEvent evt) {
  +        getWriter().println("  end suite");
  +        super.onSuiteEnded(evt);
       }
   
  -    public void onTestRunSystemProperties(Properties props) {
  -        getWriter().println("properties: " + props);
  +    public void onTestStarted(TestRunEvent evt) {
  +        getWriter().println("    running test: " + evt.getName());
       }
   
  -    public void onTestRunStarted(int testcount) {
  -        getWriter().println("testsuite:  " + testcount);
  +    public void onTestEnded(TestRunEvent evt) {
  +        getWriter().println("    success: " + evt.getName());
       }
   
  -    public void onTestStdOutLine(String testname, String line) {
  +    public void onTestFailure(TestRunEvent evt) {
  +        getWriter().println("    failure: " + evt.getName());
  +        getWriter().println(evt.getStackTrace());
       }
   
  -    public void onTestStdErrLine(String testname, String line) {
  +    public void onTestError(TestRunEvent evt) {
  +        getWriter().println("    error: " + evt.getName());
  +        getWriter().println(evt.getStackTrace());
       }
   
  -    public void onTestRunEnded(long elapsedtime) {
  -        getWriter().println("testsuite ended after: " + elapsedtime);
  +    public void onRunEnded(TestRunEvent evt) {
  +        getWriter().println("run ended");
       }
   
  -    public void onTestRunStopped(long elapsedtime) {
  -        getWriter().println("testsuite stopped after: " + elapsedtime);
  +    public void onRunStopped(TestRunEvent evt) {
  +        getWriter().println("run stopped");
       }
   }
  
  
  
  1.7       +33 -36    jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/XMLFormatter.java
  
  Index: XMLFormatter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/formatter/XMLFormatter.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XMLFormatter.java	27 Jan 2002 18:29:20 -0000	1.6
  +++ XMLFormatter.java	30 Jan 2002 21:05:52 -0000	1.7
  @@ -64,6 +64,7 @@
   
   import org.apache.tools.ant.util.DOMElementWriter;
   import org.apache.tools.ant.BuildException;
  +import org.apache.tools.ant.taskdefs.optional.junit.remote.TestRunEvent;
   
   /**
    * XML Formatter. Due to the nature of the XML we are forced to store
  @@ -140,67 +141,63 @@
       /** Timing helper. */
       private Hashtable testStarts = new Hashtable();
   
  -    public void onTestStarted(String testname) {
  +    public void onTestStarted(TestRunEvent evt) {
           //@fixme, eh, a testname only can obviouslly be a duplicate...
  -        testStarts.put(testname, new Long(System.currentTimeMillis()));
  +        testStarts.put(evt.getName(), evt);
           Element currentTest = doc.createElement(TESTCASE);
  -        currentTest.setAttribute(ATTR_NAME, testname);
  +        currentTest.setAttribute(ATTR_NAME, evt.getName());
           rootElement.appendChild(currentTest);
  -        testElements.put(testname, currentTest);
  -        super.onTestStarted(testname);
  +        testElements.put(evt.getName(), currentTest);
  +        super.onTestStarted(evt);
  +        removeEvent(evt);
       }
   
  -    public void onTestEnded(String testname) {
  -        Element currentTest = (Element) testElements.get(testname);
  +    public void onTestEnded(TestRunEvent evt) {
  +        Element currentTest = (Element) testElements.get(evt);
           // with a TestSetup, startTest and endTest are not called.
           if (currentTest == null) {
  -            onTestStarted(testname);
  -            currentTest = (Element) testElements.get(testname);
  +            onTestStarted(evt);
  +            currentTest = (Element) testElements.get(evt.getName());
           }
  -        Long l = (Long) testStarts.get(testname);
  -        float time = ((System.currentTimeMillis() - l.longValue()) / 1000.0f);
  +        TestRunEvent start = (TestRunEvent)testStarts.get(evt);
  +        float time = ((evt.getTimeStamp() - start.getTimeStamp()) / 1000.0f);
           currentTest.setAttribute(ATTR_TIME, Float.toString(time));
  -        super.onTestEnded(testname);
  -        // remove the test objects
  -        //testStarts.remove(testname);
  -        //testElements.remove(testname);
  +        super.onTestEnded(evt);
  +        removeEvent(evt);
       }
   
  -    public void onTestFailed(int status, String testname, String trace) {
  -        if (testname != null) {
  -            onTestEnded(testname);
  -        }
  -        String type = status == STATUS_FAILURE ? FAILURE : ERROR;
  +    public void onTestFailure(TestRunEvent evt) {
  +        String type = evt == evt.getType() == TestRunEvent.TEST_FAILURE ? FAILURE : ERROR;
           Element nested = doc.createElement(type);
  -        Element currentTest = null;
  -        if (testname != null) {
  -            currentTest = (Element) testElements.get(testname);
  -        } else {
  -            currentTest = rootElement;
  -        }
  -
  +        Element currentTest = (Element) testElements.get(evt.getName());
           currentTest.appendChild(nested);
   
  -        String[] args = parseFirstLine(trace);
  +        String[] args = parseFirstLine(evt.getStackTrace());
           if (args[1] != null && args[1].length() > 0) {
               nested.setAttribute(ATTR_MESSAGE, args[1]);
           }
           nested.setAttribute(ATTR_TYPE, args[0]);
  -        Text text = doc.createTextNode(trace);
  +        Text text = doc.createTextNode(evt.getStackTrace());
           nested.appendChild(text);
  -        super.onTestFailed(status, testname, trace);
  +        super.onTestFailure(evt);
  +        removeEvent(evt);
  +    }
  +
  +    protected void removeEvent(TestRunEvent evt){
  +        testStarts.remove(evt.getName());
  +        testElements.remove(evt.getName());
       }
   
  -    public void onTestRunStarted(int testcount) {
  -        super.onTestRunStarted(testcount);
  +    public void onRunStarted(TestRunEvent evt) {
  +        super.onRunStarted(evt);
       }
   
  -    public void onTestRunEnded(long elapsedtime) {
  -        super.onTestRunEnded(elapsedtime);
  +    public void onRunEnded(TestRunEvent evt) {
  +        super.onRunEnded(evt);
       }
   
  -    public void onTestRunStopped(long elapsedtime) {
  -        super.onTestRunStopped(elapsedtime);
  +    public void onRunStopped(TestRunEvent evt) {
  +        super.onRunStopped(evt);
       }
   
       protected void close() {
  
  
  
  1.7       +4 -4      jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/MessageReader.java
  
  Index: MessageReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/MessageReader.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MessageReader.java	14 Jan 2002 23:12:25 -0000	1.6
  +++ MessageReader.java	30 Jan 2002 21:05:53 -0000	1.7
  @@ -203,7 +203,7 @@
       protected void notifyTestFailed(int kind, String testname, String trace) {
           synchronized (listeners) {
               for (int i = 0; i < listeners.size(); i++) {
  -                ((TestRunListener) listeners.elementAt(i)).onTestFailed(kind, testname,
trace);
  +                ((TestRunListener) listeners.elementAt(i)).onTestFailure(kind);
               }
           }
       }
  @@ -211,7 +211,7 @@
       protected void notifyTestSuiteStarted(int count) {
           synchronized (listeners) {
               for (int i = 0; i < listeners.size(); i++) {
  -                ((TestRunListener) listeners.elementAt(i)).onTestRunStarted(count);
  +                ((TestRunListener) listeners.elementAt(i)).onRunStarted(count);
               }
           }
       }
  @@ -219,7 +219,7 @@
       protected void notifyTestSuiteEnded(long elapsedtime) {
           synchronized (listeners) {
               for (int i = 0; i < listeners.size(); i++) {
  -                ((TestRunListener) listeners.elementAt(i)).onTestRunEnded(elapsedtime);
  +                ((TestRunListener) listeners.elementAt(i)).onRunEnded(elapsedtime);
               }
           }
       }
  @@ -227,7 +227,7 @@
       protected void notifyTestSuiteStopped(long elapsedtime) {
           synchronized (listeners) {
               for (int i = 0; i < listeners.size(); i++) {
  -                ((TestRunListener) listeners.elementAt(i)).onTestRunStopped(elapsedtime);
  +                ((TestRunListener) listeners.elementAt(i)).onRunStopped(elapsedtime);
               }
           }
       }
  
  
  
  1.6       +14 -17    jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/Server.java
  
  Index: Server.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/Server.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Server.java	14 Jan 2002 23:12:25 -0000	1.5
  +++ Server.java	30 Jan 2002 21:05:53 -0000	1.6
  @@ -57,8 +57,6 @@
   import java.net.ServerSocket;
   import java.net.Socket;
   
  -import org.apache.tools.ant.taskdefs.optional.junit.TestRunListener;
  -
   /**
    * The server that will receive events from a remote client.
    *
  @@ -83,10 +81,9 @@
       private Socket client;
   
       /** the reader in charge of interpreting messages from the client */
  -    private MessageReader reader = new MessageReader();
  +    private Messenger messenger;
   
  -    /** writer used to send message to clients */
  -    private MessageWriter writer;
  +    private EventDispatcher dispatcher = new EventDispatcher();
   
       public Server(int port) {
           this.port = port;
  @@ -102,7 +99,7 @@
        * @param listener a instance of a listener.
        */
       public void addListener(TestRunListener listener) {
  -        reader.addListener(listener);
  +        dispatcher.addListener(listener);
       }
   
       /**
  @@ -110,7 +107,7 @@
        * @param listener a instance of a listener.
        */
       public void removeListener(TestRunListener listener) {
  -        reader.removeListener(listener);
  +        dispatcher.removeListener(listener);
       }
   
       /** return whether there is a client running or not */
  @@ -127,19 +124,16 @@
       /** cancel the connection to the client */
       public void cancel() {
           if (isRunning()) {
  -            writer.sendMessage(MessageIds.TEST_STOP);
  +            TestRunEvent evt = new TestRunEvent(new Integer(-1), TestRunEvent.RUN_STOP);
  +            messenger.writeEvent(evt);
           }
       }
   
       /** shutdown the server and any running client */
       public void shutdown() {
  -        if (writer != null) {
  -            writer.close();
  -            writer = null;
  -        }
  -        if (reader != null) {
  -            //@fixme what about the stream ?
  -            reader = null;
  +        if (messenger != null) {
  +            messenger.close();
  +            messenger = null;
           }
           try {
               if (client != null) {
  @@ -166,8 +160,11 @@
               try {
                   server = new ServerSocket(port);
                   client = server.accept();
  -                writer = new MessageWriter(client.getOutputStream());
  -                reader.process(client.getInputStream());
  +                messenger = new Messenger(client.getInputStream(), client.getOutputStream());
  +                TestRunEvent evt = null;
  +                while ( (evt = messenger.read()) != null ) {
  +                    dispatcher.dispatchEvent(evt);
  +                }
               } catch (IOException e) {
                   //@fixme this stacktrace might be normal when closing
                   // the socket. So decompose the above in distinct steps
  
  
  
  1.7       +26 -31    jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/TestRunner.java
  
  Index: TestRunner.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/TestRunner.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestRunner.java	27 Jan 2002 18:29:57 -0000	1.6
  +++ TestRunner.java	30 Jan 2002 21:05:53 -0000	1.7
  @@ -61,6 +61,7 @@
   import java.util.Properties;
   import java.util.StringTokenizer;
   import java.util.Vector;
  +import java.util.Random;
   
   import junit.framework.AssertionFailedError;
   import junit.framework.Test;
  @@ -86,6 +87,9 @@
    */
   public class TestRunner implements TestListener {
   
  +    /** unique identifier for the runner */
  +    private final Integer id = new Integer( (new Random()).nextInt() );
  +
       /** host to connect to */
       private String host = "127.0.0.1";
   
  @@ -104,10 +108,7 @@
       private Socket clientSocket;
   
       /** writer to send message to the server */
  -    private MessageWriter writer;
  -
  -    /** reader to listen for a shutdown from the server */
  -    private BufferedReader reader;
  +    private Messenger messenger;
   
       /** bean constructor */
       public TestRunner() {
  @@ -152,9 +153,9 @@
       private class StopThread extends Thread {
           public void run() {
               try {
  -                String line = null;
  -                if ((line = reader.readLine()) != null) {
  -                    if (line.startsWith(MessageIds.TEST_STOP)) {
  +                TestRunEvent evt = null;
  +                if ((evt = messenger.read()) != null) {
  +                    if (evt.getType() == TestRunEvent.RUN_STOP) {
                           TestRunner.this.stop();
                       }
                   }
  @@ -298,26 +299,26 @@
           // count all testMethods and inform TestRunListeners
           int count = countTests(suites);
           log("Total tests to run: " + count);
  -        writer.notifyTestRunStarted(count);
  -
  -        // send system properties to know for the JVM status
  -        writer.notifySystemProperties();
  +        fireEvent(new TestRunEvent(id, TestRunEvent.RUN_STARTED));
   
           long startTime = System.currentTimeMillis();
           for (int i = 0; i < suites.length; i++) {
  +            String name = suites[i].getClass().getName();
               if (suites[i] instanceof TestCase) {
  -                suites[i] = new TestSuite(suites[i].getClass().getName());
  +                suites[i] = new TestSuite(name);
               }
               log("running suite: " + suites[i]);
  +            fireEvent(new TestRunEvent(id, TestRunEvent.SUITE_STARTED, name));
               suites[i].run(testResult);
  +            fireEvent(new TestRunEvent(id, TestRunEvent.SUITE_ENDED, name));
           }
   
           // inform TestRunListeners of test end
           long elapsedTime = System.currentTimeMillis() - startTime;
           if (testResult == null || testResult.shouldStop()) {
  -            writer.notifyTestRunStopped(elapsedTime);
  +            fireEvent(new TestRunEvent(id, TestRunEvent.RUN_STOPPED, System.getProperties()));
           } else {
  -            writer.notifyTestRunEnded(elapsedTime);
  +            fireEvent(new TestRunEvent(id, TestRunEvent.RUN_ENDED, System.getProperties()));
           }
           log("Finished after " + elapsedTime + "ms");
           shutDown();
  @@ -345,23 +346,16 @@
       protected void connect() throws IOException {
           log("Connecting to " + host + " on port " + port + "...");
           clientSocket = new Socket(host, port);
  -        writer = new MessageWriter(clientSocket.getOutputStream());
  -        reader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
  +        messenger = new Messenger(clientSocket.getInputStream(), clientSocket.getOutputStream());
           new StopThread().start();
       }
   
   
       protected void shutDown() {
  -
  -        if (writer != null) {
  -            writer.close();
  -            writer = null;
  -        }
  -
           try {
  -            if (reader != null) {
  -                reader.close();
  -                reader = null;
  +            if (messenger != null) {
  +                messenger.close();
  +                messenger = null;
               }
           } catch (IOException e) {
               log(e);
  @@ -377,6 +371,9 @@
           }
       }
   
  +    protected void fireEvent(TestRunEvent evt){
  +        messenger.writeEvent(evt);
  +    }
   
   // -------- JUnit TestListener implementation
   
  @@ -384,14 +381,13 @@
       public void startTest(Test test) {
           String testName = test.toString();
           log("starting test: " + test);
  -        writer.notifyTestStarted(testName);
  +        fireEvent(new TestRunEvent(id, TestRunEvent.TEST_STARTED, testName));
       }
   
       public void addError(Test test, Throwable t) {
           log("Adding error for test: " + test);
           String testName = test.toString();
  -        String trace = StringUtils.getStackTrace(t);
  -        writer.notifyTestFailed(TestRunListener.STATUS_ERROR, testName, trace);
  +        fireEvent(new TestRunEvent(id, TestRunEvent.TEST_ERROR, testName, t));
       }
   
       /**
  @@ -409,14 +405,13 @@
       public void addFailure(Test test, Throwable t) {
           log("Adding failure for test: " + test);
           String testName = test.toString();
  -        String trace = StringUtils.getStackTrace(t);
  -        writer.notifyTestFailed(TestRunListener.STATUS_FAILURE, testName, trace);
  +        fireEvent(new TestRunEvent(id, TestRunEvent.TEST_FAILURE, testName, t));
       }
   
       public void endTest(Test test) {
           log("Ending test: " + test);
           String testName = test.toString();
  -        writer.notifyTestEnded(testName);
  +        fireEvent(new TestRunEvent(id, TestRunEvent.TEST_ENDED, testName));
       }
   
       public void log(String msg) {
  
  
  
  1.5       +13 -21    jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/TestRunListener.java
  
  Index: TestRunListener.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/TestRunListener.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestRunListener.java	14 Jan 2002 23:13:13 -0000	1.4
  +++ TestRunListener.java	30 Jan 2002 21:05:53 -0000	1.5
  @@ -54,6 +54,9 @@
   package org.apache.tools.ant.taskdefs.optional.junit;
   
   import java.util.Properties;
  +import java.util.EventListener;
  +
  +import org.apache.tools.ant.taskdefs.optional.junit.remote.TestRunEvent;
   
   
   /**
  @@ -67,27 +70,21 @@
    *
    * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
    */
  -public interface TestRunListener {
  -
  -    /** Some tests failed. */
  -    public final static int STATUS_FAILURE = 1;
  -
  -    /** An error occured. */
  -    public final static int STATUS_ERROR = 2;
  +public interface TestRunListener extends EventListener{
   
       /**
        * A test has started.
        * @param a testname made of the testname and testcase classname.
        * in the following format: <tt>&lt;testname&gt;(&lt;testcase&gt;)</tt>
        */
  -    public void onTestStarted(String testname);
  +    public void onTestStarted(TestRunEvent evt);
   
       /**
        * A test ended.
        * @param a testname made of the testname and testcase classname.
        * in the following format: <tt>&lt;testname&gt;(&lt;testcase&gt;)</tt>
        */
  -    public void onTestEnded(String testname);
  +    public void onTestEnded(TestRunEvent evt);
   
       /**
        * A test has failed.
  @@ -97,24 +94,19 @@
        * @param trace the error/failure stacktrace.
        * @todo change this to a testFailure / testError ?
        */
  -    public void onTestFailed(int status, String testname, String trace);
  -
  -    /** test logged this line on stdout */
  -    public void onTestStdOutLine(String testname, String line);
  -
  -    /** test logged this line on sterr */
  -    public void onTestStdErrLine(String testname, String line);
  +    public void onTestFailure(TestRunEvent evt);
   
  -    /** these system properties are used on the remote client */
  -    public void onTestRunSystemProperties(Properties props);
  +    public void onTestError(TestRunEvent evt);
   
       /** starting a sequence of <tt>testcount</tt> tests. */
  -    public void onTestRunStarted(int testcount);
  +    public void onRunStarted(TestRunEvent evt);
   
       /** ending gracefully the sequence after <tt>elapsedtime</tt> ms. */
  -    public void onTestRunEnded(long elapsedtime);
  +    public void onRunEnded(TestRunEvent evt);
   
       /** stopping the sequence after <tt>elapsedtime</tt> ms. */
  -    public void onTestRunStopped(long elapsedtime);
  +    public void onRunStopped(TestRunEvent evt);
   
  +    public void onSuiteStarted(TestRunEvent evt);
  +    public void onSuiteEnded(TestRunEvent evt);
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message