jakarta-watchdog-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From morg...@apache.org
Subject cvs commit: jakarta-watchdog-4.0/latka-scratch/src/java/org/apache/watchdog Watchdog.java
Date Mon, 29 Jul 2002 16:29:16 GMT
morgand     2002/07/29 09:29:16

  Added:       latka-scratch/src/java/org/apache/watchdog Watchdog.java
  Log:
  test driver class
  
  Revision  Changes    Path
  1.1                  jakarta-watchdog-4.0/latka-scratch/src/java/org/apache/watchdog/Watchdog.java
  
  Index: Watchdog.java
  ===================================================================
  package org.apache.watchdog;
  
  import java.io.InputStream;
  import java.io.IOException;
  import java.io.StringReader;
  import java.io.StringWriter;
  import java.net.URL;
  
  import java.util.Properties;
  
  import javax.xml.transform.Source;
  import javax.xml.transform.Transformer;
  import javax.xml.transform.TransformerException;
  import javax.xml.transform.TransformerFactory;
  import javax.xml.transform.stream.StreamResult;
  import javax.xml.transform.stream.StreamSource;
  
  import org.apache.commons.latka.Latka;
  import org.apache.commons.latka.LatkaException;
  import org.apache.commons.latka.LatkaProperties;
  import org.apache.commons.latka.Suite;
  import org.apache.commons.latka.XMLReporter;
  
  public class Watchdog {
  
      public static void main(String args[]) throws Exception {
  
          Watchdog watchdog = new Watchdog();
          watchdog.runTests();
  
      }
  
      protected void runTests() throws LatkaException {
          Latka latka = new Latka();
  
          try {
              Properties watchdogProps = loadPropsFromClasspath("watchdog.properties");
              // add them to the Latka session
              LatkaProperties.getProperties().putAll(watchdogProps);
  
              String suiteLocation = 
                  watchdogProps.getProperty("org.apache.watchdog.mainSuiteURL");
  
              URL url = new URL(suiteLocation);
              Suite suite = new Suite(url);
              XMLReporter listener = new XMLReporter();
              latka.runTests(suite,listener);
  
              String xml = listener.getDocumentAsString();
  
              System.out.println(transformXML(xml));
          } catch (IOException e) {
              throw new LatkaException(e.toString());
          }
      }
  
  
  
      /**
   * Load properties specified from context class path
   * @param classpathLocation Resource name to load
   * @throws IOException from loading resource
   * @return initialized properties object
   */
      protected Properties
      loadPropsFromClasspath(String classpathLocation)
      throws IOException {
          Properties properties  = new Properties();
  
          ClassLoader loader = Thread.currentThread().getContextClassLoader();
  
          InputStream stream = loader.getResourceAsStream(classpathLocation);
  
          if (stream == null) {
              throw new IOException("Could not find this file in classpath: "
                                    + classpathLocation);
          }
  
          properties.load(stream);
  
          return properties;
      }
  
      /**
       * Transform the XML generated by the XMLReporter using
       * the default stylesheet.
       *
       * @param xml XML generated by XMLReporter
       * @return transformed report
       * @throws LatkaException if the XML could not be transformed
       */
      private String transformXML(String xml) throws LatkaException {
      
          try {
              StringWriter output = new StringWriter();
  
              Source xslSource = null;
  
              ClassLoader loader = Thread.currentThread().getContextClassLoader();
  
              xslSource = new StreamSource(
                              loader.getResourceAsStream(
                              "org.apache.commons.latka.report.xsl")
                          );
  
              Transformer transformer = 
              TransformerFactory.newInstance().newTransformer(xslSource);
              StreamSource xmlSource = new StreamSource(new StringReader(xml));
              StreamResult result = new StreamResult(output);
              transformer.transform(xmlSource, result);
              return output.toString();
          } catch (TransformerException e) {
              throw new LatkaException(e);
          }
      }
  
  }
  
  
  

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


Mime
View raw message