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 XMLReporter.java
Date Wed, 06 Feb 2002 05:33:18 GMT
dion        02/02/05 21:33:18

  Modified:    latka/src/java/org/apache/commons/latka XMLReporter.java
  Log:
  Reformatted code, refactor JDOM element construction, fix javadoc
  
  Revision  Changes    Path
  1.16      +150 -139  jakarta-commons/latka/src/java/org/apache/commons/latka/XMLReporter.java
  
  Index: XMLReporter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/XMLReporter.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- XMLReporter.java	2 Feb 2002 12:36:00 -0000	1.15
  +++ XMLReporter.java	6 Feb 2002 05:33:18 -0000	1.16
  @@ -85,171 +85,182 @@
    *
    * @author Morgan Delagrange
    * @author dIon Gillard
  - * @version $Revision: 1.15 $
  + * @version $Id: XMLReporter.java,v 1.16 2002/02/06 05:33:18 dion Exp $
    */
   public class XMLReporter extends AbstractReporter {
  +    /** JDOM document produced as output */
  +    protected Document _doc         = null;
  +    /** top level element of JDOM document, a <report> element*/
  +    protected Element  _rootElement = null;
  +    /** used for output as tests run */                   
  +    protected PrintWriter _printWriter = new PrintWriter(System.out);
  +
  +    /**
  +     * Create an XML Reporter, initialising document property, as a new empty
  +     * report with an unsuccessful suite
  +     */
  +    public XMLReporter() {
  +        _rootElement = new Element("report");
  +        //defaults to false, until a SuiteSuccess event occurs
  +        _doc = new Document(_rootElement);
  +        _rootElement.setAttribute("suiteSuccess", "false");
  +    }
   
  -  protected Document _doc         = null;
  -  protected Element  _rootElement = null;
  -                       
  -  protected PrintWriter _printWriter = new PrintWriter(System.out);
  -
  -  public XMLReporter() {
  -    _rootElement = new Element("report");
  -    //defaults to false, until a SuiteSuccess event occurs
  -    _doc = new Document(_rootElement);
  -    _rootElement.setAttribute("suiteSuccess","false");
  -  }
  -
  -  /**
  -   * Returns the XML Document produced by this listener
  -   *
  -   * @return JDOM representation of the test report
  -   *
  -   */
  -  public Document getDocument() {
  -    return _doc;
  -  }
  +    /**
  +     * Returns the XML Document produced by this listener
  +     *
  +     * @return JDOM representation of the test report
  +     */
  +    public Document getDocument() {
  +        return _doc;
  +    }
   
  -  /**
  -   * Returns the test report converted from JDOM to a
  -   * text string.
  -   *
  -   * @return the test report as an XML string
  -   * @throws IOException
  -   *   if the XML formatter cannot convert the JDOM
  -   *   object to text
  -   */
  -  public String getDocumentAsString() throws IOException {
  -    // get the xml string from the listener
  -    XMLOutputter outputter = new XMLOutputter("  ",true);
  -    StringWriter writer = new StringWriter();
  +    /**
  +     * Returns the test report converted from JDOM to a
  +     * text string.
  +     *
  +     * @return the test report as an XML string
  +     * @throws IOException if the XML formatter cannot convert the JDOM object
  +     *                     to text
  +     */
  +    public String getDocumentAsString() throws IOException {
  +        // get the xml string from the listener
  +        XMLOutputter outputter = new XMLOutputter("  ", true);
  +        StringWriter writer = new StringWriter();
         
  -    outputter.output(getDocument(),writer);
  +        outputter.output(getDocument(), writer);
   
  -    String xmlDocument = writer.toString();
  +        String xmlDocument = writer.toString();
   
  -    return xmlDocument;
  -  }
  +        return xmlDocument;
  +    }
   
  -  // defined in interface
  -  public void requestError(RequestEvent event) {
  -    _printWriter.print("E");
  -    _printWriter.flush();
  -    super.requestError(event);
  -
  -    RequestErrorEvent errorEvent = (RequestErrorEvent) event;
  -    Request request = event.getRequest();
  -
  -    Element requestElement = createRequestElement(event);
  -    _rootElement.addContent(requestElement);
  -    Element requestError = new Element("requestError");
  -    requestElement.addContent(requestError);
  -
  -    StringBuffer buf = new StringBuffer();
  -    buf.append(errorEvent.getError());
  -
  -    Element label = new Element("label");
  -    label.addContent(buf.toString());
  -    requestError.addContent(label);
  +    /**
  +     * @see AbstractReporter#requestError(RequestEvent) 
  +     * @param event the event detailing the request in error
  +     */
  +    public void requestError(RequestEvent event) {
  +        _printWriter.print("E");
  +        _printWriter.flush();
  +        super.requestError(event);
  +
  +        RequestErrorEvent errorEvent = (RequestErrorEvent) event;
  +        // <root><request><requestError><label>errortext</label>
  +        // </requestError></request></root>
  +        Element label = new Element("label")
  +                            .addContent(errorEvent.getError().toString());
  +        Element requestError = new Element("requestError").addContent(label);
  +        _rootElement.addContent(createRequestElement(event)
  +                                .addContent(requestError));
   
  -  }
  +    }
   
  -  // defined in interface
  -  public void requestSucceeded(RequestEvent event) {
  +    /**
  +     * @see AbstractReporter#requestSucceeded(RequestEvent)
  +     * @param event the event detailing the request that succeeded
  +     */
  +    public void requestSucceeded(RequestEvent event) {
   
  -    _printWriter.print(".");
  -    _printWriter.flush();
  +        _printWriter.print(".");
  +        _printWriter.flush();
       
  -    super.requestSucceeded(event);
  +        super.requestSucceeded(event);
   
  -    Element requestElement = createRequestElement(event);
  -    _rootElement.addContent(requestElement);
  -    Element requestSuccess = new Element("requestSuccess");
  -    requestElement.addContent(requestSuccess);
  -
  -  }
  +        _rootElement.addContent(createRequestElement(event)
  +                                .addContent(new Element("requestSuccess"))
  +                               );
  +    }
   
  -  // defined in interface
  -  public void requestFailed(RequestEvent event) {
  +    /**
  +     * @see AbstractReporter#requestFailed(RequestEvent)
  +     * @param event the event detailing the request that failed
  +     */
  +    public void requestFailed(RequestEvent event) {
       
  -    _printWriter.print("F");
  -    _printWriter.flush();
  +        _printWriter.print("F");
  +        _printWriter.flush();
       
  -    super.requestFailed(event);
  -
  -    RequestFailedEvent failedEvent = (RequestFailedEvent) event;
  -    Request request = event.getRequest();
  +        super.requestFailed(event);
   
  -    Element requestElement = createRequestElement(event);
  -    _rootElement.addContent(requestElement);
  -    Element requestFailure = new Element("requestFailure");
  -    requestFailure.setAttribute("responseId",event.getResponse().toString());
  -    requestElement.addContent(requestFailure);
  -
  -    StringBuffer buf = new StringBuffer();
  -    buf.append(failedEvent.getValidationException().getMessage());
  -
  -    Element label = new Element("label");
  -    label.addContent(buf.toString());
  -    requestFailure.addContent(label);
  -  }
  +        RequestFailedEvent failedEvent = (RequestFailedEvent) event;
   
  -  // defined in interface
  -  public void requestSkipped(RequestEvent event) {
  +        // <root><request><requestFailure responseId="xxx"><label>XXX</label>
  +        // </requestFailure></request></root>
  +        Element label = new Element("label")
  +                            .addContent(failedEvent.getValidationException()
  +                                                   .getMessage()
  +                                                   .toString());
  +        Element requestFailure = new Element("requestFailure")
  +                                    .setAttribute("responseId",
  +                                                  event.getResponse().toString()
  +                                                 )
  +                                    .addContent(label);
  +
  +        _rootElement.addContent(createRequestElement(event)
  +                                .addContent(requestFailure));
  +  }
  +
  +    /**
  +     * @see AbstractReporter#requestSkipped(RequestEvent)
  +     * @param event the event detailing the request that was skipped
  +     */
  +    public void requestSkipped(RequestEvent event) {
           
  -    _printWriter.print("S");
  -    _printWriter.flush();
  +        _printWriter.print("S");
  +        _printWriter.flush();
       
  -    super.requestSkipped(event);
  +        super.requestSkipped(event);
   
  -    Request request = event.getRequest();
  +        Request request = event.getRequest();
  +        // <root><request><requestSkipped/></request></root>
  +        _rootElement.addContent(createRequestElement(event)
  +                                .addContent(new Element("requestSkipped")));
   
  -    Element requestElement = createRequestElement(event);
  -    _rootElement.addContent(requestElement);
  -    Element requestSkipped = new Element("requestSkipped");
  -    requestElement.addContent(requestSkipped);
  +    }
   
  -  }
  +    /**
  +     * @see AbstractReporter#suiteCompleted(SuiteEvent)
  +     * @param event the event detailing the completing Suite
  +     */
  +    public void suiteCompleted(SuiteEvent event) {
  +        _rootElement.getAttribute("suiteSuccess").setValue(
  +            String.valueOf(didSuiteSucceed()));
  +    }
   
  -  // defined in interface
  -  public void suiteCompleted(SuiteEvent event) {
  -    _rootElement.getAttribute("suiteSuccess").setValue(String.valueOf(didSuiteSucceed()));
  -  }
  +    /**
  +     * Utility method that converts a RequestEvent object to its
  +     * corresponding element in the JDOM object.
  +     *
  +     * @param event the request event sent to the listener
  +     * @return the JDOM Element equivalent
  +     */
  +    protected Element createRequestElement(RequestEvent event) {
  +        // the request object
  +        Request request = event.getRequest();
  +
  +        Element requestElement = new Element("request")
  +            .setAttribute("requestTime",
  +                          String.valueOf(request.getRequestTiming()))
  +            .setAttribute("url", request.getURL().toString());
  +
  +        String label = request.getLabel();
  +        if (label != null) {
  +            requestElement.setAttribute("label", label);
  +        }
   
  -  /**
  -   * Utility method that converts a RequestEvent object to its
  -   * corresponding element in the JDOM object.
  -   *
  -   * @param event the request event sent to the listener
  -   * @return the JDOM Element equivalent
  -   */
  -  protected Element createRequestElement(RequestEvent event) {
  -    // the request object
  -    Request request = event.getRequest();
  -
  -    Element requestElement = new Element("request");
  -    requestElement.setAttribute("requestTime",String.valueOf(request.getRequestTiming()));
  -
  -    String label = request.getLabel();
  -    if (label != null) {
  -      requestElement.setAttribute("label",label);
  +        return requestElement;
       }
  -    requestElement.setAttribute("url",request.getURL().toString());
  -
  -    return requestElement;
  -  }
   
  -  /**
  -   * During the execution, any diagnostic ouput will be sent
  -   * to the stream designated here.  If no PrintWriter
  -   * is set, output will be sent to standard out.
  -   * 
  -   * @param writer PrintWriter that will receive output generated during
  -   *               the test
  -   */
  -  public void setPrintWriter(PrintWriter writer) {
  -    _printWriter = writer;
  -  }
  +    /**
  +     * During the execution, any diagnostic ouput will be sent
  +     * to the stream designated here.  If no PrintWriter
  +     * is set, output will be sent to standard out.
  +     * 
  +     * @param writer PrintWriter that will receive output generated during
  +     *               the test
  +     */
  +    public void setPrintWriter(PrintWriter writer) {
  +        _printWriter = writer;
  +    }
   
   }
  
  
  

--
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