morgand     01/08/24 13:13:50

  Modified:    latka/src/java/org/apache/commons/latka Latka.java
                        LatkaException.java XMLReporter.java
  Log:
  more cleanup
  
  Revision  Changes    Path
  1.11      +47 -61    
jakarta-commons/latka/src/java/org/apache/commons/latka/Latka.java
  
  Index: Latka.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/Latka.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Latka.java        2001/08/24 18:55:23     1.10
  +++ Latka.java        2001/08/24 20:13:50     1.11
  @@ -65,12 +65,10 @@
   
   import java.io.File;
   import java.io.FileInputStream;
  -import java.io.FileNotFoundException;
   import java.io.FileWriter;
   import java.io.IOException;
   import java.io.Reader;
   import java.io.StringReader;
  -import java.io.StringWriter;
   
   import java.net.URL;
   
  @@ -97,9 +95,6 @@
   
   import org.apache.log4j.Category;
   
  -
  -import org.jdom.output.XMLOutputter;
  -
   import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
   
  @@ -108,8 +103,6 @@
    */
   public class Latka {
   
  -  XMLReporter _listener = new XMLReporter();
  -
     protected static Category log =
       Category.getInstance(Latka.class.getName());
   
  @@ -127,12 +120,10 @@
       LATKA_USAGE = buf.toString();
     }
   
  -  public void runTests(Suite suite) throws LatkaException {
  +  public void runTests(Suite suite, LatkaEventInfo listener) throws LatkaException {
       
       InputSource source = null;
   
  -    boolean failed = false;
  -
       try {
   
         XMLPreprocessor preprocessor = new XMLPreprocessor();
  @@ -157,65 +148,22 @@
   
         SAXParser parser = factory.newSAXParser();
   
  -      SuiteHandler handler = new SuiteHandler(parser.getXMLReader(),_listener);
  +      SuiteHandler handler = new SuiteHandler(parser.getXMLReader(),listener);
         
         parser.parse(source, handler);
   
       } catch (ParserConfigurationException e) {
  -      e.printStackTrace();
  -      failed = true;
  +      throw new LatkaException(e);
       } catch (SAXException e) {
  -      System.out.println("WARNING: Either a test failed, or there was a problem 
with the test XML.");
  -      e.printStackTrace();
  -      if (e.getException() != null) {
  -        e.getException().printStackTrace();
  -      }
  -      failed = true;
  -    } catch (IOException e) {
  -      e.printStackTrace();
  -      failed = true;
  -    }
  -
  -    // get the xml string from the listener
  -    XMLOutputter outputter = new XMLOutputter("  ",true);
  -    StringWriter writer = new StringWriter();
  -    try {
  -      outputter.output(_listener.getDocument(),writer);
  +      throw new LatkaException(e);
       } catch (IOException e) {
  -      e.printStackTrace();
  -      failed = true;
  -    }
  -
  -    String xmlDocument = writer.toString();
  -
  -    try {
  -      logXML(xmlDocument);
  -    } catch (IOException e) {
  -      e.printStackTrace();
  -      failed = true;
  -    }
  -
  -    //transform the XML
  -    try {
  -      transformXML(xmlDocument);
  -    } catch (TransformerConfigurationException e) {
  -      e.printStackTrace();
  -      failed = true;
  -    } catch (FileNotFoundException e) {
  -      e.printStackTrace();
  -      failed = true;
  -    } catch (TransformerException e) {
  -      e.printStackTrace();
  -      failed = true;
  -    }
  -
  -    if (failed == true) {
  -      throw new LatkaException("SUITE FAILED");
  +      throw new LatkaException(e);
       }
   
     }
   
     protected void logXML(String xml) throws IOException {
  +
       String logProp = _props.getProperty("latka.writeLog");
       if ((logProp != null) && (logProp.equals("false"))) {
         return;
  @@ -233,8 +181,8 @@
       fileWriter.close();
     }
   
  -  protected void transformXML(String xml) 
  -  throws TransformerException, TransformerConfigurationException, 
FileNotFoundException {
  +  public void transformXML(String xml) 
  +  throws TransformerException {
       
       StreamSource xslSource = 
         new 
StreamSource(getClass().getResourceAsStream("/org.apache.commons.latka.report.xsl"));
  @@ -276,7 +224,44 @@
       }
   
       Suite suite = new Suite(uri);
  -    runTests(suite);
  +
  +    XMLReporter listener = new XMLReporter();
  +
  +    runTests(suite,listener);
  +
  +    String xml = null; 
  +
  +    try {
  +      xml = listener.getDocumentAsString();
  +      logXML(xml);
  +    } catch (IOException e) {
  +      throw new LatkaException(e);
  +    }
  +
  +    try {
  +      transformXML(xml);
  +    } catch (TransformerException e) {
  +      throw new LatkaException(e);
  +    } 
  +  }
  +
  +  public void printWrappedExceptions(LatkaException e) {
  +    Exception wrappedException = e.getException();
  +
  +    if (wrappedException != null) {
  +      System.out.println("Wraps exception:");
  +      e.printStackTrace();
  +
  +      if (wrappedException instanceof SAXException) {
  +        Exception saxWrappedException = 
  +          ((SAXException) wrappedException).getException();        
  +        if (saxWrappedException != null) {
  +          System.out.println("Wraps exception:");
  +          e.printStackTrace();
  +        }
  +      }
  +
  +    }
     }
   
     public static void main (String args[]) {
  @@ -286,6 +271,7 @@
         latka.runCommandLine(args);
       } catch (LatkaException e) {
         e.printStackTrace();
  +      latka.printWrappedExceptions(e);
         System.exit(1);
       }
       
  
  
  
  1.2       +15 -0     
jakarta-commons/latka/src/java/org/apache/commons/latka/LatkaException.java
  
  Index: LatkaException.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/LatkaException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LatkaException.java       2001/08/24 18:55:23     1.1
  +++ LatkaException.java       2001/08/24 20:13:50     1.2
  @@ -61,8 +61,23 @@
   
   public class LatkaException extends Exception {
     
  +  protected Exception _wrappedException = null;
  +
     public LatkaException(String message) {
       super(message);
  +  }
  +
  +  /**
  +   * wrapped exception
  +   * 
  +   * @param e exception to wrap
  +   */
  +  public LatkaException(Exception e) {
  +    _wrappedException = e;
  +  }
  +
  +  public Exception getException() {
  +    return _wrappedException;
     }
   
   }
  
  
  
  1.8       +19 -3     
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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XMLReporter.java  2001/08/23 16:24:25     1.7
  +++ XMLReporter.java  2001/08/24 20:13:50     1.8
  @@ -59,17 +59,21 @@
   
   package org.apache.commons.latka;
   
  +import java.io.IOException;
  +import java.io.StringWriter;
  +
  +import java.util.HashMap;
  +import java.util.Map;
  +
   import org.apache.commons.latka.http.Request;
   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 java.util.HashMap;
  -import java.util.Map;
  -
   import org.jdom.Document;
   import org.jdom.Element;
  +import org.jdom.output.XMLOutputter;
   
   public class XMLReporter extends AbstractReporter {
   
  @@ -91,6 +95,18 @@
   
     public Document getDocument() {
       return _doc;
  +  }
  +
  +  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);
  +
  +    String xmlDocument = writer.toString();
  +
  +    return xmlDocument;
     }
   
     public void requestError(RequestEvent event) {
  
  
  

Reply via email to