001package com.studentgui.test; 002 003import static org.junit.jupiter.api.Assertions.*; 004 005import java.time.LocalDate; 006import java.util.List; 007 008import org.junit.jupiter.api.BeforeAll; 009import org.junit.jupiter.api.Test; 010 011import com.studentgui.apphelpers.Helpers; 012import com.studentgui.apphelpers.SqlGenerate; 013 014/** 015 * Basic integration tests for the Database helper using the on-disk sqlite 016 * created in the project's application data folder. These tests are small and 017 * intentionally exercise CRUD paths used by the UI pages. 018 */ 019public class DatabaseTest { 020 021 @BeforeAll 022 public static void init() throws Exception { 023 Helpers.createFolderHierarchy(); 024 SqlGenerate.initializeDatabase(); 025 } 026 027 @Test 028 /** 029 * Test creating a student record and fetching it back to ensure basic 030 * CRUD operations work as expected. 031 */ 032 033 public void testStudentCreateAndFetch() throws Exception { 034 int sid = com.studentgui.apphelpers.Database.getOrCreateStudent("Test Student A"); 035 assertTrue(sid > 0); 036 037 int ptId = com.studentgui.apphelpers.Database.getOrCreateProgressType("TestType"); 038 assertTrue(ptId > 0); 039 040 String[] parts = new String[] {"P1","P2","P3"}; 041 com.studentgui.apphelpers.Database.ensureAssessmentParts(ptId, parts); 042 043 int sessionId = com.studentgui.apphelpers.Database.createProgressSession(sid, ptId, LocalDate.now()); 044 assertTrue(sessionId > 0); 045 046 int[] scores = new int[] {1,2,3}; 047 com.studentgui.apphelpers.Database.insertAssessmentResults(sessionId, ptId, parts, scores); 048 049 List<List<Integer>> results = com.studentgui.apphelpers.Database.fetchLatestAssessmentResults("Test Student A", "TestType", 5); 050 assertNotNull(results); 051 assertTrue(results.size() >= 1); 052 } 053}