Skip to content

Commit 71442bd

Browse files
committed
feat: TC SQL Scripts🫸🌀✏️📗🐧🐳⬆
1 parent 9758bd6 commit 71442bd

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package id.my.hendisantika.books;
2+
3+
import org.testcontainers.containers.PostgreSQLContainer;
4+
5+
/**
6+
* Created by IntelliJ IDEA.
7+
* Project : books
8+
* User: hendisantika
9+
* Email: hendisantika@gmail.com
10+
* Telegram : @hendisantika34
11+
* Date: 01/11/24
12+
* Time: 08.16
13+
* To change this template use File | Settings | File Templates.
14+
*/
15+
public class HendiPostgresqlContainer extends PostgreSQLContainer<HendiPostgresqlContainer> {
16+
private static final String IMAGE_VERSION = "postgres:17-alpine3.20";
17+
private static HendiPostgresqlContainer container;
18+
19+
private HendiPostgresqlContainer() {
20+
super(IMAGE_VERSION);
21+
}
22+
23+
public static HendiPostgresqlContainer getInstance() {
24+
if (container == null) {
25+
container = new HendiPostgresqlContainer();
26+
}
27+
return container;
28+
}
29+
30+
@Override
31+
public void start() {
32+
super.start();
33+
System.setProperty("DB_URL", container.getJdbcUrl());
34+
System.setProperty("DB_USERNAME", container.getUsername());
35+
System.setProperty("DB_PASSWORD", container.getPassword());
36+
}
37+
38+
@Override
39+
public void stop() {
40+
//do nothing, JVM handles shut down
41+
}
42+
}

src/test/resources/application.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
spring:
2+
datasource:
3+
url: jdbc:tc:postgresql:17-alpine3.20:///integration-tests-db
4+
driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver
5+
jpa:
6+
hibernate:
7+
ddl-auto: validate

0 commit comments

Comments
 (0)