This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new 55d03266d9 Surefire report output creates the parent folder also when
"Create pa… (#9372)
55d03266d9 is described below
commit 55d03266d9c9aedb04e3b4364af903333132b092
Author: Bart Maertens <[email protected]>
AuthorDate: Thu Nov 12 10:54:39 2026 +0100
Surefire report output creates the parent folder also when "Create pa…
(#9372)
* Surefire report output creates the parent folder also when "Create parent
folder" is off, fixes #9356
* Surefire report output: check the report folder in init(), use HopVfs,
review fixes for #9356
---
.../pages/pipeline/transforms/surefirereport.adoc | 2 +-
.../surefirereport/SurefireReportOutput.java | 80 ++++++---
.../surefirereport/SurefireReportOutputData.java | 4 +
.../surefirereport/SurefireReportWriter.java | 30 ++--
.../messages/messages_en_US.properties | 2 +
.../surefirereport/SurefireReportOutputTest.java | 191 +++++++++++++++++++++
.../surefirereport/SurefireReportWriterTest.java | 40 ++++-
7 files changed, 304 insertions(+), 45 deletions(-)
diff --git
a/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/surefirereport.adoc
b/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/surefirereport.adoc
index 57d4990bf3..21b8b04020 100644
---
a/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/surefirereport.adoc
+++
b/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/surefirereport.adoc
@@ -37,7 +37,7 @@ The rows pass through unchanged, so the transform can sit in
the middle of a pip
|Transform name|Name of the transform.
|Report filename|The XML file to write. Variables are allowed.
|Test suite name|The name of the test suite in the report. Default: `tests`.
-|Create parent folder|Create the folder of the report file when it doesn't
exist.
+|Create parent folder|Create the folder of the report file when it doesn't
exist. When this is off and the folder doesn't exist, the transform fails at
the start of the pipeline, before any rows are read.
|Test name field|The field with the name of the test. Required. The value is
shortened: everything up to the last `/` or `\`, a `main-` or `main_` prefix
and a `.hwf` extension are removed, so `/project/tests/main-load-orders.hwf`
becomes `load-orders`.
|Duration field|The field with the duration of the test, in seconds.
|Duration is in milliseconds|The duration field is in milliseconds, for
example the `ExecutionTime` of a Workflow executor.
diff --git
a/plugins/transforms/surefirereport/src/main/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportOutput.java
b/plugins/transforms/surefirereport/src/main/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportOutput.java
index 3a44dd68ac..67d12a0e97 100644
---
a/plugins/transforms/surefirereport/src/main/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportOutput.java
+++
b/plugins/transforms/surefirereport/src/main/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportOutput.java
@@ -17,13 +17,13 @@
package org.apache.hop.pipeline.transforms.surefirereport;
-import java.nio.file.Path;
-import java.nio.file.Paths;
+import org.apache.commons.vfs2.FileObject;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.exception.HopTransformException;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.row.IValueMeta;
import org.apache.hop.core.util.Utils;
+import org.apache.hop.core.vfs.HopVfs;
import org.apache.hop.i18n.BaseMessages;
import org.apache.hop.pipeline.Pipeline;
import org.apache.hop.pipeline.PipelineMeta;
@@ -211,33 +211,20 @@ public class SurefireReportOutput
}
private void writeReport() throws HopException {
- String filename = resolve(meta.getFilename());
- if (Utils.isEmpty(filename)) {
- throw new HopException(
- BaseMessages.getString(PKG,
"SurefireReportOutput.Error.FilenameMissing"));
- }
-
String suiteName = resolve(meta.getSuiteName());
if (Utils.isEmpty(suiteName)) {
suiteName = "tests";
}
- Path reportPath = Paths.get(filename);
- if (meta.isCreateParentFolder() && reportPath.getParent() != null) {
- try {
- java.nio.file.Files.createDirectories(reportPath.getParent());
- } catch (Exception e) {
- throw new HopException(
- BaseMessages.getString(
- PKG, "SurefireReportOutput.Error.WriteFailed", filename,
e.getMessage()),
- e);
- }
- }
+ // Checked in init() already; check again in case the folder went away
during the run.
+ FileObject reportFile = data.reportFile;
+ String filename = HopVfs.getFriendlyURI(reportFile);
+ prepareParentFolder(reportFile, meta.isCreateParentFolder());
int failedOrErrored;
try {
synchronized (data.lock) {
- SurefireReportWriter.write(reportPath, suiteName, data.testCases);
+ SurefireReportWriter.write(reportFile, suiteName, data.testCases);
failedOrErrored = 0;
for (SurefireTestCase testCase : data.testCases) {
if (testCase.getStatus() == Status.FAIL || testCase.getStatus() ==
Status.ERROR) {
@@ -269,15 +256,62 @@ public class SurefireReportOutput
}
}
+ /**
+ * Makes sure the folder of the report file exists, creating it when {@code
createParentFolder} is
+ * on. Fails when it is missing and may not be created, or when it is not a
folder.
+ */
+ static void prepareParentFolder(FileObject reportFile, boolean
createParentFolder)
+ throws HopException {
+ String filename = HopVfs.getFriendlyURI(reportFile);
+ try {
+ FileObject parentFolder = reportFile.getParent();
+ if (parentFolder == null) {
+ return;
+ }
+ parentFolder.refresh();
+ if (parentFolder.isFolder()) {
+ return;
+ }
+ String folder = HopVfs.getFriendlyURI(parentFolder);
+ if (parentFolder.exists()) {
+ throw new HopException(
+ BaseMessages.getString(
+ PKG, "SurefireReportOutput.Error.ParentFolderIsNotAFolder",
folder, filename));
+ }
+ if (!createParentFolder) {
+ throw new HopException(
+ BaseMessages.getString(
+ PKG, "SurefireReportOutput.Error.ParentFolderDoesNotExist",
folder, filename));
+ }
+ parentFolder.createFolder();
+ } catch (HopException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new HopException(
+ BaseMessages.getString(
+ PKG, "SurefireReportOutput.Error.WriteFailed", filename,
e.getMessage()),
+ e);
+ }
+ }
+
@Override
public boolean init() {
if (super.init()) {
- if (Utils.isEmpty(meta.getFilename())) {
+ if (Utils.isEmpty(meta.getTestNameField())) {
+ logError(BaseMessages.getString(PKG,
"SurefireReportOutput.Error.TestNameFieldMissing"));
+ return false;
+ }
+ String filename = resolve(meta.getFilename());
+ if (Utils.isEmpty(filename)) {
logError(BaseMessages.getString(PKG,
"SurefireReportOutput.Error.FilenameMissing"));
return false;
}
- if (Utils.isEmpty(meta.getTestNameField())) {
- logError(BaseMessages.getString(PKG,
"SurefireReportOutput.Error.TestNameFieldMissing"));
+ // Check the folder now, so a long run does not lose its results at the
very end.
+ try {
+ data.reportFile = HopVfs.getFileObject(filename, this);
+ prepareParentFolder(data.reportFile, meta.isCreateParentFolder());
+ } catch (HopException e) {
+ logError(e.getMessage().trim());
return false;
}
return true;
diff --git
a/plugins/transforms/surefirereport/src/main/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportOutputData.java
b/plugins/transforms/surefirereport/src/main/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportOutputData.java
index df3541debf..2d1a62c5a0 100644
---
a/plugins/transforms/surefirereport/src/main/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportOutputData.java
+++
b/plugins/transforms/surefirereport/src/main/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportOutputData.java
@@ -19,6 +19,7 @@ package org.apache.hop.pipeline.transforms.surefirereport;
import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.vfs2.FileObject;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.pipeline.transform.BaseTransformData;
import org.apache.hop.pipeline.transform.ITransformData;
@@ -26,6 +27,9 @@ import org.apache.hop.pipeline.transform.ITransformData;
public class SurefireReportOutputData extends BaseTransformData implements
ITransformData {
public IRowMeta outputRowMeta;
+ /** The resolved report file, set in init(). */
+ public FileObject reportFile;
+
public int indexTestName = -1;
public int indexDuration = -1;
public int indexResult = -1;
diff --git
a/plugins/transforms/surefirereport/src/main/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportWriter.java
b/plugins/transforms/surefirereport/src/main/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportWriter.java
index 44ccb43dc5..643cf2fd0a 100644
---
a/plugins/transforms/surefirereport/src/main/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportWriter.java
+++
b/plugins/transforms/surefirereport/src/main/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportWriter.java
@@ -21,12 +21,11 @@ import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.StandardCopyOption;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
+import org.apache.commons.vfs2.FileObject;
+import org.apache.hop.core.vfs.HopVfs;
import
org.apache.hop.pipeline.transforms.surefirereport.SurefireTestCase.Status;
/** Writes Maven Surefire 3.0-compatible XML reports. */
@@ -41,7 +40,12 @@ public final class SurefireReportWriter {
private SurefireReportWriter() {}
- public static void write(Path reportFile, String suiteName,
List<SurefireTestCase> cases)
+ /**
+ * Writes the report. The parent folder of {@code reportFile} must exist:
creating it is up to the
+ * caller (the transform's "Create parent folder" option). A missing folder
fails with an {@link
+ * IOException} that names it.
+ */
+ public static void write(FileObject reportFile, String suiteName,
List<SurefireTestCase> cases)
throws IOException {
int tests = cases.size();
int failures = 0;
@@ -60,15 +64,12 @@ public final class SurefireReportWriter {
}
}
- Path parent = reportFile.getParent();
- if (parent != null) {
- Files.createDirectories(parent);
- }
-
- Path tmp = reportFile.resolveSibling(reportFile.getFileName().toString() +
".tmp");
+ // Write next to the report and move it in place, so a reader never sees a
half-written file.
+ FileObject tmp =
+ reportFile.getParent().resolveFile(reportFile.getName().getBaseName()
+ ".tmp");
try (BufferedWriter out =
new BufferedWriter(
- new OutputStreamWriter(Files.newOutputStream(tmp),
StandardCharsets.UTF_8))) {
+ new OutputStreamWriter(HopVfs.getOutputStream(tmp, false),
StandardCharsets.UTF_8))) {
out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
out.newLine();
out.write("<testsuite xmlns:xsi=\"");
@@ -98,12 +99,7 @@ public final class SurefireReportWriter {
out.newLine();
}
- try {
- Files.move(
- tmp, reportFile, StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.ATOMIC_MOVE);
- } catch (IOException atomicFailed) {
- Files.move(tmp, reportFile, StandardCopyOption.REPLACE_EXISTING);
- }
+ tmp.moveTo(reportFile);
}
private static void writeTestCase(BufferedWriter out, SurefireTestCase c)
throws IOException {
diff --git
a/plugins/transforms/surefirereport/src/main/resources/org/apache/hop/pipeline/transforms/surefirereport/messages/messages_en_US.properties
b/plugins/transforms/surefirereport/src/main/resources/org/apache/hop/pipeline/transforms/surefirereport/messages/messages_en_US.properties
index 9e9ba61a96..924e665c25 100644
---
a/plugins/transforms/surefirereport/src/main/resources/org/apache/hop/pipeline/transforms/surefirereport/messages/messages_en_US.properties
+++
b/plugins/transforms/surefirereport/src/main/resources/org/apache/hop/pipeline/transforms/surefirereport/messages/messages_en_US.properties
@@ -23,6 +23,8 @@ SurefireReportOutput.Error.FilenameMissing=Report filename is
missing!
SurefireReportOutput.Error.TestNameFieldMissing=Test name field is missing!
SurefireReportOutput.Error.CouldNotFindField=Couldn''t find field ''{0}'' in
the input row!
SurefireReportOutput.Error.WriteFailed=Unable to write Surefire report to
''{0}'': {1}
+SurefireReportOutput.Error.ParentFolderDoesNotExist=The folder ''{0}'' of
report file ''{1}'' does not exist. Create it first or turn on "Create parent
folder".
+SurefireReportOutput.Error.ParentFolderIsNotAFolder=''{0}'', the folder of
report file ''{1}'', exists but is not a folder.
SurefireReportOutput.Error.TestsFailed={0} test case(s) failed or errored
SurefireReportOutput.Log.ReportWritten=Wrote Surefire report with {0} test
case(s) to {1}
diff --git
a/plugins/transforms/surefirereport/src/test/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportOutputTest.java
b/plugins/transforms/surefirereport/src/test/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportOutputTest.java
new file mode 100644
index 0000000000..c60a74f5b9
--- /dev/null
+++
b/plugins/transforms/surefirereport/src/test/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportOutputTest.java
@@ -0,0 +1,191 @@
+/*
+ * 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.
+ */
+
+package org.apache.hop.pipeline.transforms.surefirereport;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import org.apache.commons.vfs2.FileObject;
+import org.apache.hop.core.IRowSet;
+import org.apache.hop.core.exception.HopException;
+import org.apache.hop.core.logging.ILoggingObject;
+import org.apache.hop.core.row.IRowMeta;
+import org.apache.hop.core.row.RowMeta;
+import org.apache.hop.core.row.value.ValueMetaString;
+import org.apache.hop.core.vfs.HopVfs;
+import org.apache.hop.i18n.BaseMessages;
+import org.apache.hop.pipeline.transforms.mock.TransformMockHelper;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+class SurefireReportOutputTest {
+
+ private static final Class<?> PKG = SurefireReportOutputMeta.class;
+
+ @TempDir Path tempDir;
+
+ private TransformMockHelper<SurefireReportOutputMeta,
SurefireReportOutputData> helper;
+
+ @BeforeEach
+ void setUp() {
+ helper =
+ new TransformMockHelper<>(
+ "surefire report output",
+ SurefireReportOutputMeta.class,
+ SurefireReportOutputData.class);
+ when(helper.logChannelFactory.create(any(), any(ILoggingObject.class)))
+ .thenReturn(helper.iLogChannel);
+ when(helper.pipeline.isRunning()).thenReturn(true);
+ }
+
+ @AfterEach
+ void tearDown() {
+ helper.cleanUp();
+ }
+
+ @Test
+ void missingFolderFailsInInitWhenCreateParentFolderIsOff() throws Exception {
+ Path report = tempDir.resolve("nofolder/a/b/r.xml");
+ SurefireReportOutput transform = createTransform(report.toString(), false);
+
+ assertFalse(transform.init(), "init() must fail before any test runs");
+
+
verify(helper.iLogChannel).logError(expectedMessage("ParentFolderDoesNotExist",
report));
+ assertFalse(Files.exists(tempDir.resolve("nofolder")), "no folder may be
created");
+ }
+
+ @Test
+ void missingFolderIsCreatedInInitWhenCreateParentFolderIsOn() throws
Exception {
+ Path report = tempDir.resolve("nofolder/a/b/r.xml");
+ SurefireReportOutput transform = createTransform(report.toString(), true);
+
+ assertTrue(transform.init());
+ assertTrue(Files.isDirectory(report.getParent()), "the folder is created
in init()");
+
+ runToEnd(transform);
+ assertTrue(Files.readString(report,
StandardCharsets.UTF_8).contains("tests=\"1\""));
+ }
+
+ @Test
+ void existingFolderIsWrittenWhenCreateParentFolderIsOff() throws Exception {
+ Path report = tempDir.resolve("r.xml");
+ SurefireReportOutput transform = createTransform(report.toString(), false);
+
+ assertTrue(transform.init());
+ runToEnd(transform);
+
+ assertTrue(Files.readString(report,
StandardCharsets.UTF_8).contains("tests=\"1\""));
+ }
+
+ @Test
+ void fileUrlIsResolvedThroughVfs() throws Exception {
+ Path report = tempDir.resolve("r.xml");
+ SurefireReportOutput transform =
createTransform(report.toUri().toString(), false);
+
+ assertTrue(transform.init());
+ runToEnd(transform);
+
+ assertTrue(Files.readString(report,
StandardCharsets.UTF_8).contains("tests=\"1\""));
+ }
+
+ @Test
+ void parentThatIsAFileFails() throws Exception {
+ Files.writeString(tempDir.resolve("data"), "not a folder");
+ Path report = tempDir.resolve("data/r.xml");
+
+ for (boolean createParentFolder : new boolean[] {false, true}) {
+ HopException e =
+ assertThrows(
+ HopException.class,
+ () -> SurefireReportOutput.prepareParentFolder(vfs(report),
createParentFolder));
+ assertEquals(expectedMessage("ParentFolderIsNotAFolder", report),
e.getMessage().trim());
+ }
+ }
+
+ @Test
+ void folderRemovedDuringTheRunFailsWithAClearMessage() throws Exception {
+ Path folder = Files.createDirectory(tempDir.resolve("reports"));
+ Path report = folder.resolve("r.xml");
+ SurefireReportOutput transform = createTransform(report.toString(), false);
+ assertTrue(transform.init());
+
+ Files.delete(folder);
+
+ HopException e = assertThrows(HopException.class, () ->
runToEnd(transform));
+ assertEquals(expectedMessage("ParentFolderDoesNotExist", report),
e.getMessage().trim());
+ }
+
+ private static String expectedMessage(String key, Path report) throws
Exception {
+ FileObject file = vfs(report);
+ return BaseMessages.getString(
+ PKG,
+ "SurefireReportOutput.Error." + key,
+ HopVfs.getFriendlyURI(file.getParent()),
+ HopVfs.getFriendlyURI(file));
+ }
+
+ private static FileObject vfs(Path path) throws HopException {
+ return HopVfs.getFileObject(path.toString());
+ }
+
+ private SurefireReportOutput createTransform(String filename, boolean
createParentFolder) {
+ SurefireReportOutputMeta meta = new SurefireReportOutputMeta();
+ meta.setDefault();
+ meta.setFilename(filename);
+ meta.setSuiteName("suite");
+ meta.setCreateParentFolder(createParentFolder);
+ meta.setTestNameField("testName");
+ meta.setDurationField("");
+ meta.setResultField("");
+ meta.setSystemOutField("");
+ meta.setSystemErrField("");
+ meta.setFailureMessageField("");
+ meta.setFailureTypeField("");
+
+ return new SurefireReportOutput(
+ helper.transformMeta,
+ meta,
+ new SurefireReportOutputData(),
+ 0,
+ helper.pipelineMeta,
+ helper.pipeline);
+ }
+
+ /** Feeds one test-result row and the end of the stream, which writes the
report. */
+ private void runToEnd(SurefireReportOutput transform) throws HopException {
+ IRowMeta rowMeta = new RowMeta();
+ rowMeta.addValueMeta(new ValueMetaString("testName"));
+ IRowSet rowSet = helper.getMockInputRowSet(new Object[]
{"main-0001-test.hwf"});
+ when(rowSet.getRowMeta()).thenReturn(rowMeta);
+ transform.addRowSetToInputRowSets(rowSet);
+
+ while (transform.processRow()) {
+ // one row, then the end of the stream writes the report
+ }
+ }
+}
diff --git
a/plugins/transforms/surefirereport/src/test/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportWriterTest.java
b/plugins/transforms/surefirereport/src/test/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportWriterTest.java
index 849dad36b1..e12240c0b5 100644
---
a/plugins/transforms/surefirereport/src/test/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportWriterTest.java
+++
b/plugins/transforms/surefirereport/src/test/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportWriterTest.java
@@ -19,14 +19,19 @@ package org.apache.hop.pipeline.transforms.surefirereport;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilderFactory;
+import org.apache.commons.vfs2.FileObject;
+import org.apache.hop.core.exception.HopFileException;
+import org.apache.hop.core.vfs.HopVfs;
import
org.apache.hop.pipeline.transforms.surefirereport.SurefireTestCase.Status;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@@ -39,7 +44,7 @@ class SurefireReportWriterTest {
@Test
void writesEmptySuite() throws Exception {
Path report = tempDir.resolve("surefile_empty.xml");
- SurefireReportWriter.write(report, "empty", List.of());
+ SurefireReportWriter.write(vfs(report), "empty", List.of());
String xml = Files.readString(report, StandardCharsets.UTF_8);
assertTrue(xml.contains("name=\"empty\""));
@@ -50,9 +55,32 @@ class SurefireReportWriterTest {
assertFalse(xml.contains("<testcase"));
}
+ @Test
+ void doesNotCreateMissingParentFolder() {
+ Path report = tempDir.resolve("missing/surefile.xml");
+
+ IOException e =
+ assertThrows(
+ IOException.class, () -> SurefireReportWriter.write(vfs(report),
"x", List.of()));
+ assertTrue(e.getMessage().contains("missing"), "names the missing folder:
" + e.getMessage());
+ assertFalse(Files.exists(tempDir.resolve("missing")));
+ }
+
+ @Test
+ void replacesAnExistingReport() throws Exception {
+ Path report = tempDir.resolve("surefile_twice.xml");
+ SurefireReportWriter.write(vfs(report), "first", List.of());
+ SurefireReportWriter.write(vfs(report), "second", List.of());
+
+ String xml = Files.readString(report, StandardCharsets.UTF_8);
+ assertTrue(xml.contains("name=\"second\""));
+ assertFalse(xml.contains("name=\"first\""));
+ assertFalse(Files.exists(tempDir.resolve("surefile_twice.xml.tmp")), "no
temporary file left");
+ }
+
@Test
void writesMixedResultsAndEscapes() throws Exception {
- Path report = tempDir.resolve("nested/surefile_mixed.xml");
+ Path report = tempDir.resolve("surefile_mixed.xml");
List<SurefireTestCase> cases = new ArrayList<>();
cases.add(
new SurefireTestCase("pass-test", 1.5, Status.PASS, "hello ]]> world",
null, null, null));
@@ -62,7 +90,7 @@ class SurefireReportWriterTest {
cases.add(new SurefireTestCase("skip-test", 0.0, Status.SKIP, null, null,
"not now", null));
cases.add(new SurefireTestCase("error-test", 3.0, Status.ERROR, null,
null, "oops", "Error"));
- SurefireReportWriter.write(report, "suite & name", cases);
+ SurefireReportWriter.write(vfs(report), "suite & name", cases);
String xml = Files.readString(report, StandardCharsets.UTF_8);
assertTrue(xml.contains("name=\"suite & name\""));
@@ -97,7 +125,7 @@ class SurefireReportWriterTest {
"boom \u001b[1mhighlighted\u001b[0m",
"AssertionError"));
- SurefireReportWriter.write(report, "dbt", cases);
+ SurefireReportWriter.write(vfs(report), "dbt", cases);
String xml = Files.readString(report, StandardCharsets.UTF_8);
assertFalse(xml.contains("\u001b"), "no escape character may reach the
report");
@@ -141,4 +169,8 @@ class SurefireReportWriterTest {
assertEquals("simple",
SurefireReportOutput.normalizeTestName("main_simple.hwf"));
assertEquals("already-clean",
SurefireReportOutput.normalizeTestName("already-clean"));
}
+
+ private static FileObject vfs(Path path) throws HopFileException {
+ return HopVfs.getFileObject(path.toString());
+ }
}