Skip to content

Commit

Permalink
Add test to check report generation from read-only directory
Browse files Browse the repository at this point in the history
Closes #6357 and #6358
  • Loading branch information
FSchumacher committed Oct 25, 2024
1 parent 939ae3c commit 872112b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion xdocs/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Summary
<li><pr>6274</pr> Change references to old MySQL driver to new class <code>com.mysql.cj.jdbc.Driver</code></li>
<li><issue>6352</issue> Calculate delays in Open Model Thread Group and Precise Throughput
Timer relative to start of Thread Group instead of the start of the test.</li>
<li><issue>6357</issue> Ensure writable directories when copying template files while report generation.</li>
<li><issue>6357</issue><pr>6358</pr> Ensure writable directories when copying template files while report generation.</li>
</ul>

<!-- =================== Thanks =================== -->
Expand Down

0 comments on commit 872112b

Please sign in to comment.