22301024 | 1b22bd7 | 2025-06-07 03:21:07 +0800 | [diff] [blame] | 1 | package edu.bjtu.groupone.backend; |
| 2 | |
| 3 | import org.junit.jupiter.api.Test; |
| 4 | import org.springframework.beans.factory.annotation.Autowired; |
| 5 | import org.springframework.boot.test.context.SpringBootTest; |
| 6 | |
| 7 | import javax.sql.DataSource; |
| 8 | import java.sql.Connection; |
| 9 | |
| 10 | import static org.junit.jupiter.api.Assertions.*; |
| 11 | |
| 12 | @SpringBootTest |
| 13 | public class DatabaseConnectionTest { |
| 14 | |
| 15 | @Autowired |
| 16 | private DataSource dataSource; |
| 17 | |
| 18 | @Test |
| 19 | public void testDatabaseConnection() { |
| 20 | try (Connection connection = dataSource.getConnection()) { |
| 21 | assertNotNull(connection); |
| 22 | System.out.println("✅ 数据库连接成功: " + connection.getMetaData().getURL()); |
| 23 | System.out.println("📌 数据库用户: " + connection.getMetaData().getUserName()); |
| 24 | } catch (Exception e) { |
| 25 | fail("❌ 数据库连接失败: " + e.getMessage()); |
| 26 | } |
| 27 | } |
| 28 | } |