Skip to content

Commit 957aeac

Browse files
committed
fix: report generation used wrong paths for the output files
The regression was introduced in f5518e3 "chore: remove the use of commons-io and commons-text" getNameWithoutExtension returns the file name without the parent path.
1 parent 1f17592 commit 957aeac

2 files changed

Lines changed: 64 additions & 1 deletion

File tree

src/core/src/main/java/org/apache/jmeter/report/dashboard/TemplateVisitor.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,14 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
104104
// Process template file
105105
String templatePath = relativePath.toString();
106106
Template template = configuration.getTemplate(templatePath);
107-
Path newPath = target.resolve(PathsKt.getNameWithoutExtension(relativePath));
107+
Path newPath = target;
108+
// getNameWithoutExtension returns the file name without the parent folder,
109+
// so we resolve the parent first and then add the file name without extension
110+
Path newRelativeParent = relativePath.getParent();
111+
if (newRelativeParent != null) {
112+
newPath = newPath.resolve(newRelativeParent);
113+
}
114+
newPath = newPath.resolve(PathsKt.getNameWithoutExtension(relativePath));
108115
try (FileOutputStream stream = new FileOutputStream(newPath.toString());
109116
Writer writer = new OutputStreamWriter(stream, StandardCharsets.UTF_8);
110117
BufferedWriter bufferedWriter = new BufferedWriter(writer)){

src/dist-check/src/test/kotlin/org/apache/jmeter/gui/action/HtmlReportGeneratorTest.kt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import com.fasterxml.jackson.databind.ObjectMapper
2121
import org.apache.jmeter.junit.JMeterTestCase
2222
import org.apache.jmeter.util.JMeterUtils
2323
import org.junit.jupiter.api.Assertions.assertEquals
24+
import org.junit.jupiter.api.Assertions.assertFalse
25+
import org.junit.jupiter.api.Assertions.assertTrue
2426
import org.junit.jupiter.api.Test
2527
import org.junit.jupiter.api.fail
2628
import org.junit.jupiter.api.io.TempDir
@@ -36,6 +38,22 @@ class HtmlReportGeneratorTest : JMeterTestCase() {
3638

3739
data class CheckArgumentsCase(val csvPath: String, val userPropertiesPath: String, val outputDirectoryPath: String, val expected: List<String>)
3840

41+
/**
42+
* Assert that a file exists at the given path relative to a base directory
43+
*/
44+
private fun assertFileExists(baseDir: File, relativePath: String, message: String? = null) {
45+
val file = File(baseDir, relativePath)
46+
assertTrue(file.exists()) { message ?: "$relativePath should exist" }
47+
}
48+
49+
/**
50+
* Assert that a file does NOT exist at the given path relative to a base directory
51+
*/
52+
private fun assertFileNotExists(baseDir: File, relativePath: String, message: String? = null) {
53+
val file = File(baseDir, relativePath)
54+
assertFalse(file.exists()) { message ?: "$relativePath should NOT exist" }
55+
}
56+
3957
companion object {
4058
/**
4159
* Combine the given path parts to one path with the correct path separator of the current platform.
@@ -141,4 +159,42 @@ class HtmlReportGeneratorTest : JMeterTestCase() {
141159
fail("First result message should contain '$expectedError', but was '$firstMessage'")
142160
}
143161
}
162+
163+
@Test
164+
fun `report generation creates correct directory structure for HTML and JS files`() {
165+
val htmlReportGenerator = HtmlReportGenerator(
166+
combine("testfiles", "HTMLReportTestFile.csv"),
167+
combine("user.properties"),
168+
testDirectory.toString()
169+
)
170+
htmlReportGenerator.run()
171+
172+
// Verify directory structure exists
173+
assertFileExists(testDirectory, "content")
174+
assertFileExists(testDirectory, "content/pages")
175+
assertFileExists(testDirectory, "content/js")
176+
177+
// Verify HTML pages are in correct location (content/pages/)
178+
assertFileExists(testDirectory, "content/pages/OverTime.html")
179+
assertFileExists(testDirectory, "content/pages/ResponseTimes.html")
180+
assertFileExists(testDirectory, "content/pages/Throughput.html")
181+
assertFileExists(testDirectory, "content/pages/CustomsGraphs.html")
182+
183+
// Verify JavaScript files are in correct location (content/js/)
184+
assertFileExists(testDirectory, "content/js/dashboard.js")
185+
assertFileExists(testDirectory, "content/js/graph.js")
186+
assertFileExists(testDirectory, "content/js/dashboard-commons.js")
187+
assertFileExists(testDirectory, "content/js/customGraph.js")
188+
189+
// Verify files are NOT at root level (catches the bug!)
190+
assertFileNotExists(testDirectory, "OverTime.html", "OverTime.html should NOT be at root level")
191+
assertFileNotExists(testDirectory, "ResponseTimes.html", "ResponseTimes.html should NOT be at root level")
192+
assertFileNotExists(testDirectory, "Throughput.html", "Throughput.html should NOT be at root level")
193+
assertFileNotExists(testDirectory, "CustomsGraphs.html", "CustomsGraphs.html should NOT be at root level")
194+
assertFileNotExists(testDirectory, "dashboard.js", "dashboard.js should NOT be at root level")
195+
assertFileNotExists(testDirectory, "graph.js", "graph.js should NOT be at root level")
196+
197+
// Verify index.html is at root (this should be correct)
198+
assertFileExists(testDirectory, "index.html", "index.html should exist at root level")
199+
}
144200
}

0 commit comments

Comments
 (0)