2020import org .junit .jupiter .api .Test ;
2121import org .tinystruct .ApplicationException ;
2222import org .tinystruct .data .DatabaseOperator ;
23- import org .tinystruct .system .Configuration ;
23+ import org .tinystruct .system .Settings ;
2424
2525import java .io .File ;
2626import java .io .IOException ;
@@ -37,6 +37,7 @@ public class SQLiteGeneratorTest {
3737 private static final String TEST_CLASS = "TestAutoincrement" ;
3838 private static final String TEST_OUTPUT_DIR = "target/test-classes/generated" ;
3939 private static final String TEST_PACKAGE = "org.tinystruct.test.generated" ;
40+ private static final String TEST_DB = "target/test-classes/test.db" ;
4041
4142 @ BeforeEach
4243 public void setUp () throws ApplicationException , SQLException {
@@ -48,18 +49,26 @@ public void setUp() throws ApplicationException, SQLException {
4849 throw new ApplicationException ("Failed to create test directory" , e );
4950 }
5051
51- // Create test table with INTEGER PRIMARY KEY for autoincrement
52+ // Configure SQLite database
53+ System .setProperty ("driver" , "org.sqlite.JDBC" );
54+ System .setProperty ("database.url" , "jdbc:sqlite:" + TEST_DB );
55+ System .setProperty ("database.user" , "" );
56+ System .setProperty ("database.password" , "" );
57+ System .setProperty ("database.connections.max" , "1" );
58+
59+ // Create test table with INTEGER PRIMARY KEY AUTOINCREMENT
5260 try (DatabaseOperator operator = new DatabaseOperator ()) {
61+ operator .disableSafeCheck ();
5362 // Drop table if exists
5463 try {
5564 operator .execute ("DROP TABLE IF EXISTS " + TEST_TABLE );
5665 } catch (Exception e ) {
5766 // Ignore if table doesn't exist
5867 }
5968
60- // Create table with INTEGER PRIMARY KEY for autoincrement
69+ // Create table with INTEGER PRIMARY KEY AUTOINCREMENT
6170 String createTableSQL = "CREATE TABLE " + TEST_TABLE + " (" +
62- "id INTEGER PRIMARY KEY, " +
71+ "id INTEGER PRIMARY KEY AUTOINCREMENT , " +
6372 "name TEXT, " +
6473 "age INTEGER)" ;
6574 operator .execute (createTableSQL );
@@ -97,11 +106,26 @@ public void testAutoIncrementIdColumn() throws ApplicationException {
97106
98107 @ AfterEach
99108 public void tearDown () throws ApplicationException {
100- // Drop test table
109+ // Drop test table and delete database file
101110 try (DatabaseOperator operator = new DatabaseOperator ()) {
111+ operator .disableSafeCheck ();
102112 operator .execute ("DROP TABLE IF EXISTS " + TEST_TABLE );
103113 } catch (Exception e ) {
104114 throw new ApplicationException ("Failed to drop test table" , e );
105115 }
116+
117+ // Delete the test database file
118+ /* try {
119+ Files.deleteIfExists(Paths.get(TEST_DB));
120+ } catch (IOException e) {
121+ throw new ApplicationException("Failed to delete test database file", e);
122+ }*/
123+
124+ // Clear system properties
125+ System .clearProperty ("driver" );
126+ System .clearProperty ("database.url" );
127+ System .clearProperty ("database.user" );
128+ System .clearProperty ("database.password" );
129+ System .clearProperty ("database.connections.max" );
106130 }
107131}
0 commit comments