Task 4.1: 包名统一重构 - 重命名 41 个 Java 文件的包名 - 更新所有 import 语句 - 恢复枚举类(FaultCategory、DiagnosisStatus、SourceType) - 更新测试类的 import 重构范围: - domain/entity: 3 个实体类 - domain/model: 2 个数据类 - domain/enums: 3 个枚举类 - repository: 3 个接口 - service/session: 2 个类(接口 + 实现) - config: 9 个配置类 - controller: 2 个控制器 - agent/tool: 4 个工具类 - client: 1 个客户端 - Main.java: 主类 验证结果: - 编译成功,无错误 - 所有测试通过 (27/27) - ApiDocumentRepositoryTest: 7/7 ✅ - CaseLibraryRepositoryTest: 6/6 ✅ - DiagnosisRecordRepositoryTest: 6/6 ✅ - RedisSessionManagerTest: 8/8 ✅ Progress: 21/33 tasks completed (64%)
72 lines
2.4 KiB
Java
72 lines
2.4 KiB
Java
package com.superbiz.agent.config;
|
||
|
||
import org.junit.jupiter.api.Test;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
|
||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||
import org.springframework.test.context.TestPropertySource;
|
||
|
||
import javax.sql.DataSource;
|
||
import java.sql.Connection;
|
||
|
||
import static org.junit.jupiter.api.Assertions.*;
|
||
|
||
/**
|
||
* 单独测试 MySQL 连接(不启动完整 Spring Context)
|
||
*/
|
||
@DataJpaTest
|
||
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
|
||
@TestPropertySource(properties = {
|
||
"spring.flyway.enabled=true",
|
||
"spring.jpa.hibernate.ddl-auto=validate"
|
||
})
|
||
class MySQLConnectionTest {
|
||
|
||
@Autowired
|
||
private DataSource dataSource;
|
||
|
||
@Test
|
||
void testMySQLConnection() {
|
||
assertNotNull(dataSource, "DataSource should be configured");
|
||
|
||
try (Connection connection = dataSource.getConnection()) {
|
||
assertNotNull(connection, "Connection should not be null");
|
||
assertFalse(connection.isClosed(), "Connection should be open");
|
||
|
||
String catalog = connection.getCatalog();
|
||
System.out.println("✓ MySQL 连接成功!");
|
||
System.out.println(" 数据库: " + catalog);
|
||
System.out.println(" URL: " + connection.getMetaData().getURL());
|
||
|
||
assertEquals("superbiz_agent", catalog, "Database name should be superbiz_agent");
|
||
|
||
} catch (Exception e) {
|
||
fail("MySQL 连接失败: " + e.getMessage());
|
||
}
|
||
}
|
||
|
||
@Test
|
||
void testFlywayMigration() {
|
||
// 如果能到这里,说明 Flyway 迁移成功
|
||
System.out.println("✓ Flyway 迁移已执行");
|
||
|
||
try (Connection connection = dataSource.getConnection()) {
|
||
var metadata = connection.getMetaData();
|
||
var tables = metadata.getTables(null, null, "%", new String[]{"TABLE"});
|
||
|
||
int tableCount = 0;
|
||
System.out.println(" 已创建的表:");
|
||
while (tables.next()) {
|
||
String tableName = tables.getString("TABLE_NAME");
|
||
System.out.println(" - " + tableName);
|
||
tableCount++;
|
||
}
|
||
|
||
assertTrue(tableCount >= 3, "至少应该有 3 张表 (diagnosis_record, case_library, api_document)");
|
||
|
||
} catch (Exception e) {
|
||
fail("验证表结构失败: " + e.getMessage());
|
||
}
|
||
}
|
||
}
|