Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion java/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -67,6 +68,13 @@
<version>[14.0.1,15.0.0)</version>
</dependency>

<dependency>
<groupId>io.cucumber</groupId>
<artifactId>compatibility-kit</artifactId>
<version>23.2.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.cucumber.junitxmlformatter;

import io.cucumber.compatibilitykit.MessageOrderer;
import io.cucumber.messages.NdjsonToMessageIterable;
import io.cucumber.messages.types.Envelope;
import org.assertj.core.api.Assertions;
Expand All @@ -23,7 +24,8 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Random;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -32,6 +34,8 @@

class MessagesToJunitXmlWriterAcceptanceTest {
private static final NdjsonToMessageIterable.Deserializer deserializer = (json) -> OBJECT_MAPPER.readValue(json, Envelope.class);
private static final Random random = new Random(202509282040L);
private static final MessageOrderer messageOrderer = new MessageOrderer(random);

static List<TestCase> acceptance() throws IOException {
try (Stream<Path> paths = Files.list(Paths.get("../testdata/src"))) {
Expand All @@ -46,16 +50,24 @@ static List<TestCase> acceptance() throws IOException {
@ParameterizedTest
@MethodSource("acceptance")
void test(TestCase testCase) throws IOException {
ByteArrayOutputStream bytes = writeJunitXmlReport(testCase, new ByteArrayOutputStream());
ByteArrayOutputStream bytes = writeJunitXmlReport(testCase, messageOrderer.originalOrder());
Source expected = Input.fromPath(testCase.expected).build();
Source actual = Input.fromByteArray(bytes.toByteArray()).build();
assertThat(actual).and(expected).ignoreWhitespace().areIdentical();
}

@ParameterizedTest
@MethodSource("acceptance")
void testWithSimulatedParallelExecution(TestCase testCase) throws IOException {
ByteArrayOutputStream actual = writeJunitXmlReport(testCase, messageOrderer.simulateParallelExecution());
byte[] expected = Files.readAllBytes(testCase.expected);
assertThat(actual).and(expected).ignoreWhitespace().areIdentical();
}

@ParameterizedTest
@MethodSource("acceptance")
void validateAgainstJenkins(TestCase testCase) throws IOException {
ByteArrayOutputStream bytes = writeJunitXmlReport(testCase, new ByteArrayOutputStream());
ByteArrayOutputStream bytes = writeJunitXmlReport(testCase, messageOrderer.originalOrder());
Source actual = Input.fromByteArray(bytes.toByteArray()).build();
Source jenkinsSchema = Input.fromPath(Paths.get("../jenkins-junit.xsd")).build();
assertThat(actual).isValidAgainst(jenkinsSchema);
Expand All @@ -64,7 +76,7 @@ void validateAgainstJenkins(TestCase testCase) throws IOException {
@ParameterizedTest
@MethodSource("acceptance")
void validateAgainstSurefire(TestCase testCase) throws IOException {
ByteArrayOutputStream bytes = writeJunitXmlReport(testCase, new ByteArrayOutputStream());
ByteArrayOutputStream bytes = writeJunitXmlReport(testCase, messageOrderer.originalOrder());
Source actual = Input.fromByteArray(bytes.toByteArray()).build();
Source surefireSchema = Input.fromPath(Paths.get("../surefire-test-report-3.0.2.xsd")).build();

Expand All @@ -87,20 +99,29 @@ void validateAgainstSurefire(TestCase testCase) throws IOException {
@Disabled
void updateExpectedFiles(TestCase testCase) throws IOException {
try (OutputStream out = Files.newOutputStream(testCase.expected)) {
writeJunitXmlReport(testCase, out);
writeJunitXmlReport(testCase, out, messageOrderer.originalOrder());
}
}

private static <T extends OutputStream> T writeJunitXmlReport(TestCase testCase, T out) throws IOException {
private static ByteArrayOutputStream writeJunitXmlReport(TestCase testCase, Consumer<List<Envelope>> orderer) throws IOException {
return writeJunitXmlReport(testCase, new ByteArrayOutputStream(), orderer);
}
private static <T extends OutputStream> T writeJunitXmlReport(TestCase testCase, T out, Consumer<List<Envelope>> orderer) throws IOException {
List<Envelope> messages = new ArrayList<>();
try (InputStream in = Files.newInputStream(testCase.source)) {
try (NdjsonToMessageIterable envelopes = new NdjsonToMessageIterable(in, deserializer)) {
try (MessagesToJunitXmlWriter writer = new MessagesToJunitXmlWriter(out)) {
for (Envelope envelope : envelopes) {
writer.write(envelope);
}
for (Envelope envelope : envelopes) {
messages.add(envelope);
}
}
}
orderer.accept(messages);

try (MessagesToJunitXmlWriter writer = new MessagesToJunitXmlWriter(out)) {
for (Envelope envelope : messages) {
writer.write(envelope);
}
}
return out;
}

Expand All @@ -122,18 +143,6 @@ public String toString() {
return name;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TestCase testCase = (TestCase) o;
return source.equals(testCase.source);
}

@Override
public int hashCode() {
return Objects.hash(source);
}
}

}
Expand Down
Loading