bamaer commented on code in PR #9372:
URL: https://github.com/apache/hop/pull/9372#discussion_r4540063626
##########
plugins/transforms/surefirereport/src/main/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportOutput.java:
##########
@@ -223,9 +224,18 @@ private void writeReport() throws HopException {
}
Path reportPath = Paths.get(filename);
- if (meta.isCreateParentFolder() && reportPath.getParent() != null) {
+ Path parentFolder = reportPath.getParent();
+ if (parentFolder != null && !Files.isDirectory(parentFolder)) {
+ if (!meta.isCreateParentFolder()) {
Review Comment:
Thanks @hansva, good catch. `init()` now checks the folder (and creates it
when the option is on), so a missing folder fails before any test runs. It is
checked again before writing in case the folder goes away during the run.
##########
plugins/transforms/surefirereport/src/main/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportOutput.java:
##########
@@ -223,9 +224,18 @@ private void writeReport() throws HopException {
}
Path reportPath = Paths.get(filename);
- if (meta.isCreateParentFolder() && reportPath.getParent() != null) {
+ Path parentFolder = reportPath.getParent();
+ if (parentFolder != null && !Files.isDirectory(parentFolder)) {
Review Comment:
Added a separate "exists but is not a folder" message, used with the option
on or off.
##########
plugins/transforms/surefirereport/src/main/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportOutput.java:
##########
@@ -223,9 +224,18 @@ private void writeReport() throws HopException {
}
Path reportPath = Paths.get(filename);
Review Comment:
Done in this PR: the transform and the writer now go through
`HopVfs`/`FileObject`. There is a test with a `file://` URL and the option off.
##########
plugins/transforms/surefirereport/src/main/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportWriter.java:
##########
@@ -60,11 +64,6 @@ public static void write(Path reportFile, String suiteName,
List<SurefireTestCas
}
}
- Path parent = reportFile.getParent();
- if (parent != null) {
- Files.createDirectories(parent);
- }
-
Path tmp = reportFile.resolveSibling(reportFile.getFileName().toString() +
".tmp");
Review Comment:
With the writer on `HopVfs.getOutputStream`, a missing folder now gives an
IOException that names the folder. The writer test checks that.
##########
plugins/transforms/surefirereport/src/test/java/org/apache/hop/pipeline/transforms/surefirereport/SurefireReportOutputTest.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.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.when;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+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.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 {
+
+ @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 missingFolderFailsWhenCreateParentFolderIsOff() {
+ Path report = tempDir.resolve("nofolder/a/b/r.xml");
+
+ HopException e = assertThrows(HopException.class, () ->
runTransform(report, false));
+
Review Comment:
The tests now compare against `BaseMessages.getString(...)` for the key.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]