Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
2a0f96f
Add TestContainers sample for Doma Spring Boot (Fixes #290)
devin-ai-integration[bot] May 19, 2025
448f356
Revise TestContainers sample to use Spring Boot's native TestContaine…
devin-ai-integration[bot] May 19, 2025
5198bb1
Fix code formatting issues
devin-ai-integration[bot] May 19, 2025
1e42f72
Update TestContainers sample to use Spring Initializr generated approach
devin-ai-integration[bot] May 19, 2025
06610a1
Remove old TestContainersConfig.java file
devin-ai-integration[bot] May 19, 2025
45661c4
Update TestContainers sample based on feedback: use RestClient, remov…
devin-ai-integration[bot] May 19, 2025
87b5535
Update TestContainers sample based on feedback: remove explicit diale…
devin-ai-integration[bot] May 19, 2025
237ea2d
Change page and size parameters to integers in ApplicationTest
devin-ai-integration[bot] May 19, 2025
487094d
Update transaction manager logging to use JdbcTransactionManager
devin-ai-integration[bot] May 19, 2025
2a5fa14
Use diamond operator for ParameterizedTypeReference
devin-ai-integration[bot] May 19, 2025
ccf7bfc
Add Maven wrapper info to README and remove redundant application-tes…
devin-ai-integration[bot] May 19, 2025
ccbf51f
Add Maven wrapper files to TestContainers sample
devin-ai-integration[bot] May 19, 2025
cf62c8e
Address PR comments: add SQL logging, remove useless comment, remove …
devin-ai-integration[bot] May 19, 2025
5f6bdc4
Remove JUnit comment from pom.xml
devin-ai-integration[bot] May 19, 2025
5f5aa9a
Remove TestContainers comment from pom.xml
devin-ai-integration[bot] May 19, 2025
37dc226
Remove PostgreSQL Driver comment and fix README.md to remove H2 refer…
devin-ai-integration[bot] May 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<!-- H2 for local development -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -59,30 +53,16 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<!-- TestContainers dependencies -->
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.19.7</version>
<scope>test</scope>
</dependency>
<!-- Spring Boot manages TestContainers dependencies -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this comment as well

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.19.7</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>1.19.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
<version>${spring-boot.version}</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Development configuration using H2
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
# Development configuration using TestContainers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is useless

spring.sql.init.mode=always

# Doma configuration
doma.dialect=H2
doma.dialect=POSTGRES
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doma.dialect should be automatically detected via JdbcConnectionDetails

doma.naming=SNAKE_LOWER_CASE
logging.level.org.springframework.jdbc.datasource.DataSourceTransactionManager=DEBUG
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DataSourceTransactionManager is old. Use JdbcTransactionManager instead.

logging.level.org.springframework.jdbc.support.JdbcTransactionManager=DEBUG

Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,56 @@

import java.util.List;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.context.annotation.Import;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.web.client.RestClient;
import org.springframework.web.util.UriComponentsBuilder;

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@Import(TestcontainersConfiguration.class)
class ApplicationTest {
@Autowired
private TestRestTemplate restTemplate;
private RestClient restClient;
private final ParameterizedTypeReference<List<Message>> typedReference = new ParameterizedTypeReference<List<Message>>() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicit type argument List<Message> can be replaced with <>

};
@LocalServerPort
private int port;

@BeforeEach
void setUp(@Autowired RestClient.Builder restClientBuilder) {
this.restClient = restClientBuilder.defaultStatusHandler(__ -> true, (req, res) -> {
}).build();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use .baseUrl("http://localhost:" + port) to build the RestClient and use .uri("/?text={text}", "hello") for each test method

}

@Test
void testWithTestContainers() {
Message message1 = restTemplate.getForObject(
UriComponentsBuilder.fromUriString("http://localhost").port(port)
.queryParam("text", "hello").build().toUri(),
Message.class);
Message message1 = restClient.get()
.uri(UriComponentsBuilder.fromUriString("http://localhost").port(port)
.queryParam("text", "hello").build().toUri())
.retrieve()
.body(Message.class);
assertEquals(1, message1.id);
assertEquals("hello", message1.text);
Message message2 = restTemplate.getForObject(
UriComponentsBuilder.fromUriString("http://localhost").port(port)
.queryParam("text", "world").build().toUri(),
Message.class);

Message message2 = restClient.get()
.uri(UriComponentsBuilder.fromUriString("http://localhost").port(port)
.queryParam("text", "world").build().toUri())
.retrieve()
.body(Message.class);
assertEquals(2, message2.id);
assertEquals("world", message2.text);

{
List<Message> messages = restTemplate.exchange(
UriComponentsBuilder.fromUriString("http://localhost").port(port)
.build().toUri(),
HttpMethod.GET, HttpEntity.EMPTY,
typedReference).getBody();
List<Message> messages = restClient.get()
.uri(UriComponentsBuilder.fromUriString("http://localhost").port(port)
.build().toUri())
.retrieve()
.body(typedReference);
assertEquals(2, messages.size());
assertEquals(message1.id, messages.get(0).id);
assertEquals(message1.text, messages.get(0).text);
Expand All @@ -55,12 +62,12 @@ void testWithTestContainers() {
}

{
List<Message> messages = restTemplate.exchange(
UriComponentsBuilder.fromUriString("http://localhost").port(port)
List<Message> messages = restClient.get()
.uri(UriComponentsBuilder.fromUriString("http://localhost").port(port)
.queryParam("page", "1").queryParam("size", "1").build()
.toUri(),
HttpMethod.GET, HttpEntity.EMPTY, typedReference)
.getBody();
.toUri())
.retrieve()
.body(typedReference);
assertEquals(1, messages.size());
assertEquals(message2.id, messages.get(0).id);
assertEquals(message2.text, messages.get(0).text);
Expand Down