Spaces:
Sleeping
Sleeping
File size: 1,541 Bytes
03549e5 685180e 03549e5 685180e 03549e5 ec4d503 03549e5 ec4d503 03549e5 685180e 03549e5 ec4d503 03549e5 ec4d503 03549e5 685180e 03549e5 ec4d503 03549e5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
package com.cs102.attendance;
import com.cs102.attendance.repository.StudentRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
class Cs102AttendanceProjectApplicationTests {
@Autowired
private DataSource dataSource;
@Autowired
private StudentRepository studentRepository;
@Test
void contextLoads() {
}
@Test
void testDatabaseConnection() throws SQLException {
// Test that we can get a connection from the DataSource
try (Connection connection = dataSource.getConnection()) {
assertNotNull(connection, "Database connection should not be null");
assertTrue(connection.isValid(5), "Database connection should be valid");
// Print connection details for verification
System.out.println("Database URL: " + connection.getMetaData().getURL());
System.out.println("Database Driver: " + connection.getMetaData().getDriverName());
System.out.println("Database Version: " + connection.getMetaData().getDatabaseProductVersion());
}
}
@Test
void testRepositoryConnection() {
// Test that the repository can execute queries
assertDoesNotThrow(() -> {
long count = studentRepository.count();
assertTrue(count >= 0, "Student count should be non-negative");
}, "Repository test query should not throw an exception");
}
}
|