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/junit JUnitTestAdapter.java
Date Sun, 03 Feb 2002 13:22:27 GMT
dion        02/02/03 05:22:27

  Modified:    latka/src/java/org/apache/commons/latka/junit
                        JUnitTestAdapter.java
  Log:
  Removed unneeded code, fixed javadoc
  
  Revision  Changes    Path
  1.7       +188 -181  jakarta-commons/latka/src/java/org/apache/commons/latka/junit/JUnitTestAdapter.java
  
  Index: JUnitTestAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/junit/JUnitTestAdapter.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JUnitTestAdapter.java	2 Feb 2002 13:20:47 -0000	1.6
  +++ JUnitTestAdapter.java	3 Feb 2002 13:22:27 -0000	1.7
  @@ -91,188 +91,195 @@
    *
    * @author Chuck Burdick
    * @author dIon Gillard
  - * @version $Id: JUnitTestAdapter.java,v 1.6 2002/02/02 13:20:47 dion Exp $
  + * @version $Id: JUnitTestAdapter.java,v 1.7 2002/02/03 13:22:27 dion Exp $
    */
   public class JUnitTestAdapter implements Test {
  -   private static final int ERROR = 0;
  -   private static final int FAILED = 1;
  -   private static final int SKIPPED = 2;
  -   private static final int SUCCEEDED = 3;
  -
  -   private static final Category _log = Category.getInstance(JUnitTestAdapter.class);
  -
  -   private Suite _latkaSuite = null;
  -   private TestResult _testResult = null;
  -   private int _testCount = 0;
  -
  -   /**
  -    * Create a Test from a Latka suite and a number of tests
  -    *
  -    * @param suite The Latka {@link org.apache.commons.latka.Suite}
  -    * to be run as a JUnit Test
  -    * @param testCount The number of 'request's in the Latka suite
  -    */   
  -   protected JUnitTestAdapter(Suite suite, int testCount) {
  -      _latkaSuite = suite;
  -      _testCount = testCount;
  -   }
  -
  -   /**
  -    * Create a Test from a Latka file
  -    * @param fileName The name of a readable file in Latka's XML format
  -    * @return a JUnit Test, ready to run
  -    */   
  -   public static Test createTestFromFile(String fileName) {
  -      Test result = null;
  -      File file = new File(fileName);
  -      if (file.exists()) {
  -         result = createTestFromFile(file);
  -      } else {
  -         _log.error("Input file " + file.getAbsolutePath() +
  -                    " does not exist");
  -      }
  -      return result;
  -   }
  -
  -   /**
  -    * Create a Test from a {@link java.io.File Java file}
  -    * @param file A readable java file containing Latka's XML format 
  -    * @return a JUnit Test, ready to run
  -    */   
  -   public static Test createTestFromFile(File file) {
  -      Test result = null;
  -      try {
  -         result = createTestFromURL(file.toURL());
  -      } catch (MalformedURLException e) {
  -         _log.error("Could not access input file", e);
  -      }
  -      return result;
  -   }
  -
  -   /**
  -    * Create a Test from a resource accessible via
  -    * the {@link java.lang.ClassLoader#getResource(String) class loader}
  -    * @param resourceName A resource accessible by the class loader in Latka's XML format
  -    * @return a JUnit Test, ready to run
  -    */   
  -   public static Test createTestFromResource(String resourceName) {
  -      Test result = null;
  -      ClassLoader loader = JUnitTestAdapter.class.getClassLoader();
  -      URL resource = loader.getResource(resourceName);
  -      if (resource != null) {
  -         result = createTestFromURL(resource);
  -      }
  -      return result;
  -   }
  -
  -   /**
  -    * Create a Test from a String containing a URL whose
  -    * contents are in Latka's XML format
  -    * @param url the {@link java.net.URL URL} to fetch
  -    * @return a JUnit Test, ready to run
  -    */   
  -   public static Test createTestFromURL(String url) {
  -      Test result = null;
  -      try {
  -         result = createTestFromURL(new URL(url));
  -      } catch (MalformedURLException e) {
  -         _log.error("Unable to create URL " + url, e);
  -      }
  -      return result;
  -   }
  -
  -   /**
  -    * Create a Test from a URL whose contents are in Latka's XML format
  -    * @param url the {@link java.net.URL URL} to fetch
  -    * @return a JUnit Test, ready to run
  -    */   
  -   public static Test createTestFromURL(URL url) {
  -      Test result = null;
  -      try {
  -         InputSource source = new InputSource(url.toString());
  -         Suite suite = new Suite(url);
  -         result = new JUnitTestAdapter(suite, parse(source));
  -      } catch (Throwable t) {
  -         _log.error("Unable to obtain xml from URL " + url.toString(), t);
  -      }
  -      return result;
  -   }
  -
  -   /**
  -    Parse the Latka XML document to count the requests
  -    * @param xml The inputsource to parse
  -    * @throws IOException When an IO occurs reading the document
  -    * @throws SAXException When the document is invalid XML 
  -    * @throws FactoryConfigurationError When the SAX Parser factory can't be configured
correctly
  -    * @throws ParserConfigurationException When the SAX Parser can't be configured correctly
  -    * @return the number of tests in the Latka suite
  -    */   
  -   protected static int parse(InputSource xml)
  -      throws IOException, SAXException,
  -      FactoryConfigurationError, ParserConfigurationException {
  -      int result = 0;
  -      XMLReader reader = null;
  -      SAXParserFactory factory = SAXParserFactory.newInstance();
  -      factory.setValidating(false);   
  -      SAXParser parser = factory.newSAXParser();
  -      reader = parser.getXMLReader();
  -      TestCounter handler = new TestCounter();
  -      reader.setContentHandler(handler);
  -      reader.parse(xml);
  -      result = handler.getCount();
  -      return result;
  -   }
  -
  -   /**
  -    * A SAX Handler to count the number of <code>request</code> tags in the
document
  -    *
  -    */
  -   private static class TestCounter extends DefaultHandler {
  -      private int _count = 0;
  +    /** log4j category that output is logged to */
  +    private static final Category _log = Category.getInstance(JUnitTestAdapter.class);
  +
  +    /** The latka {@link org.apache.commons.latka.Suite Suite} to be run*/
  +    private Suite _latkaSuite = null;
  +    /** the number of tests in the suite */
  +    private int _testCount = 0;
  +
  +    /**
  +     * Create a Test from a Latka suite and a number of tests
  +     *
  +     * @param suite The Latka {@link org.apache.commons.latka.Suite}
  +     * to be run as a JUnit Test
  +     * @param testCount The number of 'request's in the Latka suite
  +     */   
  +    protected JUnitTestAdapter(Suite suite, int testCount) {
  +        _latkaSuite = suite;
  +        _testCount = testCount;
  +    }
  +
  +    /**
  +     * Create a Test from a Latka file
  +     * @param fileName The name of a readable file in Latka's XML format
  +     * @return a JUnit Test, ready to run
  +     */   
  +    public static Test createTestFromFile(String fileName) {
  +        Test result = null;
  +        File file = new File(fileName);
  +        if (file.exists()) {
  +            result = createTestFromFile(file);
  +        } else {
  +            _log.error("Input file " + file.getAbsolutePath() +
  +                       " does not exist");
  +        }
  +        return result;
  +    }
  +
  +    /**
  +     * Create a Test from a {@link java.io.File Java file}
  +     * @param file A readable java file containing Latka's XML format 
  +     * @return a JUnit Test, ready to run
  +     */   
  +    public static Test createTestFromFile(File file) {
  +        Test result = null;
  +        try {
  +            result = createTestFromURL(file.toURL());
  +        } catch (MalformedURLException e) {
  +            _log.error("Could not access input file", e);
  +        }
  +        return result;
  +    }
  +
  +    /**
  +     * Create a Test from a resource accessible via
  +     * the {@link java.lang.ClassLoader#getResource(String) class loader}
  +     * @param resourceName A resource accessible by the class loader in Latka's XML format
  +     * @return a JUnit Test, ready to run
  +     */   
  +    public static Test createTestFromResource(String resourceName) {
  +        Test result = null;
  +        ClassLoader loader = JUnitTestAdapter.class.getClassLoader();
  +        URL resource = loader.getResource(resourceName);
  +        if (resource != null) {
  +            result = createTestFromURL(resource);
  +        }
  +        return result;
  +    }
  +
  +    /**
  +     * Create a Test from a String containing a URL whose
  +     * contents are in Latka's XML format
  +     * @param url the {@link java.net.URL URL} to fetch
  +     * @return a JUnit Test, ready to run
  +     */   
  +    public static Test createTestFromURL(String url) {
  +        Test result = null;
  +        try {
  +            result = createTestFromURL(new URL(url));
  +        } catch (MalformedURLException e) {
  +            _log.error("Unable to create URL " + url, e);
  +        }
  +        return result;
  +    }
  +
  +    /**
  +     * Create a Test from a URL whose contents are in Latka's XML format
  +     * @param url the {@link java.net.URL URL} to fetch
  +     * @return a JUnit Test, ready to run
  +     */   
  +    public static Test createTestFromURL(URL url) {
  +        Test result = null;
  +        try {
  +            InputSource source = new InputSource(url.toString());
  +            Suite suite = new Suite(url);
  +            result = new JUnitTestAdapter(suite, parse(source));
  +        } catch (Throwable t) {
  +            _log.error("Unable to obtain xml from URL " + url.toString(), t);
  +        }
  +        return result;
  +    }
  +
  +    /**
  +     * Parse the Latka XML document to count the requests
  +     * @param xml The inputsource to parse
  +     * @throws IOException When an IO occurs reading the document
  +     * @throws SAXException When the document is invalid XML 
  +     * @throws FactoryConfigurationError When the SAX Parser factory can't be configured
correctly
  +     * @throws ParserConfigurationException When the SAX Parser can't be configured correctly
  +     * @return the number of tests in the Latka suite
  +     */   
  +    protected static int parse(InputSource xml) throws IOException, SAXException,
  +                     FactoryConfigurationError, ParserConfigurationException {
  +        int result = 0;
  +        XMLReader reader = null;
  +        SAXParserFactory factory = SAXParserFactory.newInstance();
  +        factory.setValidating(false);   
  +        SAXParser parser = factory.newSAXParser();
  +        reader = parser.getXMLReader();
  +        TestCounter handler = new TestCounter();
  +        reader.setContentHandler(handler);
  +        reader.parse(xml);
  +        result = handler.getCount();
  +        return result;
  +    }
  +
  +    /**
  +     * A SAX Handler to count the number of <code>request</code> tags in the
document
  +     *
  +     * @author Chuck Burdick
  +     * @author dIon Gillard
  +     * @version $Id: JUnitTestAdapter.java,v 1.7 2002/02/03 13:22:27 dion Exp $
  +     */
  +    private static class TestCounter extends DefaultHandler {
  +        /** number of requests (i.e. junit tests) */
  +        private int _count = 0;
         
  -      /**
  -       * Create a DefaultHandler to count request elements
  -       */      
  -      public TestCounter() { _count = 0; }
  +        /**
  +         * Create a DefaultHandler to count request elements
  +         */      
  +        public TestCounter() {
  +            _count = 0;
  +        }
         
  -      /**
  -       * process the start of an xml element
  -       * @param uri uri
  -       * @param localName localName
  -       * @param qName qName
  -       * @param atts atts
  -       */      
  -      public void startElement(
  -         String uri, String localName, String qName, Attributes atts) {
  -         if (qName.equals("request")) { _count++; }
  -      }
  -      /**
  -       * Provides the number of &lt;request&gt; tags
  -       * @return the count of request elements found
  -       */      
  -      public int getCount() { return _count; }
  -   }
  -
  -   /**
  -    * Provides access, post-parsing, of the number of
  -    * request elements in the Latka Suite 
  -    * @return the number of test cases in the Latka suite
  -    */
  -   public int countTestCases() {
  -      return _testCount;
  -   }
  -
  -   /**
  -    * Run the test, adding results to the provided {@link junit.framework.TestResult TestResult}
  -    * @param r TestResult to accumulate
  -    */      
  -   public void run(TestResult r) {
  -      _log.debug("Attempting to perform latka tests");
  -      Latka latka = new Latka();
  -      try {
  -         latka.runTests(_latkaSuite, new JUnitEventReporter(r));
  -      } catch (LatkaException e) {
  -         _log.error("Unable to execute latka tests", e);
  -      }
  -   }
  -}
  +        /**
  +         * process the start of an xml element
  +         * @param uri uri
  +         * @param localName localName
  +         * @param qName qName
  +         * @param atts atts
  +         */      
  +        public void startElement(String uri, String localName, String qName, 
  +                                 Attributes atts) {
  +            if (qName.equals("request")) {
  +                _count++;
  +            }
  +        }
  +        
  +        /**
  +         * Provides the number of &lt;request&gt; tags
  +         * @return the count of request elements found
  +         */      
  +        public int getCount() {
  +            return _count;
  +        }
  +    }
  +
  +    /**
  +     * Provides access, post-parsing, of the number of
  +     * request elements in the Latka Suite 
  +     * @return the number of test cases in the Latka suite
  +     */
  +    public int countTestCases() {
  +        return _testCount;
  +    }
  +
  +    /**
  +     * Run the test, adding results to the provided {@link junit.framework.TestResult TestResult}
  +     * @param r TestResult to accumulate
  +     */      
  +    public void run(TestResult r) {
  +        _log.debug("Attempting to perform latka tests");
  +        Latka latka = new Latka();
  +        try {
  +            latka.runTests(_latkaSuite, new JUnitEventReporter(r));
  +        } catch (LatkaException e) {
  +            _log.error("Unable to execute latka tests", e);
  +        }
  +    }
  +}
  \ No newline at end of file
  
  
  

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