morgand     2002/09/03 12:47:28

  Modified:    latka-scratch/src/java/org/apache/watchdog Watchdog.java
  Log:
  added code for executing particular entities in the watchdog DTD
  
  Revision  Changes    Path
  1.2       +62 -6     
jakarta-watchdog-4.0/latka-scratch/src/java/org/apache/watchdog/Watchdog.java
  
  Index: Watchdog.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-watchdog-4.0/latka-scratch/src/java/org/apache/watchdog/Watchdog.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Watchdog.java     29 Jul 2002 16:29:16 -0000      1.1
  +++ Watchdog.java     3 Sep 2002 19:47:28 -0000       1.2
  @@ -21,28 +21,84 @@
   import org.apache.commons.latka.Suite;
   import org.apache.commons.latka.XMLReporter;
   
  +import org.jdom.DocType;
  +import org.jdom.Document;
  +import org.jdom.Element;
  +import org.jdom.EntityRef;
  +import org.jdom.output.XMLOutputter;
  +
   public class Watchdog {
   
       public static void main(String args[]) throws Exception {
   
           Watchdog watchdog = new Watchdog();
  -        watchdog.runTests();
  +        if (args.length == 1) {
  +            watchdog.runTests(args[0]);
  +        } else {
  +            watchdog.runTests();
  +        }
   
       }
   
  -    protected void runTests() throws LatkaException {
  -        Latka latka = new Latka();
  +    protected Properties getWatchdogProps() throws IOException {
  +        Properties watchdogProps = loadPropsFromClasspath("watchdog.properties");
  +        return watchdogProps;
  +    }
   
  +    protected void runTests(String entityName) throws LatkaException {
           try {
  -            Properties watchdogProps = 
loadPropsFromClasspath("watchdog.properties");
  -            // add them to the Latka session
  -            LatkaProperties.getProperties().putAll(watchdogProps);
  +            Properties watchdogProps = getWatchdogProps();
  +            String dtdLocation = 
  +                watchdogProps.getProperty("org.apache.watchdog.dtdURL");
  +            
  +            Element suiteElement = new Element("suite");
  +            suiteElement.setAttribute("defaultHost","${host}");
  +            suiteElement.setAttribute("defaultPort","${port}");
  +            EntityRef ref = new EntityRef(entityName);
  +            suiteElement.addContent(ref);
  +
  +            DocType type = new DocType("suite",dtdLocation);
  +
  +            Document doc = new Document(suiteElement,type);
  +                        
  +            XMLOutputter outputter = new XMLOutputter("  ", true);
  +            String xmlDoc = outputter.outputString(doc);
  +
  +            System.out.println(xmlDoc);
  +
  +            StringReader reader = new StringReader(xmlDoc);
  +            Suite suite = new Suite(reader);
  +            runTests(suite,watchdogProps);
  +
  +        } catch (IOException e) {
  +            throw new LatkaException(e.toString());
  +        }
  +    }
  +
  +    protected void runTests() throws LatkaException {
  +        Properties watchdogProps = null;
  +        try {
  +            watchdogProps = getWatchdogProps();
   
               String suiteLocation = 
                   watchdogProps.getProperty("org.apache.watchdog.mainSuiteURL");
   
               URL url = new URL(suiteLocation);
               Suite suite = new Suite(url);
  +
  +            runTests(suite, watchdogProps);
  +        } catch (IOException e) {
  +            throw new LatkaException(e.toString());
  +        }
  +    }
  +
  +    protected void runTests(Suite suite, Properties watchdogProps) throws 
LatkaException {
  +        Latka latka = new Latka();
  +
  +        try {
  +            // add props to the Latka session
  +            LatkaProperties.getProperties().putAll(watchdogProps);
  +
               XMLReporter listener = new XMLReporter();
               latka.runTests(suite,listener);
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to