add dao test

This commit is contained in:
2025-12-23 13:38:51 +08:00
parent b072f82a8f
commit ce67127d0d
8 changed files with 58 additions and 0 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+58
View File
@@ -0,0 +1,58 @@
package test
import com.msksbr.SQL.Connector
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
class TestDao {
private var connector: Connector? = null
@BeforeEach
fun setUp() {
connector = Connector()
connector?.executeUpdate(
"CREATE TABLE test_table(\n" +
"\ttest_string CHAR(35),\n" +
"\ttest_int INT\n" +
");"
)
connector?.executeUpdate(
"INSERT INTO test_table\n" +
"VALUES (\n" +
" '1',1\n" +
" );"
)
}
@AfterEach
fun tearDown() {
connector?.executeUpdate("DROP TABLE test_table")
}
@Test
fun testQuery() {
val rs = connector!!.executeQuery("SELECT * FROM test_table")
assertNotNull(rs,"result was null")
assertTrue(rs.next(),"No results found")
assertEquals(rs.getString("test_string"), "1","test_string is not \"1\"")
assertEquals(rs.getInt("test_int"), 1,"test_int is not 1")
}
@Test
fun testUpdate(){
val rs = connector!!.executeUpdate("INSERT INTO test_table\n" +
"VALUES (\n" +
" '2',2\n" +
" );")
val rs_q=connector!!.executeQuery("SELECT * FROM test_table WHERE test_string = '2';")
assertNotNull(rs,"result was null")
assertNotNull(rs_q,"result_q was null")
assertTrue(rs_q.next(),"no results found")
assertEquals(rs_q.getString("test_string"), "2","test_string is not \"2\"")
assertEquals(rs_q.getInt("test_int"), 2,"test_int is not 1")
}
}