6
6
import org .junit .jupiter .api .Disabled ;
7
7
import org .junit .jupiter .params .ParameterizedTest ;
8
8
import org .junit .jupiter .params .provider .MethodSource ;
9
+ import org .xmlunit .assertj .XmlAssert ;
9
10
import org .xmlunit .builder .Input ;
10
11
import org .xmlunit .validation .JAXPValidator ;
11
12
import org .xmlunit .validation .Languages ;
20
21
import java .nio .file .Files ;
21
22
import java .nio .file .Path ;
22
23
import java .nio .file .Paths ;
24
+ import java .util .ArrayList ;
23
25
import java .util .Arrays ;
24
26
import java .util .Comparator ;
25
27
import java .util .List ;
28
30
import java .util .stream .Stream ;
29
31
30
32
import static io .cucumber .junitxmlformatter .Jackson .OBJECT_MAPPER ;
33
+ import static org .assertj .core .api .Assertions .assertThat ;
31
34
import static org .xmlunit .assertj .XmlAssert .assertThat ;
32
35
33
36
class MessagesToJunitXmlWriterAcceptanceTest {
@@ -49,7 +52,7 @@ void test(TestCase testCase) throws IOException {
49
52
ByteArrayOutputStream bytes = writeJunitXmlReport (testCase , new ByteArrayOutputStream ());
50
53
Source expected = Input .fromPath (testCase .expected ).build ();
51
54
Source actual = Input .fromByteArray (bytes .toByteArray ()).build ();
52
- assertThat (actual ).and (expected ).ignoreWhitespace ().areIdentical ();
55
+ XmlAssert . assertThat (actual ).and (expected ).ignoreWhitespace ().areIdentical ();
53
56
}
54
57
55
58
@ ParameterizedTest
@@ -58,7 +61,7 @@ void validateAgainstJenkins(TestCase testCase) throws IOException {
58
61
ByteArrayOutputStream bytes = writeJunitXmlReport (testCase , new ByteArrayOutputStream ());
59
62
Source actual = Input .fromByteArray (bytes .toByteArray ()).build ();
60
63
Source jenkinsSchema = Input .fromPath (Paths .get ("../jenkins-junit.xsd" )).build ();
61
- assertThat (actual ).isValidAgainst (jenkinsSchema );
64
+ XmlAssert . assertThat (actual ).isValidAgainst (jenkinsSchema );
62
65
}
63
66
64
67
static final List <String > testCasesWithMissingException = Arrays .asList (
@@ -76,11 +79,16 @@ void validateAgainstSurefire(TestCase testCase) throws IOException {
76
79
ByteArrayOutputStream bytes = writeJunitXmlReport (testCase , new ByteArrayOutputStream ());
77
80
Source actual = Input .fromByteArray (bytes .toByteArray ()).build ();
78
81
Source surefireSchema = Input .fromPath (Paths .get ("../surefire-test-report-3.0.xsd" )).build ();
79
- if (!testCasesWithMissingException .contains (testCase .name )) {
80
- assertThat (actual ).isValidAgainst (surefireSchema );
81
- return ;
82
- }
83
82
83
+ JAXPValidator validator = new JAXPValidator (Languages .W3C_XML_SCHEMA_NS_URI );
84
+ validator .setSchemaSource (surefireSchema );
85
+ ValidationResult validationResult = validator .validateInstance (actual );
86
+
87
+ List <String > expectedProblems = new ArrayList <>();
88
+ /*
89
+ * We add the timestamp attribute to all reports.
90
+ */
91
+ expectedProblems .add ("cvc-complex-type.3.2.2: Attribute 'timestamp' is not allowed to appear in element 'testsuite'." );
84
92
/*
85
93
This report tries to be compatible with the Jenkins XSD. The Surefire
86
94
XSD is a bit stricter and generally assumes tests fail with an
@@ -94,12 +102,11 @@ void validateAgainstSurefire(TestCase testCase) throws IOException {
94
102
Since the Surefire XSD is also relatively popular we do check it and
95
103
exclude the cases that don't pass selectively.
96
104
*/
97
- JAXPValidator validator = new JAXPValidator ( Languages . W3C_XML_SCHEMA_NS_URI );
98
- validator . setSchemaSource ( surefireSchema );
99
- ValidationResult validationResult = validator . validateInstance ( actual );
105
+ if ( testCasesWithMissingException . contains ( testCase . name )) {
106
+ expectedProblems . add ( "cvc-complex-type.4: Attribute 'type' must appear on element 'failure'." );
107
+ }
100
108
Iterable <ValidationProblem > problems = validationResult .getProblems ();
101
- Assertions .assertThat (problems ).extracting (ValidationProblem ::getMessage )
102
- .containsOnly ("cvc-complex-type.4: Attribute 'type' must appear on element 'failure'." );
109
+ assertThat (problems ).extracting (ValidationProblem ::getMessage ).containsAll (expectedProblems );
103
110
}
104
111
105
112
@ ParameterizedTest
0 commit comments