You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2018/08/17 12:10:51 UTC
[maven-surefire] 01/01: [SUREFIRE-1550] The surefire XSD published
on maven site lacks of some rerun element
This is an automated email from the ASF dual-hosted git repository.
tibordigana pushed a commit to branch SUREFIRE-1550
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
commit 429a2390ce943be0fbeb471032f1c2085d684c05
Author: Nikolas Falco <nf...@hotmail.com>
AuthorDate: Wed Aug 15 13:18:17 2018 +0200
[SUREFIRE-1550] The surefire XSD published on maven site lacks of some
rerun element
Add missing XSD elements generated by the rerun feature.
Add a test case to validate XML in maven-surefire-report-plugin/src/test/resources/**/TEST-*.xml against the surefire schema
---
.../site/resources/xsd/surefire-test-report.xsd | 69 +++++++-------
maven-surefire-report-plugin/pom.xml | 6 ++
.../report/SurefireSchemaValidationTest.java | 100 +++++++++++++++++++++
3 files changed, 145 insertions(+), 30 deletions(-)
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 2bad4ac..684f175 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 b191515..1450d52 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 0000000..c51887d
--- /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();
+ }
+}