stevel      2005/05/13 14:42:23

  Modified:    src/etc/testcases/taskdefs/optional junitreport.xml
               src/main/org/apache/tools/ant/taskdefs/optional/junit
                        XMLResultAggregator.java
               src/testcases/org/apache/tools/ant/taskdefs/optional/junit
                        JUnitReportTest.java
  Added:       src/etc/testcases/taskdefs/optional/junitreport
                        INCOMPLETE-sampleproject.incomplete.xml
                        NAMESPACE-sampleproject.namespace.xml
                        WRONGELEMENT-sampleproject.wrongelement.xml
                        ZEROBYTES-sampleproject.package.xml
  Log:
  tests for junitreport handling various forms of bad data, plus explicit 
handling of zero-byte files with a different error message..
  
  Revision  Changes    Path
  1.1                  
ant/src/etc/testcases/taskdefs/optional/junitreport/INCOMPLETE-sampleproject.incomplete.xml
  
  Index: INCOMPLETE-sampleproject.incomplete.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <testsuite errors="0" failures="0" name="sampleproject.incomplete" tests="5" 
time="0.038">
    </properties>
    <testcase name="testEquals" time="0.0"></testcase>
    <testcase name="testHashCode" time="0.0"></testcase>
    <testcase name="testToString" time="0.0010"></testcase>
    <testcase name="testgetUniqueString" time="0.0"></testcase>
    <testcase name="testSerialization" time="0.024"></testcase>
    <system-out><![CDATA[testEquals
  testHashCode
  testToString
  testgetUniqueString
  testSerialization
  ]]></system-out>
    <system-err>
  
  
  
  1.1                  
ant/src/etc/testcases/taskdefs/optional/junitreport/NAMESPACE-sampleproject.namespace.xml
  
  Index: NAMESPACE-sampleproject.namespace.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <ns:testsuite errors="1" failures="1" name="sampleproject.namespace" 
tests="11" time="0.171" xmlns:ns="funny-namespace">
    <properties>
      <property name="testsrc" value="test/"></property>
      <property name="java.runtime.name" value="Java(TM) 2 Runtime Environment, 
Standard Edition"></property>
      <property name="sun.boot.library.path" 
value="/usr/java/jdk1.3.1_03/jre/lib/i386"></property>
      <property name="java.vm.version" value="1.3.1_03-b03"></property>
      <property name="ant.version" value="Apache Ant version 1.5 compiled on 
July 9 2002"></property>
      <property name="ant.java.version" value="1.3"></property>
      <property name="java.vm.vendor" value="Sun Microsystems Inc."></property>
      <property name="java.vendor.url" value="http://java.sun.com/";></property>
      <property name="path.separator" value=":"></property>
      <property name="java.vm.name" value="Java HotSpot(TM) Client 
VM"></property>
      <property name="file.encoding.pkg" value="sun.io"></property>
      <property name="classes" value="classes"></property>
      <property name="java.vm.specification.name" value="Java Virtual Machine 
Specification"></property>
      <property name="user.dir" 
value="/home/jkf/programming/gretant_sourceforge/sampleproject"></property>
      <property name="java.runtime.version" value="1.3.1_03-b03"></property>
      <property name="java.awt.graphicsenv" 
value="sun.awt.X11GraphicsEnvironment"></property>
      <property name="basedir" 
value="/home/jkf/programming/gretant_sourceforge/sampleproject"></property>
      <property name="os.arch" value="i386"></property>
      <property name="java.io.tmpdir" value="/tmp"></property>
      <property name="line.separator" value="
  "></property>
      <property name="java.vm.specification.vendor" value="Sun Microsystems 
Inc."></property>
      <property name="java.awt.fonts" value=""></property>
      <property name="os.name" value="Linux"></property>
      <property name="ant.home" value="/opt/jakarta-ant-1.5/"></property>
      <property name="ant.project.name" value="sample"></property>
      <property name="reportdir" value="reports"></property>
      <property name="java.library.path" 
value="/usr/java/jdk1.3.1_03/jre/lib/i386:/usr/java/jdk1.3.1_03/jre/lib/i386/native_threads/:/usr/java/jdk1.3.1_03/jre/lib/i386/client:/usr/java/jdk1.3.1_03/jre/../lib/i386"></property>
      <property name="src" value="code/"></property>
      <property name="debug" value="on"></property>
      <property name="java.specification.name" value="Java Platform API 
Specification"></property>
      <property name="java.class.version" value="47.0"></property>
      <property name="os.version" value="2.4.18-5"></property>
      <property name="ant.file" 
value="/home/jkf/programming/gretant_sourceforge/sampleproject/build.xml"></property>
      <property name="unitreport" value="cl-unit.xml"></property>
      <property name="user.home" value="/home/jkf"></property>
      <property name="user.timezone" value="Europe/Amsterdam"></property>
      <property name="java.awt.printerjob" 
value="sun.awt.motif.PSPrinterJob"></property>
      <property name="java.specification.version" value="1.3"></property>
      <property name="file.encoding" value="ISO-8859-15"></property>
      <property name="java.class.path" 
value="/opt/jakarta-ant-1.5//lib/xml-apis.jar:/opt/jakarta-ant-1.5//lib/xercesImpl.jar:/opt/jakarta-ant-1.5//lib/xalan.jar:/opt/jakarta-ant-1.5//lib/optional.jar:/opt/jakarta-ant-1.5//lib/junit.jar:/opt/jakarta-ant-1.5//lib/Gretel.jar:/opt/jakarta-ant-1.5//lib/gretant.jar:/opt/jakarta-ant-1.5//lib/cup-runtime.jar:/opt/jakarta-ant-1.5//lib/bcel.jar:/opt/jakarta-ant-1.5//lib/ant.jar:/usr/java/jdk1.3/lib/tools.jar"></property>
      <property name="user.name" value="jkf"></property>
      <property name="coverreport" value="cl-cover.xml"></property>
      <property name="java.vm.specification.version" value="1.0"></property>
      <property name="java.home" value="/usr/java/jdk1.3.1_03/jre"></property>
      <property name="java.specification.vendor" value="Sun Microsystems 
Inc."></property>
      <property name="user.language" value="en"></property>
      <property name="java.vm.info" value="mixed mode"></property>
      <property name="java.version" value="1.3.1_03"></property>
      <property name="java.ext.dirs" 
value="/usr/java/jdk1.3.1_03/jre/lib/ext"></property>
      <property name="sun.boot.class.path" 
value="/usr/java/jdk1.3.1_03/jre/lib/rt.jar:/usr/java/jdk1.3.1_03/jre/lib/i18n.jar:/usr/java/jdk1.3.1_03/jre/lib/sunrsasign.jar:/usr/java/jdk1.3.1_03/jre/classes"></property>
      <property name="java.vendor" value="Sun Microsystems Inc."></property>
      <property name="file.separator" value="/"></property>
      <property name="testclasses" value="testclasses"></property>
      <property name="java.vendor.url.bug" 
value="http://java.sun.com/cgi-bin/bugreport.cgi";></property>
      <property name="sun.io.unicode.encoding" value="UnicodeLittle"></property>
      <property name="sun.cpu.endian" value="little"></property>
      <property name="gretclasses" value="gretclasses"></property>
      <property name="user.region" value="US"></property>
      <property name="sun.cpu.isalist" value=""></property>
    </properties>
    <testcase name="testEquals" time="0.014"></testcase>
    <testcase name="testHashCode" time="0.0010"></testcase>
    <testcase name="testToString" time="0.0010"></testcase>
    <testcase name="testGetImageURL" time="0.0"></testcase>
    <testcase name="testGetCountry" time="0.0010"></testcase>
    <testcase name="testGetDenomination" time="0.0"></testcase>
    <testcase name="testGetYear" time="0.0"></testcase>
    <testcase name="testGetSubType" time="0.0"></testcase>
    <testcase name="testFail" time="0.0080">
      <failure message="DOEG" 
type="junit.framework.AssertionFailedError">junit.framework.AssertionFailedError:
 DOEG
        at sampleproject.coins.CoinTest.testFail(CoinTest.java:229)
  </failure>
    </testcase>
    <testcase name="testException" time="0.0010">
      <error message="RTE" 
type="java.lang.RuntimeException">java.lang.RuntimeException: RTE
        at sampleproject.coins.CoinTest.testException(CoinTest.java:234)
  </error>
    </testcase>
    <testcase name="testSuccess" time="0.0"></testcase>
    <system-out><![CDATA[testEquals
  testHashCode
  Hashcodes: 1434557225 1434557225 1434557226 1463186376 1434556908 1516980401 
1434557225
  testToString
  <Coin=NL,1 Euro,1999,Var a/>
  <Coin=NL,1 Euro,1999,null/>
  testGetImageURL
  testGetCountry
  testGetDenomination
  testGetYear
  testGetSubType
  testFail
  testException
  testSuccess
  ]]></system-out>
    <system-err><![CDATA[]]></system-err>
  </ns:testsuite>
  
  
  
  1.1                  
ant/src/etc/testcases/taskdefs/optional/junitreport/WRONGELEMENT-sampleproject.wrongelement.xml
  
  Index: WRONGELEMENT-sampleproject.wrongelement.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <wildebeast/>
  
  
  
  1.1                  
ant/src/etc/testcases/taskdefs/optional/junitreport/ZEROBYTES-sampleproject.package.xml
  
        <<Binary file>>
  
  
  1.2       +44 -0     ant/src/etc/testcases/taskdefs/optional/junitreport.xml
  
  Index: junitreport.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/optional/junitreport.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- junitreport.xml   26 Sep 2002 12:11:37 -0000      1.1
  +++ junitreport.xml   13 May 2005 21:42:23 -0000      1.2
  @@ -18,6 +18,50 @@
               <report todir="${outputdir}/html"/>
           </junitreport>
       </target>
  +
  +    <target name="testEmptyFile">
  +        <mkdir dir="${outputdir}/html"/>
  +        <junitreport todir="${outputdir}">
  +            <fileset dir="${jrdir}">
  +                <include name="ZEROBYTES-*.xml"/>
  +                <include name="TEST-*.xml"/>
  +            </fileset>
  +            <report todir="${outputdir}/html"/>
  +        </junitreport>
  +    </target>
  +    
  +    <target name="testIncompleteFile">
  +        <mkdir dir="${outputdir}/html"/>
  +        <junitreport todir="${outputdir}">
  +            <fileset dir="${jrdir}">
  +                <include name="INCOMPLETE-*.xml"/>
  +                <include name="TEST-*.xml"/>
  +            </fileset>
  +            <report todir="${outputdir}/html"/>
  +        </junitreport>
  +    </target>
  +    
  +    <target name="testWrongElement">
  +        <mkdir dir="${outputdir}/html"/>
  +        <junitreport todir="${outputdir}">
  +            <fileset dir="${jrdir}">
  +                <include name="WRONGELEMENT-*.xml"/>
  +                <include name="TEST-*.xml"/>
  +            </fileset>
  +            <report todir="${outputdir}/html"/>
  +        </junitreport>
  +    </target>    
  +
  +    <target name="testNamespace">
  +        <mkdir dir="${outputdir}/html"/>
  +        <junitreport todir="${outputdir}">
  +            <fileset dir="${jrdir}">
  +                <include name="NAMESPACE-*.xml"/>
  +                <include name="TEST-*.xml"/>
  +            </fileset>
  +            <report todir="${outputdir}/html"/>
  +        </junitreport>
  +    </target>        
       
       <target name="clean">
           <delete dir="${outputdir}"/>
  
  
  
  1.34      +35 -18    
ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java
  
  Index: XMLResultAggregator.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- XMLResultAggregator.java  14 Mar 2005 09:19:50 -0000      1.33
  +++ XMLResultAggregator.java  13 May 2005 21:42:23 -0000      1.34
  @@ -77,6 +77,19 @@
       protected int generatedId = 0;
   
       /**
  +     * text checked for in tests, [EMAIL PROTECTED]
  +     */
  +    static final String WARNING_IS_POSSIBLY_CORRUPTED = " is not a valid XML 
document. It is possibly corrupted.";
  +    /**
  +     * text checked for in tests, [EMAIL PROTECTED]
  +     */
  +    static final String WARNING_INVALID_ROOT_ELEMENT = " is not a valid 
testsuite XML document";
  +    /**
  +     * text checked for in tests, [EMAIL PROTECTED]
  +     */
  +    static final String WARNING_EMPTY_FILE = " is empty.\nThis can be caused 
by the test JVM exiting unexpectedly";
  +
  +    /**
        * Generate a report based on the document created by the merge.
        * @return the report
        */
  @@ -228,32 +241,36 @@
           // get all files and add them to the document
           File[] files = getFiles();
           for (int i = 0; i < files.length; i++) {
  +            File file = files[i];
               try {
  -                log("Parsing file: '" + files[i] + "'", Project.MSG_VERBOSE);
  -                //XXX there seems to be a bug in xerces 1.3.0 that doesn't 
like file object
  -                // will investigate later. It does not use the given 
directory but
  -                // the vm dir instead ? Works fine with crimson.
  -                Document testsuiteDoc
  -                    = builder.parse("file:///" + files[i].getAbsolutePath());
  -                Element elem = testsuiteDoc.getDocumentElement();
  -                // make sure that this is REALLY a testsuite.
  -                if (TESTSUITE.equals(elem.getNodeName())) {
  -                    addTestSuite(rootElement, elem);
  -                    generatedId++;
  +                log("Parsing file: '" + file + "'", Project.MSG_VERBOSE);
  +                if(file.length()>0) {
  +                    Document testsuiteDoc
  +                            = builder.parse("file:///" + 
file.getAbsolutePath());
  +                    Element elem = testsuiteDoc.getDocumentElement();
  +                    // make sure that this is REALLY a testsuite.
  +                    if (TESTSUITE.equals(elem.getNodeName())) {
  +                        addTestSuite(rootElement, elem);
  +                        generatedId++;
  +                    } else {
  +                        //wrong root element name
  +                        // issue a warning.
  +                        log("the file " + file
  +                                + WARNING_INVALID_ROOT_ELEMENT,
  +                                Project.MSG_WARN);
  +                    }
                   } else {
  -                    // issue a warning.
  -                    log("the file " + files[i]
  -                        + " is not a valid testsuite XML document",
  -                        Project.MSG_WARN);
  +                    log("the file " + file
  +                            + WARNING_EMPTY_FILE,
  +                            Project.MSG_WARN);
                   }
               } catch (SAXException e) {
                   // a testcase might have failed and write a zero-length 
document,
                   // It has already failed, but hey.... mm. just put a warning
  -                log("The file " + files[i] + " is not a valid XML document. "
  -                    + "It is possibly corrupted.", Project.MSG_WARN);
  +                log("The file " + file + WARNING_IS_POSSIBLY_CORRUPTED, 
Project.MSG_WARN);
                   log(StringUtils.getStackTrace(e), Project.MSG_DEBUG);
               } catch (IOException e) {
  -                log("Error while accessing file " + files[i] + ": "
  +                log("Error while accessing file " + file + ": "
                       + e.getMessage(), Project.MSG_ERR);
               }
           }
  
  
  
  1.8       +36 -0     
ant/src/testcases/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java
  
  Index: JUnitReportTest.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JUnitReportTest.java      7 Dec 2004 09:10:38 -0000       1.7
  +++ JUnitReportTest.java      13 May 2005 21:42:23 -0000      1.8
  @@ -52,5 +52,41 @@
           }
       }
   
  +    public void assertIndexCreated() {
  +        if (!new File(System.getProperty("root"),
  +                
"src/etc/testcases/taskdefs/optional/junitreport/test/html/index.html").exists())
 {
  +            fail("No file index file found");
  +        }
  +
  +    }
  +
  +    /**
  +     * run a target, assert the index file is there, look for text in the log
  +     * @param targetName target
  +     * @param text optional text to look for
  +     */
  +    private void expectReportWithText(String targetName, String text) {
  +        executeTarget(targetName);
  +        assertIndexCreated();
  +        if(text!=null) {
  +            assertLogContaining(text);
  +        }
  +    }
  +
  +
  +    public void testEmptyFile() throws Exception {
  +        expectReportWithText("testEmptyFile",
  +                XMLResultAggregator.WARNING_EMPTY_FILE);
  +    }
  +
  +    public void testIncompleteFile() throws Exception {
  +        expectReportWithText("testIncompleteFile",
  +                XMLResultAggregator.WARNING_IS_POSSIBLY_CORRUPTED);
  +    }
  +    public void testWrongElement() throws Exception {
  +        expectReportWithText("testWrongElement",
  +                XMLResultAggregator.WARNING_INVALID_ROOT_ELEMENT);
  +    }
  +
   }
   
  
  
  

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

Reply via email to