1414import me .zort .sqllib .internal .annotation .PrimaryKey ;
1515import me .zort .sqllib .mapping .annotation .*;
1616import me .zort .sqllib .model .schema .EntitySchemaBuilder ;
17+ import me .zort .sqllib .model .schema .SQLSchemaSynchronizer ;
1718import org .junit .jupiter .api .*;
1819import org .junit .jupiter .api .condition .EnabledOnOs ;
1920import org .junit .jupiter .api .condition .OS ;
2021
22+ import java .io .File ;
23+ import java .io .IOException ;
2124import java .util .List ;
2225import java .util .Optional ;
2326
3033public class TestCase2 { // Experimental features
3134
3235 private SQLDatabaseConnection connection ;
36+ private SQLDatabaseConnection sqliteConnection ;
3337
3438 @ BeforeAll
3539 public void prepare () {
@@ -45,12 +49,28 @@ public void prepare() {
4549 .withDriver ("com.mysql.cj.jdbc.Driver" )
4650 .build (options );
4751
52+ doPrepareConnection (connection );
53+ }
54+
55+ @ BeforeAll
56+ public void prepareSqlite () throws IOException {
57+ File file = new File (System .getProperty ("user.dir" ) + "/test.db" );
58+ file .delete ();
59+ file .getParentFile ().mkdirs ();
60+ file .createNewFile ();
61+ SQLDatabaseOptions options = new SQLDatabaseOptions ();
62+ options .setDebug (true );
63+ sqliteConnection = SQLConnectionBuilder .ofSQLite (file .getAbsolutePath ())
64+ .build (options );
65+ doPrepareConnection (sqliteConnection );
66+ }
67+
68+ private static void doPrepareConnection (SQLDatabaseConnection connection ) {
4869 assertTrue (connection .connect ());
4970 assertTrue (connection .isConnected ());
5071
5172 assertNull (connection .exec (() -> "DROP TABLE IF EXISTS users;" ).getRejectMessage ());
5273 assertTrue (connection .buildEntitySchema ("users" , User .class ));
53- assertNull (connection .exec (() -> "TRUNCATE TABLE users;" ).getRejectMessage ());
5474 }
5575
5676 @ Timeout (10 )
@@ -75,24 +95,34 @@ public void test1_Mapping() {
7595 @ Timeout (5 )
7696 @ Test
7797 public void test2_Synchronization () {
98+ doTestSynchronization (connection );
99+ doTestSynchronization (sqliteConnection );
100+ }
101+
102+ private static void doTestSynchronization (SQLDatabaseConnection connection ) {
103+ System .out .println (connection .getClass ().getSimpleName () + ":" );
78104 TableSchema schema = new EntitySchemaBuilder ("users" , User .class , ((SQLDatabaseConnectionImpl ) connection ).getOptions ().getNamingStrategy (), false ).buildTableSchema ();
79105 assertEquals (2 , schema .getDefinitions ().length );
80106 assertEquals ("nickname VARCHAR(255) PRIMARY KEY" , schema .getDefinitions ()[0 ]);
81107 assertEquals ("points INTEGER" , schema .getDefinitions ()[1 ]);
82108
83109 TableSchema dbSchema = connection .getSchemaBuilder ("users" ).buildTableSchema ();
84110 assertEquals (2 , dbSchema .getDefinitions ().length );
85- assertEquals ("nickname VARCHAR(255) PRIMARY KEY" , dbSchema .getDefinitions ()[0 ]);
86- assertEquals ("points INTEGER" , dbSchema .getDefinitions ()[1 ]);
111+ assertEquals ("nickname " + adjustColumnType ( connection , " VARCHAR(255) PRIMARY KEY") , dbSchema .getDefinitions ()[0 ]);
112+ assertEquals ("points " + adjustColumnType ( connection , " INTEGER") , dbSchema .getDefinitions ()[1 ]);
87113 assertFalse (connection .synchronizeModel (schema , "users" ));
88114 assertFalse (connection .synchronizeModel ());
89115
90116 assertTrue (connection .synchronizeModel (UserCopy .class , "users" ));
91117
92118 TableSchema copySchema = connection .getSchemaBuilder ("users" ).buildTableSchema ();
93119 assertEquals (2 , copySchema .getDefinitions ().length );
94- assertEquals ("nickname VARCHAR(255) PRIMARY KEY" , copySchema .getDefinitions ()[0 ]);
95- assertEquals ("points INTEGER DEFAULT 0" , copySchema .getDefinitions ()[1 ]);
120+ assertEquals ("nickname " + adjustColumnType (connection , "VARCHAR(255) PRIMARY KEY" ), copySchema .getDefinitions ()[0 ]);
121+ assertEquals ("points " + adjustColumnType (connection , "INTEGER DEFAULT 0" ), copySchema .getDefinitions ()[1 ]);
122+ }
123+
124+ private static String adjustColumnType (SQLDatabaseConnection connection , String type ) {
125+ return ((SQLSchemaSynchronizer ) connection .getSchemaSynchronizer ()).getColumnTypeAdjuster ().adjust (type );
96126 }
97127
98128 @ Timeout (5 )
0 commit comments