-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSpringBootDatabaseTest.java
More file actions
41 lines (36 loc) · 1.34 KB
/
SpringBootDatabaseTest.java
File metadata and controls
41 lines (36 loc) · 1.34 KB
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
package com.example;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.Duration;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.oracle.OracleContainer;
@Testcontainers
@SpringBootTest
public class SpringBootDatabaseTest {
/**
* Use a containerized Oracle AI Database instance for testing.
*/
@Container
@ServiceConnection
static OracleContainer oracleContainer = new OracleContainer("gvenzl/oracle-free:23.26.1-slim-faststart")
.withStartupTimeout(Duration.ofMinutes(5))
.withUsername("testuser")
.withPassword("testpwd");
@Autowired
DataSource dataSource;
@Test
void springDatasourceConnection() throws SQLException {
// Query Database version to verify Spring DataSource connection
try (Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement()) {
stmt.executeQuery("select * from v$version");
}
}
}