This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit 872112bf5d08d2f698f765b3c950b2898ec23e98
Author: Felix Schumacher <[email protected]>
AuthorDate: Fri Oct 4 18:34:10 2024 +0200

    Add test to check report generation from read-only directory
    
    Closes #6357 and #6358
---
 .../jmeter/report/dashboard/ReportGeneratorTest.kt | 27 ++++++++++++++++++++++
 xdocs/changes.xml                                  |  2 +-
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git 
a/src/dist-check/src/test/kotlin/org/apache/jmeter/report/dashboard/ReportGeneratorTest.kt
 
b/src/dist-check/src/test/kotlin/org/apache/jmeter/report/dashboard/ReportGeneratorTest.kt
index 6191f7afee..0c72affaac 100644
--- 
a/src/dist-check/src/test/kotlin/org/apache/jmeter/report/dashboard/ReportGeneratorTest.kt
+++ 
b/src/dist-check/src/test/kotlin/org/apache/jmeter/report/dashboard/ReportGeneratorTest.kt
@@ -18,6 +18,7 @@
 package org.apache.jmeter.report.dashboard
 
 import com.fasterxml.jackson.databind.ObjectMapper
+import org.apache.commons.io.FileUtils
 import org.apache.jmeter.junit.JMeterTestCase
 import org.apache.jmeter.util.JMeterUtils
 import org.junit.jupiter.api.Assertions.assertEquals
@@ -26,7 +27,10 @@ import org.junit.jupiter.api.assertThrows
 import org.junit.jupiter.api.io.TempDir
 import org.junit.jupiter.api.parallel.Isolated
 import java.io.File
+import java.nio.file.Files
+import java.nio.file.Path
 import java.nio.file.Paths
+import kotlin.io.path.absolutePathString
 
 @Isolated("modifies shared properties")
 class ReportGeneratorTest : JMeterTestCase() {
@@ -43,6 +47,29 @@ class ReportGeneratorTest : JMeterTestCase() {
     fun combine(vararg paths: String) =
         Paths.get(JMeterUtils.getJMeterBinDir(), *paths).toString()
 
+    @Test
+    fun `check that report generation succeeds from read-only templates`() {
+        val roTemplate = Files.createTempDirectory("report-template-ro")
+        
FileUtils.copyDirectoryToDirectory(Path.of(combine("report-template")).toFile(),
 roTemplate.toFile())
+        Files.walk(roTemplate).forEach { p -> p.toFile().setReadOnly() }
+        
JMeterUtils.setProperty("jmeter.reportgenerator.exporter.html.property.template_dir",
 roTemplate.absolutePathString())
+        val roReport = Files.createTempDirectory("report-from-ro-template")
+
+        val mapper = ObjectMapper()
+        val expected = 
ReportGenerator::class.java.getResource("/org/apache/jmeter/gui/report/HTMLReportExpect.json")
+        val expectedRoot = mapper.readTree(expected)
+
+        JMeterUtils.setProperty("jmeter.reportgenerator.outputdir", 
roReport.absolutePathString())
+        val reportGenerator = ReportGenerator(
+            combine("testfiles", "HTMLReportTestFile.csv"), null
+        )
+        reportGenerator.generate()
+        val statistics = File(roReport.toFile(), "statistics.json")
+        val actualRoot = mapper.readTree(statistics)
+
+        assertEquals(expectedRoot, actualRoot, "test report json file")
+    }
+
     @Test
     fun `check that report generation succeeds and statistics json are 
generated`() {
         val mapper = ObjectMapper()
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index b3c79ec82e..f50ac08b50 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -67,7 +67,7 @@ Summary
     <li><pr>6274</pr> Change references to old MySQL driver to new class 
<code>com.mysql.cj.jdbc.Driver</code></li>
     <li><issue>6352</issue> Calculate delays in Open Model Thread Group and 
Precise Throughput
         Timer relative to start of Thread Group instead of the start of the 
test.</li>
-    <li><issue>6357</issue> Ensure writable directories when copying template 
files while report generation.</li>
+    <li><issue>6357</issue><pr>6358</pr> Ensure writable directories when 
copying template files while report generation.</li>
   </ul>
 
  <!--  =================== Thanks =================== -->

Reply via email to