Skip to content

Commit 7f8a98d

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 7f8a98d

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

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
@@ -36,6 +36,24 @@ class HtmlReportGeneratorTest : JMeterTestCase() {
3636

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

39+
/**
40+
* Assert that a file exists at the given path relative to a base directory
41+
*/
42+
private fun assertFileExists(baseDir: File, relativePath: String, message: String? = null) {
43+
val file = File(baseDir, relativePath)
44+
val errorMessage = message ?: "$relativePath should exist"
45+
assert(file.exists()) { errorMessage }
46+
}
47+
48+
/**
49+
* Assert that a file does NOT exist at the given path relative to a base directory
50+
*/
51+
private fun assertFileNotExists(baseDir: File, relativePath: String, message: String? = null) {
52+
val file = File(baseDir, relativePath)
53+
val errorMessage = message ?: "$relativePath should NOT exist"
54+
assert(!file.exists()) { errorMessage }
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)