diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 2b020d7..d7cd731 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Java uses: actions/setup-java@v3 diff --git a/.sdkmanrc b/.sdkmanrc index e791dfd..f52e760 100644 --- a/.sdkmanrc +++ b/.sdkmanrc @@ -1,2 +1,2 @@ -java=17.0.4-tem +java=17.0.8-tem maven=3.8.6 \ No newline at end of file diff --git a/guide/working-with-jooq-flyway-using-testcontainers/index.adoc b/guide/working-with-jooq-flyway-using-testcontainers/index.adoc index 16a37e0..48993dd 100644 --- a/guide/working-with-jooq-flyway-using-testcontainers/index.adoc +++ b/guide/working-with-jooq-flyway-using-testcontainers/index.adoc @@ -90,8 +90,8 @@ Configure the *testcontainers-jooq-codegen-maven-plugin* in `pom.xml` as follows [source,xml] ---- - 1.18.3 - 0.0.2 + 1.19.3 + 0.0.3 3.18.3 42.6.0 @@ -124,7 +124,7 @@ Configure the *testcontainers-jooq-codegen-maven-plugin* in `pom.xml` as follows POSTGRES - postgres:15.3-alpine + postgres:16-alpine @@ -155,7 +155,7 @@ Configure the *testcontainers-jooq-codegen-maven-plugin* in `pom.xml` as follows Let's understand the plugin configuration. * As we are using PostgreSQL database, we have configured the postgres JDBC driver and Testcontainers postgresql libraries as dependencies of the plugin. -* Under `/` section, we have configured the type of the database, POSTGRES, that we want to use it for our code generation, and specified the Docker image name, `postgres:15.3-alpine`, which will be used to create the database instance. +* Under `/` section, we have configured the type of the database, POSTGRES, that we want to use it for our code generation, and specified the Docker image name, `postgres:16-alpine`, which will be used to create the database instance. * Under `/` section we have specified the location of Flyway migration scripts path. * We have also configured the *packageName* and *target* location for the generated code. You can configure all the configuration options supported by the official *jooq-code-generator* plugin. diff --git a/pom.xml b/pom.xml index e65a273..2463801 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.springframework.boot spring-boot-starter-parent - 3.1.0 + 3.2.0 com.testcontainers @@ -17,7 +17,7 @@ UTF-8 17 - 0.0.2 + 0.0.3 @@ -89,7 +89,7 @@ POSTGRES - postgres:15.3-alpine + postgres:16-alpine @@ -116,14 +116,23 @@ com.diffplug.spotless spotless-maven-plugin - 2.37.0 + 2.41.0 - - 2.30.0 - + + + 3.0.3 + 2.3.0 + + + java + 2 + 80 + prettier-plugin-java + + diff --git a/src/main/java/com/testcontainers/demo/Application.java b/src/main/java/com/testcontainers/demo/Application.java index 18585f7..0d3b1e2 100644 --- a/src/main/java/com/testcontainers/demo/Application.java +++ b/src/main/java/com/testcontainers/demo/Application.java @@ -6,7 +6,7 @@ @SpringBootApplication public class Application { - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } } diff --git a/src/main/java/com/testcontainers/demo/domain/Comment.java b/src/main/java/com/testcontainers/demo/domain/Comment.java index ccd8e81..3511e36 100644 --- a/src/main/java/com/testcontainers/demo/domain/Comment.java +++ b/src/main/java/com/testcontainers/demo/domain/Comment.java @@ -2,4 +2,10 @@ import java.time.LocalDateTime; -public record Comment(Long id, String name, String content, LocalDateTime createdAt, LocalDateTime updatedAt) {} +public record Comment( + Long id, + String name, + String content, + LocalDateTime createdAt, + LocalDateTime updatedAt +) {} diff --git a/src/main/java/com/testcontainers/demo/domain/Post.java b/src/main/java/com/testcontainers/demo/domain/Post.java index 6197abd..f8fa010 100644 --- a/src/main/java/com/testcontainers/demo/domain/Post.java +++ b/src/main/java/com/testcontainers/demo/domain/Post.java @@ -4,10 +4,11 @@ import java.util.List; public record Post( - Long id, - String title, - String content, - User createdBy, - List comments, - LocalDateTime createdAt, - LocalDateTime updatedAt) {} + Long id, + String title, + String content, + User createdBy, + List comments, + LocalDateTime createdAt, + LocalDateTime updatedAt +) {} diff --git a/src/main/java/com/testcontainers/demo/domain/PostRepository.java b/src/main/java/com/testcontainers/demo/domain/PostRepository.java index 02b3eb5..dc8be2f 100644 --- a/src/main/java/com/testcontainers/demo/domain/PostRepository.java +++ b/src/main/java/com/testcontainers/demo/domain/PostRepository.java @@ -13,35 +13,39 @@ @Repository class PostRepository { - private final DSLContext dsl; - PostRepository(DSLContext dsl) { - this.dsl = dsl; - } + private final DSLContext dsl; - public Optional getPostById(Long id) { - return this.dsl - .select( - POSTS.ID, - POSTS.TITLE, - POSTS.CONTENT, - row(POSTS.users().ID, POSTS.users().NAME, POSTS.users().EMAIL) - .mapping(User::new) - .as("createdBy"), - multiset(select( - COMMENTS.ID, - COMMENTS.NAME, - COMMENTS.CONTENT, - COMMENTS.CREATED_AT, - COMMENTS.UPDATED_AT) - .from(COMMENTS) - .where(POSTS.ID.eq(COMMENTS.POST_ID))) - .as("comments") - .convertFrom(r -> r.map(mapping(Comment::new))), - POSTS.CREATED_AT, - POSTS.UPDATED_AT) - .from(POSTS) - .where(POSTS.ID.eq(id)) - .fetchOptional(mapping(Post::new)); - } + PostRepository(DSLContext dsl) { + this.dsl = dsl; + } + + public Optional getPostById(Long id) { + return this.dsl.select( + POSTS.ID, + POSTS.TITLE, + POSTS.CONTENT, + row(POSTS.users().ID, POSTS.users().NAME, POSTS.users().EMAIL) + .mapping(User::new) + .as("createdBy"), + multiset( + select( + COMMENTS.ID, + COMMENTS.NAME, + COMMENTS.CONTENT, + COMMENTS.CREATED_AT, + COMMENTS.UPDATED_AT + ) + .from(COMMENTS) + .where(POSTS.ID.eq(COMMENTS.POST_ID)) + ) + .as("comments") + .convertFrom(r -> r.map(mapping(Comment::new))), + POSTS.CREATED_AT, + POSTS.UPDATED_AT + ) + .from(POSTS) + .where(POSTS.ID.eq(id)) + .fetchOptional(mapping(Post::new)); + } } diff --git a/src/main/java/com/testcontainers/demo/domain/UserRepository.java b/src/main/java/com/testcontainers/demo/domain/UserRepository.java index 2cf81be..a9096ae 100644 --- a/src/main/java/com/testcontainers/demo/domain/UserRepository.java +++ b/src/main/java/com/testcontainers/demo/domain/UserRepository.java @@ -10,27 +10,26 @@ @Repository class UserRepository { - private final DSLContext dsl; - UserRepository(DSLContext dsl) { - this.dsl = dsl; - } + private final DSLContext dsl; - public User createUser(User user) { - return this.dsl - .insertInto(USERS) - .set(USERS.NAME, user.name()) - .set(USERS.EMAIL, user.email()) - .set(USERS.CREATED_AT, LocalDateTime.now()) - .returningResult(USERS.ID, USERS.NAME, USERS.EMAIL) - .fetchOne(mapping(User::new)); - } + UserRepository(DSLContext dsl) { + this.dsl = dsl; + } - public Optional getUserByEmail(String email) { - return this.dsl - .select(USERS.ID, USERS.NAME, USERS.EMAIL) - .from(USERS) - .where(USERS.EMAIL.equalIgnoreCase(email)) - .fetchOptional(mapping(User::new)); - } + public User createUser(User user) { + return this.dsl.insertInto(USERS) + .set(USERS.NAME, user.name()) + .set(USERS.EMAIL, user.email()) + .set(USERS.CREATED_AT, LocalDateTime.now()) + .returningResult(USERS.ID, USERS.NAME, USERS.EMAIL) + .fetchOne(mapping(User::new)); + } + + public Optional getUserByEmail(String email) { + return this.dsl.select(USERS.ID, USERS.NAME, USERS.EMAIL) + .from(USERS) + .where(USERS.EMAIL.equalIgnoreCase(email)) + .fetchOptional(mapping(User::new)); + } } diff --git a/src/test/java/com/testcontainers/demo/ContainersConfig.java b/src/test/java/com/testcontainers/demo/ContainersConfig.java index a599b6b..a654b51 100644 --- a/src/test/java/com/testcontainers/demo/ContainersConfig.java +++ b/src/test/java/com/testcontainers/demo/ContainersConfig.java @@ -9,10 +9,10 @@ @TestConfiguration(proxyBeanMethods = false) public class ContainersConfig { - @Bean - @ServiceConnection - @RestartScope - PostgreSQLContainer postgreSQLContainer() { - return new PostgreSQLContainer<>("postgres:15.3-alpine"); - } + @Bean + @ServiceConnection + @RestartScope + PostgreSQLContainer postgreSQLContainer() { + return new PostgreSQLContainer<>("postgres:16-alpine"); + } } diff --git a/src/test/java/com/testcontainers/demo/TestApplication.java b/src/test/java/com/testcontainers/demo/TestApplication.java index b716a8f..75fcf7d 100644 --- a/src/test/java/com/testcontainers/demo/TestApplication.java +++ b/src/test/java/com/testcontainers/demo/TestApplication.java @@ -3,7 +3,11 @@ import org.springframework.boot.SpringApplication; public class TestApplication { - public static void main(String[] args) { - SpringApplication.from(Application::main).with(ContainersConfig.class).run(args); - } + + public static void main(String[] args) { + SpringApplication + .from(Application::main) + .with(ContainersConfig.class) + .run(args); + } } diff --git a/src/test/java/com/testcontainers/demo/domain/PostRepositoryTest.java b/src/test/java/com/testcontainers/demo/domain/PostRepositoryTest.java index c599b59..9f04623 100644 --- a/src/test/java/com/testcontainers/demo/domain/PostRepositoryTest.java +++ b/src/test/java/com/testcontainers/demo/domain/PostRepositoryTest.java @@ -8,24 +8,27 @@ import org.springframework.test.context.jdbc.Sql; @SpringBootTest( - properties = {"spring.test.database.replace=none", "spring.datasource.url=jdbc:tc:postgresql:15.3-alpine:///db" - }) + properties = { + "spring.test.database.replace=none", + "spring.datasource.url=jdbc:tc:postgresql:16-alpine:///db", + } +) @Sql("/test-data.sql") class PostRepositoryTest { - @Autowired - PostRepository repository; + @Autowired + PostRepository repository; - @Test - void shouldGetPostById() { - Post post = repository.getPostById(1L).orElseThrow(); + @Test + void shouldGetPostById() { + Post post = repository.getPostById(1L).orElseThrow(); - assertThat(post.id()).isEqualTo(1L); - assertThat(post.title()).isEqualTo("Post 1 Title"); - assertThat(post.content()).isEqualTo("Post 1 content"); - assertThat(post.createdBy().id()).isEqualTo(1L); - assertThat(post.createdBy().name()).isEqualTo("Siva"); - assertThat(post.createdBy().email()).isEqualTo("siva@gmail.com"); - assertThat(post.comments()).hasSize(2); - } + assertThat(post.id()).isEqualTo(1L); + assertThat(post.title()).isEqualTo("Post 1 Title"); + assertThat(post.content()).isEqualTo("Post 1 content"); + assertThat(post.createdBy().id()).isEqualTo(1L); + assertThat(post.createdBy().name()).isEqualTo("Siva"); + assertThat(post.createdBy().email()).isEqualTo("siva@gmail.com"); + assertThat(post.comments()).hasSize(2); + } } diff --git a/src/test/java/com/testcontainers/demo/domain/UserRepositoryJooqTest.java b/src/test/java/com/testcontainers/demo/domain/UserRepositoryJooqTest.java index 0c9badf..6af87e6 100644 --- a/src/test/java/com/testcontainers/demo/domain/UserRepositoryJooqTest.java +++ b/src/test/java/com/testcontainers/demo/domain/UserRepositoryJooqTest.java @@ -10,38 +10,41 @@ import org.springframework.test.context.jdbc.Sql; @JooqTest( - properties = {"spring.test.database.replace=none", "spring.datasource.url=jdbc:tc:postgresql:15.3-alpine:///db" - }) + properties = { + "spring.test.database.replace=none", + "spring.datasource.url=jdbc:tc:postgresql:16-alpine:///db", + } +) @Sql("/test-data.sql") class UserRepositoryJooqTest { - @Autowired - DSLContext dsl; + @Autowired + DSLContext dsl; - UserRepository repository; + UserRepository repository; - @BeforeEach - void setUp() { - this.repository = new UserRepository(dsl); - } + @BeforeEach + void setUp() { + this.repository = new UserRepository(dsl); + } - @Test - void shouldCreateUserSuccessfully() { - User user = new User(null, "John", "john@gmail.com"); + @Test + void shouldCreateUserSuccessfully() { + User user = new User(null, "John", "john@gmail.com"); - User savedUser = repository.createUser(user); + User savedUser = repository.createUser(user); - assertThat(savedUser.id()).isNotNull(); - assertThat(savedUser.name()).isEqualTo("John"); - assertThat(savedUser.email()).isEqualTo("john@gmail.com"); - } + assertThat(savedUser.id()).isNotNull(); + assertThat(savedUser.name()).isEqualTo("John"); + assertThat(savedUser.email()).isEqualTo("john@gmail.com"); + } - @Test - void shouldGetUserByEmail() { - User user = repository.getUserByEmail("siva@gmail.com").orElseThrow(); + @Test + void shouldGetUserByEmail() { + User user = repository.getUserByEmail("siva@gmail.com").orElseThrow(); - assertThat(user.id()).isEqualTo(1L); - assertThat(user.name()).isEqualTo("Siva"); - assertThat(user.email()).isEqualTo("siva@gmail.com"); - } + assertThat(user.id()).isEqualTo(1L); + assertThat(user.name()).isEqualTo("Siva"); + assertThat(user.email()).isEqualTo("siva@gmail.com"); + } } diff --git a/src/test/java/com/testcontainers/demo/domain/UserRepositoryTest.java b/src/test/java/com/testcontainers/demo/domain/UserRepositoryTest.java index 0252e75..a05473a 100644 --- a/src/test/java/com/testcontainers/demo/domain/UserRepositoryTest.java +++ b/src/test/java/com/testcontainers/demo/domain/UserRepositoryTest.java @@ -16,30 +16,32 @@ @Testcontainers class UserRepositoryTest { - @Container - @ServiceConnection - static PostgreSQLContainer postgres = new PostgreSQLContainer<>("postgres:15.3-alpine"); - - @Autowired - UserRepository repository; - - @Test - void shouldCreateUserSuccessfully() { - User user = new User(null, "John", "john@gmail.com"); - - User savedUser = repository.createUser(user); - - assertThat(savedUser.id()).isNotNull(); - assertThat(savedUser.name()).isEqualTo("John"); - assertThat(savedUser.email()).isEqualTo("john@gmail.com"); - } - - @Test - void shouldGetUserByEmail() { - User user = repository.getUserByEmail("siva@gmail.com").orElseThrow(); - - assertThat(user.id()).isEqualTo(1L); - assertThat(user.name()).isEqualTo("Siva"); - assertThat(user.email()).isEqualTo("siva@gmail.com"); - } + @Container + @ServiceConnection + static PostgreSQLContainer postgres = new PostgreSQLContainer<>( + "postgres:16-alpine" + ); + + @Autowired + UserRepository repository; + + @Test + void shouldCreateUserSuccessfully() { + User user = new User(null, "John", "john@gmail.com"); + + User savedUser = repository.createUser(user); + + assertThat(savedUser.id()).isNotNull(); + assertThat(savedUser.name()).isEqualTo("John"); + assertThat(savedUser.email()).isEqualTo("john@gmail.com"); + } + + @Test + void shouldGetUserByEmail() { + User user = repository.getUserByEmail("siva@gmail.com").orElseThrow(); + + assertThat(user.id()).isEqualTo(1L); + assertThat(user.name()).isEqualTo("Siva"); + assertThat(user.email()).isEqualTo("siva@gmail.com"); + } }