001package com.studentgui.tools; 002 003import java.nio.file.Path; 004import java.time.LocalDate; 005import java.time.format.DateTimeFormatter; 006import java.util.ArrayList; 007import java.util.List; 008 009import com.studentgui.apphelpers.Helpers; 010import com.studentgui.apppages.JLineGraph; 011 012/** 013 * Minimal automated smoke test for chart rendering and PNG export functionality. 014 * 015 * <p>Generates deterministic synthetic assessment data, renders it via {@link JLineGraph}, 016 * and writes a PNG to the app data folder. Used to verify:</p> 017 * <ul> 018 * <li>JFreeChart rendering pipeline functions correctly</li> 019 * <li>PNG export via {@link JLineGraph#saveChart} produces valid image files</li> 020 * <li>File I/O permissions and folder creation work as expected</li> 021 * <li>Chart layout and visual appearance match expectations (manual review)</li> 022 * </ul> 023 * 024 * <p><b>Usage:</b></p> 025 * <pre>{@code 026 * java -cp StudentDataGUI.jar com.studentgui.tools.SmokeTest 027 * }</pre> 028 * 029 * <p><b>Expected Output:</b></p> 030 * <pre> 031 * Smoke test wrote chart to: /path/to/app_home/StudentDataFiles/Smoke_Test/plots/SmokeTest-2024-01-15.png 032 * Exists: true 033 * </pre> 034 * 035 * <p><b>Test Data:</b> Generates 3 synthetic sessions with 28 skills each, using 036 * the formula {@code (skillIndex + sessionIndex) % 5} to produce deterministic 037 * values in the 0–4 range.</p> 038 * 039 * <p><b>Output Location:</b> {@code app_home/StudentDataFiles/Smoke_Test/plots/SmokeTest-<ISO_DATE>.png}</p> 040 * 041 * <p><b>Validation:</b> Success is indicated by "Exists: true" output and a valid 042 * 800×400px PNG file at the reported path. Visual inspection of the chart should show 043 * 3 line series (2 gray, 1 black) with colored background bands.</p> 044 * 045 * @see com.studentgui.apppages.JLineGraph#updateWithData 046 * @see com.studentgui.apppages.JLineGraph#saveChart 047 * @see com.studentgui.apphelpers.Helpers#createFolderHierarchy() 048 */ 049public class SmokeTest { 050 /** 051 * Entry point for the smoke test. 052 * 053 * @param args ignored 054 * @throws Exception on IO or chart errors 055 */ 056 public static void main(final String[] args) throws Exception { 057 Helpers.createFolderHierarchy(); 058 JLineGraph graph = new JLineGraph(); 059 060 // Create sample data: 3 sessions, each with 28 skill values (0-4) 061 List<List<Integer>> data = new ArrayList<>(); 062 for (int s = 0; s < 3; s++) { 063 List<Integer> row = new ArrayList<>(); 064 for (int i = 0; i < 28; i++) { 065 row.add((i + s) % 5); // deterministic sample 066 } 067 data.add(row); 068 } 069 graph.updateWithData(data); 070 071 Path outDir = Helpers.APP_HOME.resolve("StudentDataFiles").resolve(Helpers.safeName("Smoke Test")).resolve("plots"); 072 DateTimeFormatter df = DateTimeFormatter.ISO_DATE; 073 Path outFile = outDir.resolve("SmokeTest-" + LocalDate.now().format(df) + ".png"); 074 graph.saveChart(outFile, 800, 400); 075 System.out.println("Smoke test wrote chart to: " + outFile.toAbsolutePath()); 076 System.out.println("Exists: " + java.nio.file.Files.exists(outFile)); 077 } 078 079 /** 080 * Private constructor to prevent instantiation of this utility test class. 081 */ 082 private SmokeTest() { 083 // no instances 084 } 085}