Skip to content

Commit

Permalink
feat: using testcontainers in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Nov 23, 2023
1 parent b8080ab commit c7a7670
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.example.graphql;

import static org.assertj.core.api.Assertions.assertThat;

import com.example.graphql.common.AbstractIntegrationTest;
import com.example.graphql.dtos.Customer;
import com.example.graphql.dtos.CustomerDTO;
Expand All @@ -17,11 +15,6 @@ class ApplicationIntegrationTest extends AbstractIntegrationTest {
@Autowired
private GraphQlTester graphQlTester;

@Test
void contextLoads() {
assertThat(postgreSQLContainer.isRunning()).isTrue();
}

@Test
void test_query_all_customers() {
this.graphQlTester
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.graphql;

import org.springframework.boot.SpringApplication;
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 TestApplication {

@Bean
@ServiceConnection
PostgreSQLContainer<?> postgreSQLContainer() {
return new PostgreSQLContainer<>("postgres:16.1-alpine");
}

public static void main(String[] args) {
SpringApplication.from(Application::main).with(TestApplication.class).run(args);
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
package com.example.graphql.common;

import static com.example.graphql.utils.AppConstants.PROFILE_IT;
import static com.example.graphql.utils.AppConstants.PROFILE_TEST;

import com.example.graphql.TestApplication;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.test.context.ActiveProfiles;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

@ActiveProfiles({PROFILE_TEST, PROFILE_IT})
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Testcontainers(disabledWithoutDocker = true)
@ActiveProfiles({PROFILE_TEST})
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TestApplication.class)
public abstract class AbstractIntegrationTest {

@Autowired
protected ObjectMapper objectMapper;

@Container
@ServiceConnection
protected static final PostgreSQLContainer<?> postgreSQLContainer =
new PostgreSQLContainer<>("postgres:16.1-alpine");
}

0 comments on commit c7a7670

Please sign in to comment.