You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kr...@apache.org on 2012/12/22 16:25:36 UTC

git commit: o Added testcase for report parser when hitting incorrect files

Updated Branches:
  refs/heads/master 4f65754ba -> dd13e351d


o Added testcase for report parser when hitting incorrect files


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/dd13e351
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/dd13e351
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/dd13e351

Branch: refs/heads/master
Commit: dd13e351d580e92ec62fbf59f52e3a2c2691e942
Parents: 4f65754
Author: Kristian Rosenvold <kr...@apache.org>
Authored: Sat Dec 22 16:00:35 2012 +0100
Committer: Kristian Rosenvold <kr...@apache.org>
Committed: Sat Dec 22 16:24:44 2012 +0100

----------------------------------------------------------------------
 .../surefire/report/TestSuiteXmlParser.java        |   22 +++++++++++++-
 .../surefire/report/TestSuiteXmlParserTest.java    |   11 +++++++
 .../testsuitexmlparser/failsafe-summary-old.xml    |    8 +++++
 .../testsuitexmlparser/failsafe-summary.xml        |    8 +++++
 .../testsuitexmlparser/failsafe-summary-old.xml    |    8 -----
 .../testsuitexmlparser/failsafe-summary.xml        |    8 -----
 6 files changed, 47 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/dd13e351/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java
----------------------------------------------------------------------
diff --git a/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java b/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java
index 49e7c15..acc0256 100644
--- a/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java
+++ b/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java
@@ -62,6 +62,8 @@ public class TestSuiteXmlParser
 
     private ReportTestCase testCase;
 
+    private boolean valid = true;
+
     public Collection<ReportTestSuite> parse( String xmlPath )
         throws ParserConfigurationException, SAXException, IOException
     {
@@ -108,6 +110,10 @@ public class TestSuiteXmlParser
     public void startElement( String uri, String localName, String qName, Attributes attributes )
         throws SAXException
     {
+        if ( !valid )
+        {
+            return;
+        }
         try
         {
             if ( "testsuite".equals( qName ) )
@@ -169,7 +175,7 @@ public class TestSuiteXmlParser
 
                 String timeAsString = attributes.getValue( "time" );
 
-                Number time = new Integer( 0 );
+                Number time = 0;
 
                 if ( timeAsString != null )
                 {
@@ -199,6 +205,10 @@ public class TestSuiteXmlParser
                 testCase.addFailure( message != null ? message : "skipped", "skipped" );
                 currentSuite.setNumberOfSkipped( 1 + currentSuite.getNumberOfSkipped() );
             }
+            else if ( "failsafe-summary".equals( qName ) )
+            {
+                valid = false;
+            }
         }
         catch ( ParseException e )
         {
@@ -249,6 +259,10 @@ public class TestSuiteXmlParser
     public void characters( char[] ch, int start, int length )
         throws SAXException
     {
+        if ( !valid )
+        {
+            return;
+        }
         String s = new String( ch, start, length );
 
         if ( !"".equals( s.trim() ) )
@@ -273,7 +287,7 @@ public class TestSuiteXmlParser
         {
             String lineString = stringTokenizer.nextToken().trim();
             parsedDetail.add( lineString );
-            if ( lineString.indexOf( compareTo ) >= 0 )
+            if ( lineString.contains( compareTo ) )
             {
                 break;
             }
@@ -282,4 +296,8 @@ public class TestSuiteXmlParser
         return parsedDetail;
     }
 
+    public boolean isValid()
+    {
+        return valid;
+    }
 }

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/dd13e351/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java
----------------------------------------------------------------------
diff --git a/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java b/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java
index 27e4a53..344eb02 100644
--- a/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java
+++ b/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java
@@ -96,4 +96,15 @@ public class TestSuiteXmlParserTest
 
     }
 
+    public void testParserHitsSum()
+        throws IOException, SAXException, ParserConfigurationException
+    {
+        TestSuiteXmlParser parser = new TestSuiteXmlParser();
+
+        parser.parse( "src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml" );
+
+        assertFalse( parser.isValid() );
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/dd13e351/maven-surefire-report-plugin/src/test/resources/fixture/testsuitexmlparser/failsafe-summary-old.xml
----------------------------------------------------------------------
diff --git a/maven-surefire-report-plugin/src/test/resources/fixture/testsuitexmlparser/failsafe-summary-old.xml b/maven-surefire-report-plugin/src/test/resources/fixture/testsuitexmlparser/failsafe-summary-old.xml
new file mode 100644
index 0000000..6839aa9
--- /dev/null
+++ b/maven-surefire-report-plugin/src/test/resources/fixture/testsuitexmlparser/failsafe-summary-old.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<failsafe-summary timeout="false">
+  <completed>1</completed>
+  <errors>0</errors>
+  <failures>1</failures>
+  <skipped>0</skipped>
+  <failureMessage/>
+</failsafe-summary>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/dd13e351/maven-surefire-report-plugin/src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml
----------------------------------------------------------------------
diff --git a/maven-surefire-report-plugin/src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml b/maven-surefire-report-plugin/src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml
new file mode 100644
index 0000000..1bc82d9
--- /dev/null
+++ b/maven-surefire-report-plugin/src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<failsafe-summary timeout="false">
+  <completed>4</completed>
+  <errors>0</errors>
+  <failures>2</failures>
+  <skipped>0</skipped>
+  <failureMessage/>
+</failsafe-summary>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/dd13e351/surefire-integration-tests/src/test/resources/fixture/testsuitexmlparser/failsafe-summary-old.xml
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/fixture/testsuitexmlparser/failsafe-summary-old.xml b/surefire-integration-tests/src/test/resources/fixture/testsuitexmlparser/failsafe-summary-old.xml
deleted file mode 100644
index 6839aa9..0000000
--- a/surefire-integration-tests/src/test/resources/fixture/testsuitexmlparser/failsafe-summary-old.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<failsafe-summary timeout="false">
-  <completed>1</completed>
-  <errors>0</errors>
-  <failures>1</failures>
-  <skipped>0</skipped>
-  <failureMessage/>
-</failsafe-summary>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/dd13e351/surefire-integration-tests/src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml b/surefire-integration-tests/src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml
deleted file mode 100644
index 1bc82d9..0000000
--- a/surefire-integration-tests/src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<failsafe-summary timeout="false">
-  <completed>4</completed>
-  <errors>0</errors>
-  <failures>2</failures>
-  <skipped>0</skipped>
-  <failureMessage/>
-</failsafe-summary>
\ No newline at end of file