asfgit closed pull request #192: [SUREFIRE-1550] The surefire XSD published on 
maven site lacks of some
URL: https://github.com/apache/maven-surefire/pull/192
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/maven-surefire-plugin/src/site/resources/xsd/surefire-test-report.xsd 
b/maven-surefire-plugin/src/site/resources/xsd/surefire-test-report.xsd
index 2bad4aca7..684f17516 100644
--- a/maven-surefire-plugin/src/site/resources/xsd/surefire-test-report.xsd
+++ b/maven-surefire-plugin/src/site/resources/xsd/surefire-test-report.xsd
@@ -18,6 +18,11 @@
   ~ under the License.
   -->
 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";>
+    <xs:simpleType name="SUREFIRE_TIME">
+        <xs:restriction base="xs:string">
+            <xs:pattern 
value="(([0-9]{0,3},)*[0-9]{3}|[0-9]{0,3})*(\.[0-9]{0,3})?"/>
+        </xs:restriction>
+    </xs:simpleType>
     <xs:element name="testsuite">
         <xs:complexType>
             <xs:sequence>
@@ -42,14 +47,7 @@
                                         <xs:extension base="xs:string">
                                             <xs:attribute name="message" 
type="xs:string"/>
                                             <xs:attribute name="type" 
type="xs:string" use="required"/>
-                                            <xs:attribute name="time">
-                                                <xs:simpleType>
-                                                    <xs:restriction 
base="xs:string">
-                                                        <xs:pattern
-                                                                
value="(([0-9]{0,3},)*[0-9]{3}|[0-9]{0,3})*(\.[0-9]{0,3})?"/>
-                                                    </xs:restriction>
-                                                </xs:simpleType>
-                                            </xs:attribute>
+                                            <xs:attribute name="time" 
type="SUREFIRE_TIME" />
                                         </xs:extension>
                                     </xs:simpleContent>
                                 </xs:complexType>
@@ -60,18 +58,21 @@
                                         <xs:extension base="xs:string">
                                             <xs:attribute name="message" 
type="xs:string"/>
                                             <xs:attribute name="type" 
type="xs:string" use="required"/>
-                                            <xs:attribute name="time">
-                                                <xs:simpleType>
-                                                    <xs:restriction 
base="xs:string">
-                                                        <xs:pattern
-                                                                
value="(([0-9]{0,3},)*[0-9]{3}|[0-9]{0,3})*(\.[0-9]{0,3})?"/>
-                                                    </xs:restriction>
-                                                </xs:simpleType>
-                                            </xs:attribute>
+                                            <xs:attribute name="time" 
type="SUREFIRE_TIME" />
                                         </xs:extension>
                                     </xs:simpleContent>
                                 </xs:complexType>
                             </xs:element>
+                            <xs:element name="flakyFailure" nillable="true" 
minOccurs="0" maxOccurs="unbounded">
+                                <xs:complexType>
+                                    <xs:simpleContent>
+                                        <xs:extension base="xs:string">
+                                            <xs:attribute name="message" 
type="xs:string"/>
+                                            <xs:attribute name="type" 
type="xs:string" use="required"/>
+                                            <xs:attribute name="time" 
type="SUREFIRE_TIME" />                                        </xs:extension>
+                                    </xs:simpleContent>
+                                </xs:complexType>
+                            </xs:element>
                             <xs:element name="skipped" nillable="true" 
minOccurs="0" maxOccurs="1">
                                 <xs:complexType>
                                     <xs:simpleContent>
@@ -91,30 +92,38 @@
                                     </xs:simpleContent>
                                 </xs:complexType>
                             </xs:element>
+                            <xs:element name="rerunError" nillable="true" 
minOccurs="0" maxOccurs="unbounded">
+                                <xs:complexType>
+                                    <xs:simpleContent>
+                                        <xs:extension base="xs:string">
+                                            <xs:attribute name="message" 
type="xs:string"/>
+                                            <xs:attribute name="type" 
type="xs:string" use="required"/>
+                                            <xs:attribute name="time" 
type="SUREFIRE_TIME" />                                        </xs:extension>
+                                    </xs:simpleContent>
+                                </xs:complexType>
+                            </xs:element>
+                            <xs:element name="flakyError" nillable="true" 
minOccurs="0" maxOccurs="unbounded">
+                                <xs:complexType>
+                                    <xs:simpleContent>
+                                        <xs:extension base="xs:string">
+                                            <xs:attribute name="message" 
type="xs:string"/>
+                                            <xs:attribute name="type" 
type="xs:string" use="required"/>
+                                            <xs:attribute name="time" 
type="SUREFIRE_TIME" />                                        </xs:extension>
+                                    </xs:simpleContent>
+                                </xs:complexType>
+                            </xs:element>
                             <xs:element name="system-out" nillable="true" 
minOccurs="0" maxOccurs="1"/>
                             <xs:element name="system-err" nillable="true" 
minOccurs="0" maxOccurs="1"/>
                         </xs:sequence>
                         <xs:attribute name="name" type="xs:string" 
use="required"/>
                         <xs:attribute name="classname" type="xs:string"/>
                         <xs:attribute name="group" type="xs:string"/>
-                        <xs:attribute name="time" use="required">
-                            <xs:simpleType>
-                                <xs:restriction base="xs:string">
-                                    <xs:pattern 
value="(([0-9]{0,3},)*[0-9]{3}|[0-9]{0,3})*(\.[0-9]{0,3})?"/>
-                                </xs:restriction>
-                            </xs:simpleType>
-                        </xs:attribute>
+                        <xs:attribute name="time" type="SUREFIRE_TIME" 
use="required"/>
                     </xs:complexType>
                 </xs:element>
             </xs:sequence>
             <xs:attribute name="name" type="xs:string" use="required"/>
-            <xs:attribute name="time">
-                <xs:simpleType>
-                    <xs:restriction base="xs:string">
-                        <xs:pattern 
value="(([0-9]{0,3},)*[0-9]{3}|[0-9]{0,3})*(\.[0-9]{0,3})?"/>
-                    </xs:restriction>
-                </xs:simpleType>
-            </xs:attribute>
+            <xs:attribute name="time" type="SUREFIRE_TIME"/>
             <xs:attribute name="tests" type="xs:string" use="required"/>
             <xs:attribute name="errors" type="xs:string" use="required"/>
             <xs:attribute name="skipped" type="xs:string" use="required"/>
diff --git a/maven-surefire-report-plugin/pom.xml 
b/maven-surefire-report-plugin/pom.xml
index b19151524..1450d5262 100644
--- a/maven-surefire-report-plugin/pom.xml
+++ b/maven-surefire-report-plugin/pom.xml
@@ -103,6 +103,12 @@
       <version>1.2</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.xmlunit</groupId>
+      <artifactId>xmlunit-core</artifactId>
+      <version>2.6.0</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
diff --git 
a/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/SurefireSchemaValidationTest.java
 
b/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/SurefireSchemaValidationTest.java
new file mode 100644
index 000000000..c51887d14
--- /dev/null
+++ 
b/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/SurefireSchemaValidationTest.java
@@ -0,0 +1,100 @@
+package org.apache.maven.plugins.surefire.report;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.maven.shared.utils.io.DirectoryScanner;
+import org.fest.assertions.Assertions;
+import org.junit.Assert;
+import org.junit.Test;
+import org.xmlunit.validation.Languages;
+import org.xmlunit.validation.ValidationProblem;
+import org.xmlunit.validation.ValidationResult;
+import org.xmlunit.validation.Validator;
+
+public class SurefireSchemaValidationTest
+{
+
+    @Test
+    public void validate_XMLs_against_schema()
+        throws Exception
+    {
+        File basedir = getProjectBasedir();
+
+        File xsd = getSchemaFile( basedir );
+        Assert.assertTrue( "XSD schema validation not found", xsd.exists() );
+
+        // looks for all xml surefire report in test resources
+        DirectoryScanner ds = new DirectoryScanner();
+        ds.setBasedir( basedir );
+        ds.setIncludes( "**/TEST-*.xml" );
+        ds.scan();
+
+        String[] xmlFiles = ds.getIncludedFiles();
+        Assertions.assertThat( xmlFiles ).describedAs( "No XML surefire 
reports found to validate" ).isNotEmpty();
+
+        Validator v = Validator.forLanguage( Languages.W3C_XML_SCHEMA_NS_URI );
+        v.setSchemaSource( new StreamSource( xsd ) );
+
+        for ( String xmlFile : xmlFiles )
+        {
+            ValidationResult vr = v.validateInstance( new StreamSource( new 
File( basedir, xmlFile ) ) );
+            StringBuilder msg = new StringBuilder();
+            if ( !vr.isValid() )
+            {
+                msg.append( xmlFile ).append( " has violations:" );
+                for ( ValidationProblem problem : vr.getProblems() )
+                {
+                    msg.append( "\n" ) //
+                       .append( " - " ).append( problem.getType() ) //
+                       .append( " at row:" ).append( problem.getLine() ) //
+                       .append( " col:" ).append( problem.getColumn() ) //
+                       .append( ' ' ).append( problem.getMessage() );
+                }
+            }
+            Assert.assertTrue( Utils.toSystemNewLine( msg.toString() ), 
vr.isValid() );
+        }
+    }
+
+    private File getProjectBasedir()
+        throws URISyntaxException
+    {
+        // get the root path of test-classes
+        URL basedirURL = 
SurefireSchemaValidationTest.class.getClassLoader().getResource( "." );
+        return new File( basedirURL.toURI() );
+    }
+
+    private File getSchemaFile( File basedir )
+        throws IOException
+    {
+        // get the schema file placed in a different module
+        Path xsd = Paths.get( basedir.getAbsolutePath(), "..", "..", "..", 
"maven-surefire-plugin", "src", "site",
+                              "resources", "xsd", "surefire-test-report.xsd" );
+        return xsd.toFile().getCanonicalFile();
+    }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to