18
18
package org.apache.jmeter.report.dashboard
19
19
20
20
import com.fasterxml.jackson.databind.ObjectMapper
21
+ import org.apache.commons.io.FileUtils
21
22
import org.apache.jmeter.junit.JMeterTestCase
22
23
import org.apache.jmeter.util.JMeterUtils
23
24
import org.junit.jupiter.api.Assertions.assertEquals
@@ -26,7 +27,10 @@ import org.junit.jupiter.api.assertThrows
26
27
import org.junit.jupiter.api.io.TempDir
27
28
import org.junit.jupiter.api.parallel.Isolated
28
29
import java.io.File
30
+ import java.nio.file.Files
31
+ import java.nio.file.Path
29
32
import java.nio.file.Paths
33
+ import kotlin.io.path.absolutePathString
30
34
31
35
@Isolated(" modifies shared properties" )
32
36
class ReportGeneratorTest : JMeterTestCase () {
@@ -43,6 +47,29 @@ class ReportGeneratorTest : JMeterTestCase() {
43
47
fun combine (vararg paths : String ) =
44
48
Paths .get(JMeterUtils .getJMeterBinDir(), * paths).toString()
45
49
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
+
46
73
@Test
47
74
fun `check that report generation succeeds and statistics json are generated` () {
48
75
val mapper = ObjectMapper ()
0 commit comments