mirror of
https://github.com/CarmJos/EasySQL.git
synced 2026-06-04 15:28:20 +08:00
test(metadata): 添加Metadata读取操作的测试
This commit is contained in:
@@ -52,6 +52,8 @@ public class EasySQLTest {
|
|||||||
tests.add(new QueryFunctionTest());
|
tests.add(new QueryFunctionTest());
|
||||||
tests.add(new QueryFutureTest());
|
tests.add(new QueryFutureTest());
|
||||||
tests.add(new QueryAsyncTest());
|
tests.add(new QueryAsyncTest());
|
||||||
|
|
||||||
|
tests.add(new TableMetadataTest());
|
||||||
// tests.add(new DeleteTest());
|
// tests.add(new DeleteTest());
|
||||||
|
|
||||||
print("准备进行测试...");
|
print("准备进行测试...");
|
||||||
|
|||||||
@@ -4,9 +4,6 @@ import cc.carm.lib.easysql.api.SQLManager;
|
|||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
|
|
||||||
public abstract class TestHandler {
|
public abstract class TestHandler {
|
||||||
|
|
||||||
protected static void print(@NotNull String format, Object... params) {
|
protected static void print(@NotNull String format, Object... params) {
|
||||||
@@ -14,7 +11,7 @@ public abstract class TestHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiStatus.OverrideOnly
|
@ApiStatus.OverrideOnly
|
||||||
public abstract void onTest(SQLManager sqlManager) throws SQLException, ExecutionException, InterruptedException;
|
public abstract void onTest(SQLManager sqlManager) throws Exception;
|
||||||
|
|
||||||
public boolean executeTest(int index, SQLManager sqlManager) {
|
public boolean executeTest(int index, SQLManager sqlManager) {
|
||||||
String testName = getClass().getSimpleName();
|
String testName = getClass().getSimpleName();
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package cc.carm.lib.easysql.tests;
|
||||||
|
|
||||||
|
import cc.carm.lib.easysql.TestHandler;
|
||||||
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public class TableMetadataTest extends TestHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTest(SQLManager sqlManager) throws Exception {
|
||||||
|
|
||||||
|
print(" 获取数据库中所有的表");
|
||||||
|
CompletableFuture<List<String>> tables = sqlManager.fetchMetadata(
|
||||||
|
(meta) -> meta.getTables(null, null, "%", new String[]{"TABLE"}),
|
||||||
|
(rs) -> {
|
||||||
|
List<String> data = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
data.add(rs.getString("TABLE_NAME"));
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
print("表名:" + Arrays.toString(tables.get().toArray()));
|
||||||
|
|
||||||
|
print(" 获取数据库中所有的列");
|
||||||
|
CompletableFuture<Set<String>> columns = sqlManager.fetchTableMetadata("test%").listColumns();
|
||||||
|
print("列名:" + Arrays.toString(columns.get().toArray()));
|
||||||
|
|
||||||
|
print("表是否存在 " + sqlManager.fetchTableMetadata("test_user_info").validateExist().get());
|
||||||
|
print("列是否存在 " + sqlManager.fetchTableMetadata("test_user_info").isColumnExists("uid").get());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user