Skip to content

Commit

Permalink
Add spring boot testcontainers support for local development
Browse files Browse the repository at this point in the history
  • Loading branch information
juncevich committed May 23, 2023
1 parent db2d663 commit 6030454
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion relay-store-service/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'com.google.cloud.tools.jib' version '3.3.1'
id 'org.springframework.boot' version '3.0.6'
id 'org.springframework.boot' version '3.1.0'
id 'io.spring.dependency-management' version '1.1.0'
id 'java'
id "org.sonarqube" version "4.0.0.2929"
Expand Down Expand Up @@ -86,6 +86,8 @@ dependencies {
// annotationProcessor "io.dekorate:kubernetes-spring-starter:${dekorateVersion}"
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.springframework.boot:spring-boot-testcontainers'
testImplementation 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.testcontainers:postgresql'

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.relay;

import org.springframework.boot.SpringApplication;

public class AppWithTestContainers {

public static void main(String[] args) {
SpringApplication.from(RelaySystemApplication::main).with(TestContainersConfiguration.class).run(args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.relay;

import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.testcontainers.containers.PostgreSQLContainer;

@TestConfiguration(proxyBeanMethods = false)
public class TestContainersConfiguration {

@Bean
@ServiceConnection
public PostgreSQLContainer postgresqlContainer() {
return new PostgreSQLContainer();
}

}

0 comments on commit 6030454

Please sign in to comment.