commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: jakarta-commons/latka/src/java/org/apache/commons/latka SimpleReporter.java
Date Sat, 02 Feb 2002 12:00:02 GMT
dion        02/02/02 04:00:02

  Modified:    latka/src/java/org/apache/commons/latka SimpleReporter.java
  Log:
  Javadoc, formatting and small code cleanups
  
  Revision  Changes    Path
  1.6       +167 -109  jakarta-commons/latka/src/java/org/apache/commons/latka/SimpleReporter.java
  
  Index: SimpleReporter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/SimpleReporter.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SimpleReporter.java	4 Sep 2001 05:37:13 -0000	1.5
  +++ SimpleReporter.java	2 Feb 2002 12:00:02 -0000	1.6
  @@ -58,122 +58,180 @@
    */   
   
   package org.apache.commons.latka;
  +// java imports
  +import java.util.ArrayList;
  +import java.util.Iterator;
  +import java.util.List;
  +
  +// latka imports
  +import org.apache.commons.latka.event.RequestErrorEvent;
  +import org.apache.commons.latka.event.RequestEvent;
  +import org.apache.commons.latka.event.RequestFailedEvent;
  +import org.apache.commons.latka.event.SuiteEvent;
   
  -import org.apache.commons.latka.event.*;
  -
  -import java.util.*;
   
   /**
  - * Needs docs.
  + * A simple class that reports on Latka events. As events occur, a single 
  + * character is printed to show their status <code>.</code> for success,
  + * <code>F</code> for failure, <code>e</code> for skipping, <code>E</code>
for
  + * error.
  + *
  + * On Suite completion, the statistics for the suite are printed
    *
    * @author Rodney Waldhoff
  + * @author dIon Gillard
    */
   public class SimpleReporter extends AbstractReporter {
  -   int _pass = 0;
  -   int _fail = 0;
  -   int _err  = 0;
  -   int _skip = 0;
  -
  -   List _failures = new ArrayList();
  -   List _errors = new ArrayList();
  -
  -   public void requestSucceeded(RequestEvent event) {
  -      System.out.print(".");
  -      super.requestSucceeded(event);
  -      _pass++;
  -   }
  -
  -   public void requestFailed(RequestEvent event) {
  -      System.out.print("F");
  -      super.requestFailed(event);
  -      _fail++;
  -      _failures.add(event);
  -   }
  -
  -   public void requestSkipped(RequestEvent event) {
  -      System.out.print("s");
  -      super.requestSkipped(event);
  -      _skip++;
  -   }
  -
  -   public void requestError(RequestEvent event) {
  -      System.out.print("E");
  -      super.requestError(event);
  -      _err++;
  -      _errors.add(event);
  -   }
  -
  -   public void suiteCompleted(SuiteEvent event) {
  -      System.out.println();
  -      if (didSuiteSucceed() == true) {
  -        System.out.println("SUITE PASSED");
  -      } else {
  -        System.out.println("SUITE FAILED");
  -      }
  -
  -      printStats();
  -
  -      if (didSuiteSucceed() == true) {
  -        System.out.println("SUITE PASSED");
  -      } else {
  -        maybePrintFailures();
  -        maybePrintErrors();
  -        System.out.println("SUITE FAILED");
  -      }
  -   }
  -
  -   private void printStats() {
  -      System.out.println((_pass + _fail + _err + _skip) + " requests run.");
  -      System.out.println(_pass + " passed.");
  -      System.out.println(_fail + " failed.");
  -      System.out.println(_err + " errors.");
  -      System.out.println(_skip + " skipped.");
  -   }
  -
  -   private void maybePrintFailures() {
  -      if(!_failures.isEmpty()) {
  -         System.out.println();
  -         System.out.println("Failures:");
  -         Iterator it = _failures.iterator();
  -         while(it.hasNext()) {
  -            RequestFailedEvent event = (RequestFailedEvent)it.next();
  -            StringBuffer buf = new StringBuffer();
  -            buf.append("Request ");
  -            if(null != event.getRequest()) {
  -               if(null != event.getRequest().getLabel()) {
  -                  buf.append("\"").append(event.getRequest().getLabel()).append("\" ");
  -               }
  -               if(null != event.getRequest().getURL()) {
  -                  buf.append("<").append(event.getRequest().getURL()).append("> ");
  -               }
  +    /** number of requests that succeed */
  +    private int _pass = 0;
  +    /** number of requests that fail */
  +    private int _fail = 0;
  +    /** number of requests that are in error */
  +    private int _err  = 0;
  +    /** number of requests that are skippped */
  +    private int _skip = 0;
  +    /** list of events for failures */
  +    private List _failures = new ArrayList();
  +    /** list of events for errors */
  +    private List _errors = new ArrayList();
  +
  +    /**
  +     * Handle a request succeeding by printing a <code>.</code>, and
  +     * keeping the stats for later usage
  +     * @param event the success event from Latka
  +     */
  +    public void requestSucceeded(RequestEvent event) {
  +        System.out.print(".");
  +        super.requestSucceeded(event);
  +        _pass++;
  +    }
  +
  +    /**
  +     * Handle a request failing by printing an <code>F</code>, and
  +     * keeping the stats for later usage
  +     * @param event the failure event from Latka
  +     */
  +    public void requestFailed(RequestEvent event) {
  +        System.out.print("F");
  +        super.requestFailed(event);
  +        _fail++;
  +        _failures.add(event);
  +    }
  +    
  +    /**
  +     * Handle a request being skipped by printing an <code>s</code>, and
  +     * keeping the stats for later usage
  +     * @param event the skipped event from Latka
  +     */
  +    public void requestSkipped(RequestEvent event) {
  +        System.out.print("s");
  +        super.requestSkipped(event);
  +        _skip++;
  +    }
  +
  +    /**
  +     * Handle a request in error by printing an <code>E</code>, and
  +     * keeping the stats for later usage
  +     * @param event the error event from Latka
  +     */
  +    public void requestError(RequestEvent event) {
  +        System.out.print("E");
  +        super.requestError(event);
  +        _err++;
  +        _errors.add(event);
  +    }
  +
  +    /**
  +     * On suite completion, print the statistics gather on event handling
  +     * @param event the failure event from Latka
  +     */
  +    public void suiteCompleted(SuiteEvent event) {
  +        System.out.println();
  +        if (didSuiteSucceed() == true) {
  +            System.out.println("SUITE PASSED");
  +        } else {
  +            System.out.println("SUITE FAILED");
  +        }
  +
  +        printStats();
  +
  +        if (didSuiteSucceed() == true) {
  +            System.out.println("SUITE PASSED");
  +        } else {
  +            maybePrintFailures();
  +            maybePrintErrors();
  +            System.out.println("SUITE FAILED");
  +        }
  +    }
  +
  +    /**
  +     * Print the statistics gathered (total, passed, failed, errors 
  +     * and skipped requests counts)
  +     */
  +    private void printStats() {
  +        System.out.println((_pass + _fail + _err + _skip) + " requests run.");
  +        System.out.println(_pass + " passed.");
  +        System.out.println(_fail + " failed.");
  +        System.out.println(_err + " errors.");
  +        System.out.println(_skip + " skipped.");
  +    }
  +
  +    /**
  +     * Print any failure requests details
  +     */
  +    private void maybePrintFailures() {
  +        if (!_failures.isEmpty()) {
  +            System.out.println();
  +            System.out.println("Failures:");
  +            Iterator it = _failures.iterator();
  +            while (it.hasNext()) {
  +                RequestFailedEvent event = (RequestFailedEvent) it.next();
  +                StringBuffer buf = new StringBuffer("Request ");
  +                if (null != event.getRequest()) {
  +                    if (null != event.getRequest().getLabel()) {
  +                        buf.append("\"")
  +                           .append(event.getRequest().getLabel())
  +                           .append("\" ");
  +                    }
  +                    if (null != event.getRequest().getURL()) {
  +                        buf.append("<")
  +                           .append(event.getRequest().getURL())
  +                           .append("> ");
  +                    }
  +                }
  +                buf.append(" failed. ");
  +                buf.append(event.getValidationException().getMessage());
  +                System.out.println(buf.toString());
               }
  -            buf.append(" failed. ");
  -            buf.append(event.getValidationException().getMessage());
  -            System.out.println(buf.toString());
  -         }
  -      }
  -   }
  -
  -   private void maybePrintErrors() {
  -      if(!_errors.isEmpty()) {
  -         System.out.println();
  -         System.out.println("Failures:");
  -         Iterator it = _errors.iterator();
  -         while(it.hasNext()) {
  -            RequestErrorEvent event = (RequestErrorEvent)it.next();
  -            StringBuffer buf = new StringBuffer();
  -            buf.append("Request ");
  -            if(null != event.getRequest()) {
  -               if(null != event.getRequest().getLabel()) {
  -                  buf.append("\"").append(event.getRequest().getLabel()).append("\" ");
  -               }
  -               if(null != event.getRequest().getURL()) {
  -                  buf.append("<").append(event.getRequest().getURL()).append("> ");
  -               }
  +        }
  +    }
  +
  +    /**
  +     * Print any error requests details
  +     */
  +    private void maybePrintErrors() {
  +        if (!_errors.isEmpty()) {
  +            System.out.println();
  +            System.out.println("Failures:");
  +            Iterator it = _errors.iterator();
  +            while (it.hasNext()) {
  +                RequestErrorEvent event = (RequestErrorEvent) it.next();
  +                StringBuffer buf = new StringBuffer("Request ");
  +                if (null != event.getRequest()) {
  +                    if (null != event.getRequest().getLabel()) {
  +                        buf.append("\"")
  +                           .append(event.getRequest().getLabel())
  +                           .append("\" ");
  +                    }
  +                    if (null != event.getRequest().getURL()) {
  +                        buf.append("<")
  +                           .append(event.getRequest().getURL())
  +                           .append("> ");
  +                    }
  +                }
  +                buf.append(event.getError().toString());
  +                System.out.println(buf.toString());
               }
  -            buf.append(event.getError().toString());
  -            System.out.println(buf.toString());
  -         }
  -      }
  -   }
  +        }
  +    }
   }
  
  
  

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


Mime
View raw message