1818package org.apache.jmeter.report.dashboard
1919
2020import com.fasterxml.jackson.databind.ObjectMapper
21+ import org.apache.commons.io.FileUtils
2122import org.apache.jmeter.junit.JMeterTestCase
2223import org.apache.jmeter.util.JMeterUtils
2324import org.junit.jupiter.api.Assertions.assertEquals
@@ -26,7 +27,10 @@ import org.junit.jupiter.api.assertThrows
2627import org.junit.jupiter.api.io.TempDir
2728import org.junit.jupiter.api.parallel.Isolated
2829import java.io.File
30+ import java.nio.file.Files
31+ import java.nio.file.Path
2932import java.nio.file.Paths
33+ import kotlin.io.path.absolutePathString
3034
3135@Isolated(" modifies shared properties" )
3236class 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