Skip to content

Commit eda4b75

Browse files
committed
Add test to check report generation from read-only directory
1 parent f4f1ef1 commit eda4b75

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

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()

0 commit comments

Comments
 (0)