Skip to content

Commit 872112b

Browse files
committed
Add test to check report generation from read-only directory
Closes #6357 and #6358
1 parent 939ae3c commit 872112b

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/dist-check/src/test/kotlin/org/apache/jmeter/report/dashboard/ReportGeneratorTest.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.jmeter.report.dashboard
1919

2020
import com.fasterxml.jackson.databind.ObjectMapper
21+
import org.apache.commons.io.FileUtils
2122
import org.apache.jmeter.junit.JMeterTestCase
2223
import org.apache.jmeter.util.JMeterUtils
2324
import org.junit.jupiter.api.Assertions.assertEquals
@@ -26,7 +27,10 @@ import org.junit.jupiter.api.assertThrows
2627
import org.junit.jupiter.api.io.TempDir
2728
import org.junit.jupiter.api.parallel.Isolated
2829
import java.io.File
30+
import java.nio.file.Files
31+
import java.nio.file.Path
2932
import java.nio.file.Paths
33+
import kotlin.io.path.absolutePathString
3034

3135
@Isolated("modifies shared properties")
3236
class ReportGeneratorTest : JMeterTestCase() {
@@ -43,6 +47,29 @@ class ReportGeneratorTest : JMeterTestCase() {
4347
fun combine(vararg paths: String) =
4448
Paths.get(JMeterUtils.getJMeterBinDir(), *paths).toString()
4549

50+
@Test
51+
fun `check that report generation succeeds from read-only templates`() {
52+
val roTemplate = Files.createTempDirectory("report-template-ro")
53+
FileUtils.copyDirectoryToDirectory(Path.of(combine("report-template")).toFile(), roTemplate.toFile())
54+
Files.walk(roTemplate).forEach { p -> p.toFile().setReadOnly() }
55+
JMeterUtils.setProperty("jmeter.reportgenerator.exporter.html.property.template_dir", roTemplate.absolutePathString())
56+
val roReport = Files.createTempDirectory("report-from-ro-template")
57+
58+
val mapper = ObjectMapper()
59+
val expected = ReportGenerator::class.java.getResource("/org/apache/jmeter/gui/report/HTMLReportExpect.json")
60+
val expectedRoot = mapper.readTree(expected)
61+
62+
JMeterUtils.setProperty("jmeter.reportgenerator.outputdir", roReport.absolutePathString())
63+
val reportGenerator = ReportGenerator(
64+
combine("testfiles", "HTMLReportTestFile.csv"), null
65+
)
66+
reportGenerator.generate()
67+
val statistics = File(roReport.toFile(), "statistics.json")
68+
val actualRoot = mapper.readTree(statistics)
69+
70+
assertEquals(expectedRoot, actualRoot, "test report json file")
71+
}
72+
4673
@Test
4774
fun `check that report generation succeeds and statistics json are generated`() {
4875
val mapper = ObjectMapper()

xdocs/changes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Summary
6767
<li><pr>6274</pr> Change references to old MySQL driver to new class <code>com.mysql.cj.jdbc.Driver</code></li>
6868
<li><issue>6352</issue> Calculate delays in Open Model Thread Group and Precise Throughput
6969
Timer relative to start of Thread Group instead of the start of the test.</li>
70-
<li><issue>6357</issue> Ensure writable directories when copying template files while report generation.</li>
70+
<li><issue>6357</issue><pr>6358</pr> Ensure writable directories when copying template files while report generation.</li>
7171
</ul>
7272

7373
<!-- =================== Thanks =================== -->

0 commit comments

Comments
 (0)