Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : using aws Serviceconnection for testcontainers in dev mode #665

Merged
merged 8 commits into from
Apr 2, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class ApplicationIntegrationTest extends AbstractIntegrationTest {

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

UUID id = UUID.randomUUID();
String email = "[email protected]";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.learning.awsspring;

import lombok.extern.slf4j.Slf4j;
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.localstack.LocalStackContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;

@Slf4j
@TestConfiguration(proxyBeanMethods = false)
public class TestApplication {

@Bean
@ServiceConnection
LocalStackContainer localstackContainer() {
LocalStackContainer localstackContainer =
new LocalStackContainer(
DockerImageName.parse("localstack/localstack").withTag("3.3.0"))
.withCopyFileToContainer(
MountableFile.forHostPath(".localstack/"),
"/etc/localstack/init/ready.d/")
.waitingFor(Wait.forLogMessage(".*Initialized\\.\n", 1));
localstackContainer.start();
Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(log);
localstackContainer.followOutput(logConsumer);
return localstackContainer;
}

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
Expand Up @@ -4,16 +4,17 @@
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.learning.awsspring.TestApplication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;

@ActiveProfiles({PROFILE_TEST})
@SpringBootTest(webEnvironment = RANDOM_PORT)
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = TestApplication.class)
@AutoConfigureMockMvc
public abstract class AbstractIntegrationTest extends LocalStackConfig {
public abstract class AbstractIntegrationTest {

@Autowired protected MockMvc mockMvc;

Expand Down

This file was deleted.