Skip to content

Commit

Permalink
Fixed integrationTest configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliopulina committed Jun 14, 2024
1 parent ed8e210 commit dd9865a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/00-build-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ jobs:
- name: Run mvn verify on application
run: mvn -B -q verify --file application/pom.xml
- name: Run integrationTest on application
run: mvn -B -q -Dspring-boot.run.profiles=local,integrationTest verify --file application/pom.xml
run: mvn -B -q -DintegrationTest verify --file application/pom.xml
- name: Run mvn verify on cdk
run: mvn -B -q verify --file cdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Profile;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.EnabledIf;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.testcontainers.containers.DockerComposeContainer;
import org.testcontainers.containers.wait.strategy.Wait;
Expand All @@ -21,30 +21,28 @@
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Testcontainers
//profile that needs to be there to activate the test
@Profile("integrationTest")
@EnabledIf(expression = "#{systemProperties['integrationTest'] != null}", loadContext = false)
//profile that will be set to the SpringBoot application that is going to be integration tested
@ActiveProfiles("local")
public class ApplicationContextTest {

@Autowired
private ApplicationContext context;

@Container
public static DockerComposeContainer<?> environment =
new DockerComposeContainer<>(new File("docker-compose.yml"))
.withExposedService("postgres_1", 5432, Wait.forListeningPort())
.withExposedService("localstack_1", 4566)
.withExposedService("keycloak_1", 8080,
Wait.forHttp("/").forStatusCode(200)
.withStartupTimeout(Duration.ofSeconds(45)))
.withOptions("--compatibility")
.withLocalCompose(true);
public static DockerComposeContainer<?> dockerComposeEnvironment = new DockerComposeContainer<>(
new File("docker-compose.yml"))
.withExposedService("postgres_1", 5432, Wait.forListeningPort())
.withExposedService("localstack_1", 4566)
.withExposedService("keycloak_1", 8080, Wait.forHttp("/")
.forStatusCode(200).withStartupTimeout(Duration.ofSeconds(45)))
.withOptions("--compatibility")
.withLocalCompose(true);

static {
environment.start();
dockerComposeEnvironment.start();
}

@Autowired
private ApplicationContext context;

@Test
public void contextLoads() {
assertThat(context).isNotNull();
Expand Down

0 comments on commit dd9865a

Please sign in to comment.