Skip to content

Commit

Permalink
test(metadata): 添加Metadata读取操作的测试
Browse files Browse the repository at this point in the history
  • Loading branch information
CarmJos committed Aug 16, 2022
1 parent fc0a3e9 commit 274b54b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
2 changes: 2 additions & 0 deletions demo/src/test/java/cc/carm/lib/easysql/EasySQLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public void onTest() {
tests.add(new QueryFunctionTest());
tests.add(new QueryFutureTest());
tests.add(new QueryAsyncTest());

tests.add(new TableMetadataTest());
// tests.add(new DeleteTest());

print("准备进行测试...");
Expand Down
5 changes: 1 addition & 4 deletions demo/src/test/java/cc/carm/lib/easysql/TestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

import java.sql.SQLException;
import java.util.concurrent.ExecutionException;

public abstract class TestHandler {

protected static void print(@NotNull String format, Object... params) {
EasySQLTest.print(format, params);
}

@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) {
String testName = getClass().getSimpleName();
Expand Down
Original file line number Diff line number Diff line change
@@ -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());

}

}

0 comments on commit 274b54b

Please sign in to comment.