From f9297b687586716b9d9010a88d6ac85e63cbd354 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 27 Oct 2025 05:41:39 +0000 Subject: [PATCH 01/19] Add socket support to OpenTestReportGeneratingListener - Add SOCKET_PROPERTY_NAME constant for junit.platform.reporting.open.xml.socket - Implement createDocumentWriter method to support both file and socket outputs - When socket property is set, connect to localhost: and write XML to socket - Add comprehensive test for socket-based reporting - Update documentation to describe socket configuration parameter - Update release notes with new feature Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com> --- .../release-notes/release-notes-6.1.0-M1.adoc | 3 + .../junit-platform-reporting.adoc | 8 ++- .../xml/OpenTestReportGeneratingListener.java | 40 +++++++++++- ...OpenTestReportGeneratingListenerTests.java | 63 +++++++++++++++++++ 4 files changed, 110 insertions(+), 4 deletions(-) diff --git a/documentation/src/docs/asciidoc/release-notes/release-notes-6.1.0-M1.adoc b/documentation/src/docs/asciidoc/release-notes/release-notes-6.1.0-M1.adoc index ee0700a3c59f..a4510019a4a3 100644 --- a/documentation/src/docs/asciidoc/release-notes/release-notes-6.1.0-M1.adoc +++ b/documentation/src/docs/asciidoc/release-notes/release-notes-6.1.0-M1.adoc @@ -28,6 +28,9 @@ repository on GitHub. * Support for creating a `ModuleSelector` from a `java.lang.Module` and using its classloader for test discovery. +* `OpenTestReportGeneratingListener` now supports redirecting XML events to a socket via + the new `junit.platform.reporting.open.xml.socket` configuration parameter. When set to a + port number, events are sent to `localhost:` instead of being written to a file. [[release-notes-6.1.0-M1-junit-jupiter]] diff --git a/documentation/src/docs/asciidoc/user-guide/advanced-topics/junit-platform-reporting.adoc b/documentation/src/docs/asciidoc/user-guide/advanced-topics/junit-platform-reporting.adoc index 66851d49dd9b..82dcbdd87592 100644 --- a/documentation/src/docs/asciidoc/user-guide/advanced-topics/junit-platform-reporting.adoc +++ b/documentation/src/docs/asciidoc/user-guide/advanced-topics/junit-platform-reporting.adoc @@ -42,9 +42,15 @@ The listener is auto-registered and can be configured via the following Enable/disable writing the report; defaults to `false`. `junit.platform.reporting.open.xml.git.enabled=true|false`:: Enable/disable including information about the Git repository (see https://github.com/ota4j-team/open-test-reporting#git[Git extension schema] of open-test-reporting); defaults to `false`. +`junit.platform.reporting.open.xml.socket=`:: + Optional port number to redirect events to a socket instead of a file. When specified, the + listener will connect to `localhost:` and send the XML events to the socket. The socket + connection is automatically closed when the test execution completes. If enabled, the listener creates an XML report file named `open-test-report.xml` in the -configured <>. +configured <>, unless the +`junit.platform.reporting.open.xml.socket` configuration parameter is set, in which case the +events are sent to the specified socket instead. If <> is enabled, the captured output written to `System.out` and `System.err` will be included in the report as well. diff --git a/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java b/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java index 5037090412a1..462b8ccc3933 100644 --- a/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java +++ b/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java @@ -53,9 +53,13 @@ import static org.opentest4j.reporting.events.root.RootFactory.started; import java.io.IOException; +import java.io.OutputStreamWriter; import java.io.UncheckedIOException; +import java.io.Writer; import java.net.InetAddress; +import java.net.Socket; import java.net.UnknownHostException; +import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.time.Instant; import java.time.LocalDateTime; @@ -102,6 +106,7 @@ public class OpenTestReportGeneratingListener implements TestExecutionListener { static final String ENABLED_PROPERTY_NAME = "junit.platform.reporting.open.xml.enabled"; static final String GIT_ENABLED_PROPERTY_NAME = "junit.platform.reporting.open.xml.git.enabled"; + static final String SOCKET_PROPERTY_NAME = "junit.platform.reporting.open.xml.socket"; private final AtomicInteger idCounter = new AtomicInteger(); private final Map inProgressIds = new ConcurrentHashMap<>(); @@ -130,17 +135,46 @@ public void testPlanExecutionStarted(TestPlan testPlan) { .add("junit", JUnitFactory.NAMESPACE, "https://schemas.junit.org/open-test-reporting/junit-1.9.xsd") // .build(); outputDir = testPlan.getOutputDirectoryCreator().getRootDirectory(); - Path eventsXml = outputDir.resolve("open-test-report.xml"); try { - eventsFileWriter = Events.createDocumentWriter(namespaceRegistry, eventsXml); + eventsFileWriter = createDocumentWriter(config, namespaceRegistry); reportInfrastructure(config); } catch (Exception e) { - throw new JUnitException("Failed to initialize XML events file: " + eventsXml, e); + throw new JUnitException("Failed to initialize XML events writer", e); } } } + private DocumentWriter createDocumentWriter(ConfigurationParameters config, + NamespaceRegistry namespaceRegistry) throws Exception { + return config.get(SOCKET_PROPERTY_NAME) // + .map(portString -> { + try { + int port = Integer.parseInt(portString); + Socket socket = new Socket("localhost", port); + Writer writer = new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8); + return Events.createDocumentWriter(namespaceRegistry, writer); + } + catch (NumberFormatException e) { + throw new JUnitException( + "Invalid port number for socket configuration: " + portString + ". Expected an integer.", + e); + } + catch (Exception e) { + throw new JUnitException("Failed to connect to socket on port: " + portString, e); + } + }) // + .orElseGet(() -> { + try { + Path eventsXml = requireNonNull(outputDir).resolve("open-test-report.xml"); + return Events.createDocumentWriter(namespaceRegistry, eventsXml); + } + catch (Exception e) { + throw new JUnitException("Failed to create XML events file", e); + } + }); + } + private boolean isEnabled(ConfigurationParameters config) { return config.getBoolean(ENABLED_PROPERTY_NAME).orElse(false); } diff --git a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java index 686844b0857e..8b4bfd469e3f 100644 --- a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java +++ b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java @@ -24,13 +24,22 @@ import static org.junit.platform.launcher.core.LauncherFactoryForTestingPurposesOnly.createLauncher; import static org.junit.platform.reporting.open.xml.OpenTestReportGeneratingListener.ENABLED_PROPERTY_NAME; import static org.junit.platform.reporting.open.xml.OpenTestReportGeneratingListener.GIT_ENABLED_PROPERTY_NAME; +import static org.junit.platform.reporting.open.xml.OpenTestReportGeneratingListener.SOCKET_PROPERTY_NAME; import static org.junit.platform.reporting.testutil.FileUtils.findPath; +import java.io.BufferedReader; +import java.io.InputStreamReader; import java.io.PrintStream; +import java.net.ServerSocket; +import java.net.Socket; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -311,4 +320,58 @@ private static void executeTests(Path tempDirectory, TestEngine engine, Path out createLauncher(engine).execute(request); } + @Test + void writesXmlReportToSocket(@TempDir Path tempDirectory) throws Exception { + var engine = new DemoHierarchicalTestEngine("dummy"); + engine.addTest("test1", "Test 1", (context, descriptor) -> { + // Simple test + }); + + // Start a server socket to receive the XML + var xmlContent = new AtomicReference(); + var latch = new CountDownLatch(1); + + try (var serverSocket = new ServerSocket(0)) { // Use any available port + int port = serverSocket.getLocalPort(); + + // Start a daemon thread to accept the connection and read the XML + Thread serverThread = new Thread(() -> { + try (Socket clientSocket = serverSocket.accept(); + var reader = new BufferedReader( + new InputStreamReader(clientSocket.getInputStream(), StandardCharsets.UTF_8))) { + var builder = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + builder.append(line).append("\n"); + } + xmlContent.set(builder.toString()); + } + catch (Exception e) { + // Only throw if not interrupted during cleanup + if (!Thread.currentThread().isInterrupted()) { + throw new RuntimeException(e); + } + } + finally { + latch.countDown(); + } + }); + serverThread.setDaemon(true); + serverThread.start(); + + // Execute tests with socket configuration + executeTests(tempDirectory, engine, tempDirectory.resolve("junit-reports"), + Map.of(SOCKET_PROPERTY_NAME, String.valueOf(port))); + + // Wait for the server to receive the data + assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue(); + + // Verify XML was received + assertThat(xmlContent.get()).isNotNull(); + assertThat(xmlContent.get()).contains(" Date: Mon, 27 Oct 2025 14:06:38 +0100 Subject: [PATCH 02/19] Apply suggestion from @marcphilipp Co-authored-by: Marc Philipp --- .../reporting/open/xml/OpenTestReportGeneratingListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java b/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java index 462b8ccc3933..928cedb92ec9 100644 --- a/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java +++ b/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java @@ -161,7 +161,7 @@ private DocumentWriter createDocumentWriter(ConfigurationParameters conf e); } catch (Exception e) { - throw new JUnitException("Failed to connect to socket on port: " + portString, e); + throw new JUnitException("Failed to connect to socket on port " + port, e); } }) // .orElseGet(() -> { From 276665d59381d88bb3be38e2a3a9ca5719c1ca51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Mon, 27 Oct 2025 14:07:11 +0100 Subject: [PATCH 03/19] Apply suggestion from @marcphilipp Co-authored-by: Marc Philipp --- .../reporting/open/xml/OpenTestReportGeneratingListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java b/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java index 928cedb92ec9..962379dd2cb4 100644 --- a/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java +++ b/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java @@ -147,7 +147,7 @@ public void testPlanExecutionStarted(TestPlan testPlan) { private DocumentWriter createDocumentWriter(ConfigurationParameters config, NamespaceRegistry namespaceRegistry) throws Exception { - return config.get(SOCKET_PROPERTY_NAME) // + return config.get(SOCKET_PROPERTY_NAME, Integer::valueOf) // .map(portString -> { try { int port = Integer.parseInt(portString); From 7b38fdfbe67895ec0a33aea832cd3830b8c060ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Mon, 27 Oct 2025 14:07:21 +0100 Subject: [PATCH 04/19] Apply suggestion from @marcphilipp Co-authored-by: Marc Philipp --- .../open/xml/OpenTestReportGeneratingListener.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java b/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java index 962379dd2cb4..9cc80b14a3c2 100644 --- a/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java +++ b/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java @@ -148,18 +148,12 @@ public void testPlanExecutionStarted(TestPlan testPlan) { private DocumentWriter createDocumentWriter(ConfigurationParameters config, NamespaceRegistry namespaceRegistry) throws Exception { return config.get(SOCKET_PROPERTY_NAME, Integer::valueOf) // - .map(portString -> { + .map(port -> { try { - int port = Integer.parseInt(portString); Socket socket = new Socket("localhost", port); Writer writer = new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8); return Events.createDocumentWriter(namespaceRegistry, writer); } - catch (NumberFormatException e) { - throw new JUnitException( - "Invalid port number for socket configuration: " + portString + ". Expected an integer.", - e); - } catch (Exception e) { throw new JUnitException("Failed to connect to socket on port " + port, e); } From ed9b207fdb1634f215590ce052bbd87bdff4d7e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Mon, 27 Oct 2025 17:44:58 +0100 Subject: [PATCH 05/19] Update platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java Co-authored-by: Marc Philipp --- .../open/xml/OpenTestReportGeneratingListenerTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java index 8b4bfd469e3f..79c72218d82f 100644 --- a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java +++ b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java @@ -331,7 +331,7 @@ void writesXmlReportToSocket(@TempDir Path tempDirectory) throws Exception { var xmlContent = new AtomicReference(); var latch = new CountDownLatch(1); - try (var serverSocket = new ServerSocket(0)) { // Use any available port + try (var serverSocket = new ServerSocket(0, 50, InetAddress.getLoopbackAddress())) { // Use any available port int port = serverSocket.getLocalPort(); // Start a daemon thread to accept the connection and read the XML From 80aa07c6f835d62cfd4caa86b595f9de3af8d11b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Mon, 27 Oct 2025 17:45:07 +0100 Subject: [PATCH 06/19] Update platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java Co-authored-by: Marc Philipp --- .../open/xml/OpenTestReportGeneratingListenerTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java index 79c72218d82f..d2586cfc3f25 100644 --- a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java +++ b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java @@ -364,7 +364,7 @@ void writesXmlReportToSocket(@TempDir Path tempDirectory) throws Exception { Map.of(SOCKET_PROPERTY_NAME, String.valueOf(port))); // Wait for the server to receive the data - assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue(); + assertThat(serverThread.join(Duration.ofSeconds(10))).isTrue(); // Verify XML was received assertThat(xmlContent.get()).isNotNull(); From 7c1018c818d8467f738aa505bb057edb9c9d86fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Mon, 27 Oct 2025 17:45:17 +0100 Subject: [PATCH 07/19] Update platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java Co-authored-by: Marc Philipp --- .../open/xml/OpenTestReportGeneratingListenerTests.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java index d2586cfc3f25..85947b12d273 100644 --- a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java +++ b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java @@ -367,10 +367,11 @@ void writesXmlReportToSocket(@TempDir Path tempDirectory) throws Exception { assertThat(serverThread.join(Duration.ofSeconds(10))).isTrue(); // Verify XML was received - assertThat(xmlContent.get()).isNotNull(); - assertThat(xmlContent.get()).contains(" Date: Mon, 27 Oct 2025 17:45:33 +0100 Subject: [PATCH 08/19] Update platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java Co-authored-by: Marc Philipp --- .../open/xml/OpenTestReportGeneratingListenerTests.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java index 85947b12d273..318d532696b1 100644 --- a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java +++ b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java @@ -347,10 +347,7 @@ void writesXmlReportToSocket(@TempDir Path tempDirectory) throws Exception { xmlContent.set(builder.toString()); } catch (Exception e) { - // Only throw if not interrupted during cleanup - if (!Thread.currentThread().isInterrupted()) { - throw new RuntimeException(e); - } + fail(e); } finally { latch.countDown(); From 8d54467801437dba9cb5e2d8873b2ba876c981a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Mon, 27 Oct 2025 18:03:32 +0100 Subject: [PATCH 09/19] No need for atomic reference --- .../open/xml/OpenTestReportGeneratingListenerTests.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java index 318d532696b1..8b20a617df20 100644 --- a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java +++ b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java @@ -328,7 +328,7 @@ void writesXmlReportToSocket(@TempDir Path tempDirectory) throws Exception { }); // Start a server socket to receive the XML - var xmlContent = new AtomicReference(); + var builder = new StringBuilder(); var latch = new CountDownLatch(1); try (var serverSocket = new ServerSocket(0, 50, InetAddress.getLoopbackAddress())) { // Use any available port @@ -339,12 +339,10 @@ void writesXmlReportToSocket(@TempDir Path tempDirectory) throws Exception { try (Socket clientSocket = serverSocket.accept(); var reader = new BufferedReader( new InputStreamReader(clientSocket.getInputStream(), StandardCharsets.UTF_8))) { - var builder = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { builder.append(line).append("\n"); } - xmlContent.set(builder.toString()); } catch (Exception e) { fail(e); @@ -364,7 +362,7 @@ void writesXmlReportToSocket(@TempDir Path tempDirectory) throws Exception { assertThat(serverThread.join(Duration.ofSeconds(10))).isTrue(); // Verify XML was received - assertThat(xmlContent.get()) // + assertThat(builder.toString()) // .isNotNull() // .contains(" Date: Mon, 27 Oct 2025 18:06:01 +0100 Subject: [PATCH 10/19] No need for latch anymore --- .../open/xml/OpenTestReportGeneratingListenerTests.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java index 8b20a617df20..42aac53e7901 100644 --- a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java +++ b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java @@ -37,7 +37,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; @@ -329,7 +328,6 @@ void writesXmlReportToSocket(@TempDir Path tempDirectory) throws Exception { // Start a server socket to receive the XML var builder = new StringBuilder(); - var latch = new CountDownLatch(1); try (var serverSocket = new ServerSocket(0, 50, InetAddress.getLoopbackAddress())) { // Use any available port int port = serverSocket.getLocalPort(); @@ -347,9 +345,6 @@ void writesXmlReportToSocket(@TempDir Path tempDirectory) throws Exception { catch (Exception e) { fail(e); } - finally { - latch.countDown(); - } }); serverThread.setDaemon(true); serverThread.start(); From a435927a67b28f27d385b6882eecc210612313b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Mon, 27 Oct 2025 18:26:37 +0100 Subject: [PATCH 11/19] Spotless --- .../open/xml/OpenTestReportGeneratingListenerTests.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java index 42aac53e7901..6e49c74c1048 100644 --- a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java +++ b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java @@ -37,8 +37,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; From be456a7e4834a65e148e03a606e6761d56bd0102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Mon, 27 Oct 2025 18:36:26 +0100 Subject: [PATCH 12/19] FIx missing import --- .../open/xml/OpenTestReportGeneratingListenerTests.java | 1 + 1 file changed, 1 insertion(+) diff --git a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java index 6e49c74c1048..7afe1f603f2f 100644 --- a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java +++ b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java @@ -30,6 +30,7 @@ import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintStream; +import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; import java.net.URISyntaxException; From d45ade224704bf9f4b8d3ec8da2f97fd108f2448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Mon, 27 Oct 2025 18:38:38 +0100 Subject: [PATCH 13/19] Fix missing durration import --- .../open/xml/OpenTestReportGeneratingListenerTests.java | 1 + 1 file changed, 1 insertion(+) diff --git a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java index 7afe1f603f2f..c2bf6bcb26d6 100644 --- a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java +++ b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java @@ -37,6 +37,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.time.Duration; import java.util.Map; import org.junit.jupiter.api.AfterEach; From 4503fa6c7e982d55549c7a3753cd11acf28f5b00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Tue, 28 Oct 2025 11:19:48 +0100 Subject: [PATCH 14/19] Update documentation/src/docs/asciidoc/release-notes/release-notes-6.1.0-M1.adoc Co-authored-by: Marc Philipp --- .../src/docs/asciidoc/release-notes/release-notes-6.1.0-M1.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/docs/asciidoc/release-notes/release-notes-6.1.0-M1.adoc b/documentation/src/docs/asciidoc/release-notes/release-notes-6.1.0-M1.adoc index a4510019a4a3..a42b54393899 100644 --- a/documentation/src/docs/asciidoc/release-notes/release-notes-6.1.0-M1.adoc +++ b/documentation/src/docs/asciidoc/release-notes/release-notes-6.1.0-M1.adoc @@ -30,7 +30,7 @@ repository on GitHub. its classloader for test discovery. * `OpenTestReportGeneratingListener` now supports redirecting XML events to a socket via the new `junit.platform.reporting.open.xml.socket` configuration parameter. When set to a - port number, events are sent to `localhost:` instead of being written to a file. + port number, events are sent to `127.0.0.1:` instead of being written to a file. [[release-notes-6.1.0-M1-junit-jupiter]] From 7a1bd13aa2efbf0ef8a59a3f59b0b0dc8dc3aedf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Tue, 28 Oct 2025 11:19:59 +0100 Subject: [PATCH 15/19] Update documentation/src/docs/asciidoc/user-guide/advanced-topics/junit-platform-reporting.adoc Co-authored-by: Marc Philipp --- .../user-guide/advanced-topics/junit-platform-reporting.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/docs/asciidoc/user-guide/advanced-topics/junit-platform-reporting.adoc b/documentation/src/docs/asciidoc/user-guide/advanced-topics/junit-platform-reporting.adoc index 82dcbdd87592..10f7744f54b0 100644 --- a/documentation/src/docs/asciidoc/user-guide/advanced-topics/junit-platform-reporting.adoc +++ b/documentation/src/docs/asciidoc/user-guide/advanced-topics/junit-platform-reporting.adoc @@ -44,7 +44,7 @@ The listener is auto-registered and can be configured via the following Enable/disable including information about the Git repository (see https://github.com/ota4j-team/open-test-reporting#git[Git extension schema] of open-test-reporting); defaults to `false`. `junit.platform.reporting.open.xml.socket=`:: Optional port number to redirect events to a socket instead of a file. When specified, the - listener will connect to `localhost:` and send the XML events to the socket. The socket + listener will connect to `127.0.0.1:` and send the XML events to the socket. The socket connection is automatically closed when the test execution completes. If enabled, the listener creates an XML report file named `open-test-report.xml` in the From e89a20e14e4101b98268efd76841c27f26810237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Tue, 28 Oct 2025 11:20:12 +0100 Subject: [PATCH 16/19] Update junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java Co-authored-by: Marc Philipp --- .../reporting/open/xml/OpenTestReportGeneratingListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java b/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java index 9cc80b14a3c2..76e40bd0b249 100644 --- a/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java +++ b/junit-platform-reporting/src/main/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListener.java @@ -150,7 +150,7 @@ private DocumentWriter createDocumentWriter(ConfigurationParameters conf return config.get(SOCKET_PROPERTY_NAME, Integer::valueOf) // .map(port -> { try { - Socket socket = new Socket("localhost", port); + Socket socket = new Socket(InetAddress.getLoopbackAddress(), port); Writer writer = new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8); return Events.createDocumentWriter(namespaceRegistry, writer); } From c55b21a03db442ac176f0e9cc3574f6d5182d1f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Tue, 28 Oct 2025 11:20:36 +0100 Subject: [PATCH 17/19] Update platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java Co-authored-by: Marc Philipp --- ...OpenTestReportGeneratingListenerTests.java | 48 +++++++++++++++++-- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java index c2bf6bcb26d6..9d0582b6ca7c 100644 --- a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java +++ b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java @@ -357,11 +357,49 @@ void writesXmlReportToSocket(@TempDir Path tempDirectory) throws Exception { assertThat(serverThread.join(Duration.ofSeconds(10))).isTrue(); // Verify XML was received - assertThat(builder.toString()) // - .isNotNull() // - .contains(" + + ${xmlunit.ignore} + ${xmlunit.ignore} + ${xmlunit.ignore} + ${xmlunit.ignore} + ${xmlunit.ignore} + ${xmlunit.ignore} + + + + + [engine:dummy] + dummy + CONTAINER + + + + + [engine:dummy]/[test:test1] + Test 1 + TEST + + + + + + + + + + """; + XmlAssert.assertThat(builder.toString()).and(expected) // + .withDifferenceEvaluator(new PlaceholderDifferenceEvaluator()) // + .ignoreWhitespace() // + .areIdentical(); } } From bcd1a93b8e2a87ede516583640fb73ab773bbf4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Tue, 28 Oct 2025 13:42:56 +0100 Subject: [PATCH 18/19] Fix spotless --- ...OpenTestReportGeneratingListenerTests.java | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java index 9d0582b6ca7c..94da972a8e44 100644 --- a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java +++ b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java @@ -358,44 +358,44 @@ void writesXmlReportToSocket(@TempDir Path tempDirectory) throws Exception { // Verify XML was received var expected = """ - - - ${xmlunit.ignore} - ${xmlunit.ignore} - ${xmlunit.ignore} - ${xmlunit.ignore} - ${xmlunit.ignore} - ${xmlunit.ignore} - - - - - [engine:dummy] - dummy - CONTAINER - - - - - [engine:dummy]/[test:test1] - Test 1 - TEST - - - - - - - - - - """; + + + ${xmlunit.ignore} + ${xmlunit.ignore} + ${xmlunit.ignore} + ${xmlunit.ignore} + ${xmlunit.ignore} + ${xmlunit.ignore} + + + + + [engine:dummy] + dummy + CONTAINER + + + + + [engine:dummy]/[test:test1] + Test 1 + TEST + + + + + + + + + + """; XmlAssert.assertThat(builder.toString()).and(expected) // .withDifferenceEvaluator(new PlaceholderDifferenceEvaluator()) // .ignoreWhitespace() // From 7fb6e4fa9cb378d8e02c488fc470d7eafe478d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Tue, 28 Oct 2025 15:57:11 +0100 Subject: [PATCH 19/19] Move method above static ones --- ...OpenTestReportGeneratingListenerTests.java | 92 +++++++++---------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java index 94da972a8e44..5db92bbd1aa5 100644 --- a/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java +++ b/platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java @@ -273,52 +273,6 @@ void stripsCredentialsFromOriginUrl(String configuredUrl, String reportedUrl, @T .isEqualTo(reportedUrl); } - private static XmlAssert assertThatXml(Path xmlFile) { - return XmlAssert.assertThat(xmlFile) // - .withNamespaceContext(NAMESPACE_CONTEXT); - } - - private static ProcessResult execGit(Path workingDir, String... arguments) throws InterruptedException { - var result = tryExecGit(workingDir, arguments); - assertEquals(0, result.exitCode(), "git " + String.join(" ", arguments) + " failed"); - return result; - } - - private static ProcessResult tryExecGit(Path workingDir, String... arguments) throws InterruptedException { - System.out.println("$ git " + String.join(" ", arguments)); - return new ProcessStarter() // - .executable(Path.of("git")) // - .putEnvironment("GIT_CONFIG_GLOBAL", "/dev/null") // https://git-scm.com/docs/git#Documentation/git.txt-GITCONFIGGLOBAL - .workingDir(workingDir) // - .addArguments(arguments) // - .startAndWait(); - } - - private ValidationResult validate(Path xmlFile) throws URISyntaxException { - var catalogUri = requireNonNull(getClass().getResource("catalog.xml")).toURI(); - return new DefaultValidator(catalogUri).validate(xmlFile); - } - - private static void executeTests(Path tempDirectory, TestEngine engine, Path outputDir) { - executeTests(tempDirectory, engine, outputDir, Map.of()); - } - - private static void executeTests(Path tempDirectory, TestEngine engine, Path outputDir, - Map extraConfigurationParameters) { - var request = request() // - .selectors(selectUniqueId(UniqueId.forEngine(engine.getId()))) // - .enableImplicitConfigurationParameters(false) // - .configurationParameter(ENABLED_PROPERTY_NAME, String.valueOf(true)) // - .configurationParameter(CAPTURE_STDOUT_PROPERTY_NAME, String.valueOf(true)) // - .configurationParameter(CAPTURE_STDERR_PROPERTY_NAME, String.valueOf(true)) // - .configurationParameter(OUTPUT_DIR_PROPERTY_NAME, outputDir.toString()) // - .configurationParameters(extraConfigurationParameters) // - .forExecution() // - .listeners(new OpenTestReportGeneratingListener(tempDirectory)) // - .build(); - createLauncher(engine).execute(request); - } - @Test void writesXmlReportToSocket(@TempDir Path tempDirectory) throws Exception { var engine = new DemoHierarchicalTestEngine("dummy"); @@ -403,4 +357,50 @@ void writesXmlReportToSocket(@TempDir Path tempDirectory) throws Exception { } } + private static XmlAssert assertThatXml(Path xmlFile) { + return XmlAssert.assertThat(xmlFile) // + .withNamespaceContext(NAMESPACE_CONTEXT); + } + + private static ProcessResult execGit(Path workingDir, String... arguments) throws InterruptedException { + var result = tryExecGit(workingDir, arguments); + assertEquals(0, result.exitCode(), "git " + String.join(" ", arguments) + " failed"); + return result; + } + + private static ProcessResult tryExecGit(Path workingDir, String... arguments) throws InterruptedException { + System.out.println("$ git " + String.join(" ", arguments)); + return new ProcessStarter() // + .executable(Path.of("git")) // + .putEnvironment("GIT_CONFIG_GLOBAL", "/dev/null") // https://git-scm.com/docs/git#Documentation/git.txt-GITCONFIGGLOBAL + .workingDir(workingDir) // + .addArguments(arguments) // + .startAndWait(); + } + + private ValidationResult validate(Path xmlFile) throws URISyntaxException { + var catalogUri = requireNonNull(getClass().getResource("catalog.xml")).toURI(); + return new DefaultValidator(catalogUri).validate(xmlFile); + } + + private static void executeTests(Path tempDirectory, TestEngine engine, Path outputDir) { + executeTests(tempDirectory, engine, outputDir, Map.of()); + } + + private static void executeTests(Path tempDirectory, TestEngine engine, Path outputDir, + Map extraConfigurationParameters) { + var request = request() // + .selectors(selectUniqueId(UniqueId.forEngine(engine.getId()))) // + .enableImplicitConfigurationParameters(false) // + .configurationParameter(ENABLED_PROPERTY_NAME, String.valueOf(true)) // + .configurationParameter(CAPTURE_STDOUT_PROPERTY_NAME, String.valueOf(true)) // + .configurationParameter(CAPTURE_STDERR_PROPERTY_NAME, String.valueOf(true)) // + .configurationParameter(OUTPUT_DIR_PROPERTY_NAME, outputDir.toString()) // + .configurationParameters(extraConfigurationParameters) // + .forExecution() // + .listeners(new OpenTestReportGeneratingListener(tempDirectory)) // + .build(); + createLauncher(engine).execute(request); + } + }