001package com.studentgui.test;
002
003import java.time.LocalDate;
004import java.util.List;
005
006import static org.junit.jupiter.api.Assertions.assertNotNull;
007import static org.junit.jupiter.api.Assertions.assertTrue;
008import org.junit.jupiter.api.Test;
009
010import com.studentgui.apphelpers.Helpers;
011import com.studentgui.apphelpers.SqlGenerate;
012
013/**
014 * Small integration-style unit test that uses the normalized Database helper methods
015 * to create a student, a progress type, ensure parts, insert one session and fetch the
016 * latest results. This runs headless and doesn't start any UI components.
017 */
018public class BrailleDatabaseTest {
019
020    @Test
021    /**
022     * Exercise a simple database create/save/fetch flow for Braille session
023     * records and assert basic invariants to detect regressions.
024     */
025
026    public void smokeDatabaseFlow() throws Exception {
027        // Ensure app folders and DB exist
028        Helpers.createFolderHierarchy();
029        SqlGenerate.initializeDatabase();
030
031        int studentId = com.studentgui.apphelpers.Database.getOrCreateStudent("JUnit Smoke Student");
032        assertTrue(studentId > 0);
033
034        int ptId = com.studentgui.apphelpers.Database.getOrCreateProgressType("Braille");
035        assertTrue(ptId > 0);
036
037        String[] codes = new String[5];
038        int[] scores = new int[5];
039        for (int i = 0; i < 5; i++) { codes[i] = "P" + (i+1); scores[i] = (i % 3) + 1; }
040        com.studentgui.apphelpers.Database.ensureAssessmentParts(ptId, codes);
041
042        int sessionId = com.studentgui.apphelpers.Database.createProgressSession(studentId, ptId, LocalDate.now());
043        assertTrue(sessionId > 0);
044
045        com.studentgui.apphelpers.Database.insertAssessmentResults(sessionId, ptId, codes, scores);
046
047        List<List<Integer>> rows = com.studentgui.apphelpers.Database.fetchLatestAssessmentResults("JUnit Smoke Student", "Braille", 5);
048        assertNotNull(rows);
049
050        // At least one row should be returned
051        assertTrue(rows.size() >= 1);
052    }
053}