001package com.studentgui.apphelpers; 002 003import java.nio.file.Files; 004import java.nio.file.Path; 005import java.sql.Connection; 006import java.sql.DriverManager; 007import java.sql.ResultSet; 008import java.sql.Statement; 009 010import static org.junit.jupiter.api.Assertions.assertTrue; 011import org.junit.jupiter.api.Test; 012 013/** 014 * Verify SQL schema initialization and helper routines used to create the 015 * application's database structure. 016 */ 017 018public class SqlGenerateTest { 019 020 @Test 021 /** 022 * Verify SQL schema initialization creates the expected contact log table 023 * and related structures needed by the application. 024 */ 025 026 public void testInitializeCreatesContactLogTable() throws Exception { 027 SqlGenerate.initializeDatabase(); 028 Path db = Helpers.DATABASE_PATH; 029 assertTrue(Files.exists(db)); 030 String url = "jdbc:sqlite:" + db.toString(); 031 try (Connection c = DriverManager.getConnection(url)) { 032 try (Statement st = c.createStatement()) { 033 ResultSet rs = st.executeQuery("SELECT name FROM sqlite_master WHERE type='table' AND name='ContactLog'"); 034 assertTrue(rs.next(), "ContactLog table should exist after initialization"); 035 } 036 } 037 } 038}