From eda4b75c03fd6bcec6a2f1c524dfee503cfdaed8 Mon Sep 17 00:00:00 2001 From: Felix Schumacher Date: Fri, 4 Oct 2024 18:34:10 +0200 Subject: [PATCH] Add test to check report generation from read-only directory --- .../report/dashboard/ReportGeneratorTest.kt | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) 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 6191f7afee7..0c72affaac8 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()