Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ All tutorials are documented in AsciiDoc format and published as an https://anto
|link:modulith[Spring Modulith: Building Modular Monolithic Applications] | Structure Spring Boot applications into well-defined modules with clear boundaries
|link:data-mongodb-tc-data-load[Spring Test: Load data with Testcontainers] |Load test data with Testcontainers instead of `BeforeEach`
|link:test-execution-listeners[Spring Test: Test Execution Listeners] |Implement custom `TestExecutionListener` to manage data in tests
|link:test-rest-assured[Spring Test: Integration with RestAssured] | Implement Behaviour Driven Development with https://rest-assured.io/[RestAssured]
|link:test-slice-tests-rest[Spring Test: Implementing Slice Tests for REST application] | Dive into available options to implement tests with Spring Boot's test components
|link:web-rest-client[Spring Web: REST Clients for calling Synchronous API] | Implement REST client to perform synchronous API calls
|link:web-thymeleaf-xss[Spring Web: Preventing XSS with Thymeleaf] |Prevent Cross-Site Scripting (XSS) attacks in Spring Boot applications using Spring Security and Thymeleaf
Expand Down
4 changes: 2 additions & 2 deletions batch-rest-repository/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class UserJobConfiguration {
private JsonItemReader<User> reader() throws MalformedURLException {
JacksonJsonObjectReader<User> jsonObjectReader = new JacksonJsonObjectReader<>(User.class);

jsonObjectReader.setMapper(new ObjectMapper());
jsonObjectReader.setMapper(new JsonMapper());

return new JsonItemReaderBuilder<User>()
.name("userReader")
Expand Down Expand Up @@ -80,7 +80,7 @@ class UserJobConfiguration {
private JsonItemReader<User> reader() throws MalformedURLException {
JacksonJsonObjectReader<User> jsonObjectReader = new JacksonJsonObjectReader<>(User.class);

jsonObjectReader.setMapper(new ObjectMapper());
jsonObjectReader.setMapper(new JsonMapper());

return new JsonItemReaderBuilder<User>()
.name("userReader")
Expand Down
10 changes: 5 additions & 5 deletions batch-rest-repository/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
java
id("org.springframework.boot") version "3.5.7"
id("org.springframework.boot") version "4.0.2"
id("io.spring.dependency-management") version "1.1.7"
}

Expand All @@ -20,14 +20,14 @@ repositories {
dependencies {
implementation("org.springframework.boot:spring-boot-starter-batch")
implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
implementation("com.fasterxml.jackson.core:jackson-databind")
implementation("tools.jackson.core:jackson-databind")
runtimeOnly("com.mysql:mysql-connector-j")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.boot:spring-boot-testcontainers")
testImplementation("org.springframework.batch:spring-batch-test")
testImplementation("org.testcontainers:junit-jupiter")
testImplementation("org.testcontainers:mongodb")
testImplementation("org.testcontainers:mysql")
testImplementation("org.testcontainers:testcontainers-junit-jupiter")
testImplementation("org.testcontainers:testcontainers-mongodb")
testImplementation("org.testcontainers:testcontainers-mysql")
}

tasks.named<Test>("test") {
Expand Down
6 changes: 5 additions & 1 deletion batch-rest-repository/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
rootProject.name = "batch-rest-repository"
rootProject.name = "batch-rest-repository"

dependencies {
runtimeOnly("com.fasterxml.jackson.core:jackson-annotations:2.21")
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
package zin.rashidi.boot.batch.rest.user;

import java.net.MalformedURLException;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.job.Job;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.Step;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.item.data.MongoItemWriter;
import org.springframework.batch.item.data.builder.MongoItemWriterBuilder;
import org.springframework.batch.item.json.JacksonJsonObjectReader;
import org.springframework.batch.item.json.JsonItemReader;
import org.springframework.batch.item.json.builder.JsonItemReaderBuilder;
import org.springframework.batch.infrastructure.item.data.MongoItemWriter;
import org.springframework.batch.infrastructure.item.data.builder.MongoItemWriterBuilder;
import org.springframework.batch.infrastructure.item.json.JacksonJsonObjectReader;
import org.springframework.batch.infrastructure.item.json.JsonItemReader;
import org.springframework.batch.infrastructure.item.json.builder.JsonItemReaderBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.UrlResource;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.transaction.PlatformTransactionManager;
import tools.jackson.databind.json.JsonMapper;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.MalformedURLException;

/**
* @author Rashidi Zin
*/
@Configuration
class UserJobConfiguration {

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private static final JsonMapper OBJECT_MAPPER = new JsonMapper();

private final JobRepository jobRepository;
private final PlatformTransactionManager transactionManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration;
import org.springframework.batch.core.job.JobExecution;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.batch.test.context.SpringBatchTest;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -17,10 +18,10 @@
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.jdbc.support.JdbcTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.testcontainers.containers.MongoDBContainer;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.mongodb.MongoDBContainer;
import org.testcontainers.mysql.MySQLContainer;

import javax.sql.DataSource;

Expand All @@ -42,7 +43,7 @@ class UserBatchJobTests {

@Container
@ServiceConnection
private final static MySQLContainer<?> MYSQL_CONTAINER = new MySQLContainer<>("mysql:lts")
private final static MySQLContainer MYSQL_CONTAINER = new MySQLContainer("mysql:lts")
.withInitScript("org/springframework/batch/core/schema-mysql.sql");

@Container
Expand Down
9 changes: 5 additions & 4 deletions batch-skip-step/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
java
id("org.springframework.boot") version "3.5.7"
id("org.springframework.boot") version "4.0.2"
id("io.spring.dependency-management") version "1.1.7"
}

Expand All @@ -20,13 +20,14 @@ repositories {
dependencies {
implementation("org.springframework.boot:spring-boot-starter-batch")
implementation("org.springframework.boot:spring-boot-starter-data-jdbc")
implementation("com.fasterxml.jackson.core:jackson-databind")
implementation("org.springframework.boot:spring-boot-starter-jackson")
runtimeOnly("com.mysql:mysql-connector-j")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.boot:spring-boot-starter-jackson-test")
testImplementation("org.springframework.boot:spring-boot-testcontainers")
testImplementation("org.springframework.batch:spring-batch-test")
testImplementation("org.testcontainers:junit-jupiter")
testImplementation("org.testcontainers:mysql")
testImplementation("org.testcontainers:testcontainers-junit-jupiter")
testImplementation("org.testcontainers:testcontainers-mysql")
}

tasks.named<Test>("test") {
Expand Down
6 changes: 5 additions & 1 deletion batch-skip-step/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
rootProject.name = "batch-skip-step"
rootProject.name = "batch-skip-step"

dependencies {
runtimeOnly("com.fasterxml.jackson.core:jackson-annotations:2.21")
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package zin.rashidi.boot.batch.user;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.job.Job;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.Step;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.database.JdbcBatchItemWriter;
import org.springframework.batch.item.database.builder.JdbcBatchItemWriterBuilder;
import org.springframework.batch.item.json.JacksonJsonObjectReader;
import org.springframework.batch.item.json.JsonItemReader;
import org.springframework.batch.item.json.builder.JsonItemReaderBuilder;
import org.springframework.batch.infrastructure.item.ItemProcessor;
import org.springframework.batch.infrastructure.item.database.JdbcBatchItemWriter;
import org.springframework.batch.infrastructure.item.database.builder.JdbcBatchItemWriterBuilder;
import org.springframework.batch.infrastructure.item.json.JacksonJsonObjectReader;
import org.springframework.batch.infrastructure.item.json.JsonItemReader;
import org.springframework.batch.infrastructure.item.json.builder.JsonItemReaderBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
Expand All @@ -25,13 +24,9 @@
@Configuration
class UserJobConfiguration {

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

private JsonItemReader<UserFile> reader() {
JacksonJsonObjectReader<UserFile> reader = new JacksonJsonObjectReader<>(UserFile.class);

reader.setMapper(OBJECT_MAPPER);

return new JsonItemReaderBuilder<UserFile>()
.jsonObjectReader(reader)
.name("userReader")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration;
import org.springframework.batch.core.job.JobExecution;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.batch.test.context.SpringBatchTest;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -16,9 +17,9 @@
import org.springframework.jdbc.support.JdbcTransactionManager;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.transaction.PlatformTransactionManager;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.mysql.MySQLContainer;

import javax.sql.DataSource;

Expand Down Expand Up @@ -51,7 +52,7 @@ class UserBatchJobTests {

@Container
@ServiceConnection
private final static MySQLContainer<?> MYSQL_CONTAINER = new MySQLContainer<>("mysql:lts");
private final static MySQLContainer MYSQL_CONTAINER = new MySQLContainer("mysql:lts");

@Autowired
private JobLauncherTestUtils launcher;
Expand All @@ -68,7 +69,7 @@ void findAll() {
assertThat(execution.getExitStatus()).isEqualTo(COMPLETED);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Changing the lambda parameter from _ to i is a good practice for clarity, even if the parameter is not directly used within the lambda body. It improves readability by explicitly naming the parameter, which can be helpful for future maintainers understanding the lambda's signature.

        var users = jdbc.query("SELECT * FROM users", (rs, i) ->

var users = jdbc.query("SELECT * FROM users", (rs, _) ->
var users = jdbc.query("SELECT * FROM users", (rs, i) ->
new User(rs.getLong("id"), rs.getString("name"), rs.getString("username"))
);

Expand Down Expand Up @@ -113,7 +114,6 @@ void truncateUsers() {
@TestConfiguration
static class BatchTestConfiguration extends DefaultBatchConfiguration {

@Override
@Bean
protected DataSource getDataSource() {
return DataSourceBuilder.create()
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.springframework.boot.gradle.plugin.SpringBootPlugin

plugins {
java
id("org.springframework.boot") version "3.5.7" apply false
id("org.springframework.boot") version "4.0.2" apply false
id("io.spring.dependency-management") version "1.1.7"
id("org.sonarqube") version "7.2.2.6593"
id("jacoco-report-aggregation")
Expand Down
9 changes: 5 additions & 4 deletions cloud-jdbc-env-repo/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
plugins {
java
id("org.springframework.boot") version "3.5.7"
id("org.springframework.boot") version "4.0.2"
id("io.spring.dependency-management") version "1.1.7"
}

group = "zin.rashidi.boot"
version = "0.0.1-SNAPSHOT"

val springCloudVersion = "2025.0.0"
val springCloudVersion = "2025.0.1"

java {
toolchain {
Expand All @@ -28,15 +28,16 @@ repositories {
dependencies {
implementation(platform("org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"))

implementation("org.springframework.boot:spring-boot-resttestclient:4.0.2")
implementation("org.springframework.boot:spring-boot-starter-data-jdbc")
implementation("org.springframework.cloud:spring-cloud-starter-bootstrap")
implementation("org.springframework.cloud:spring-cloud-config-server")
runtimeOnly("com.mysql:mysql-connector-j")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.boot:spring-boot-testcontainers")
testImplementation("org.testcontainers:junit-jupiter")
testImplementation("org.testcontainers:mysql")
testImplementation("org.testcontainers:testcontainers-junit-jupiter")
testImplementation("org.testcontainers:testcontainers-mysql")
}

tasks.named<Test>("test") {
Expand Down
6 changes: 5 additions & 1 deletion cloud-jdbc-env-repo/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
rootProject.name = "cloud-jdbc-env-repo"
rootProject.name = "cloud-jdbc-env-repo"

dependencies {
runtimeOnly("org.springframework:spring-context:7.0.3")
}
12 changes: 9 additions & 3 deletions cloud-jdbc-env-repo/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
app:
greet:
name: Default
app.greet.name: Default
spring:
application.name: demo
cloud.config.server:
bootstrap: true
jdbc:
sql: SELECT `KEY`, `VALUE` from PROPERTIES where APPLICATION=? and PROFILE=? and LABEL=?
sql-without-profile: SELECT `KEY`, `VALUE` from PROPERTIES where APPLICATION=? and PROFILE='default' and LABEL=?
profiles.active: jdbc
Comment on lines +1 to +9
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The migration of configuration from bootstrap.yml to application.yml and the change in YAML structure from nested to flat for app.greet.name is a significant refactoring. While bootstrap.yml is deprecated in newer Spring Boot versions, ensuring all configurations are correctly translated and behave as expected is crucial. The flat property app.greet.name is a more concise way to define simple properties.

13 changes: 0 additions & 13 deletions cloud-jdbc-env-repo/src/main/resources/bootstrap.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.testcontainers.containers.MySQLContainer;
import org.springframework.boot.resttestclient.TestRestTemplate;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.mysql.MySQLContainer;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

@AutoConfigureTestRestTemplate
@Testcontainers
@SpringBootTest(properties = "spring.datasource.url=jdbc:tc:mysql:lts:///test?TC_INITSCRIPT=init-script.sql", webEnvironment = RANDOM_PORT)
class CloudJdbcEnvRepoApplicationTests {

@Container
private static final MySQLContainer<?> MYSQL = new MySQLContainer<>("mysql:lts");
private static final MySQLContainer MYSQL = new MySQLContainer("mysql:lts");

@Autowired
private TestRestTemplate restClient;
Expand Down
9 changes: 5 additions & 4 deletions data-domain-events/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
java
id("org.springframework.boot") version "3.5.7"
id("org.springframework.boot") version "4.0.2"
id("io.spring.dependency-management") version "1.1.7"
}

Expand All @@ -18,13 +18,14 @@ repositories {
}

dependencies {
implementation("org.springframework.boot:spring-boot-resttestclient:4.0.2")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-webmvc")
runtimeOnly("com.mysql:mysql-connector-j")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.boot:spring-boot-testcontainers")
testImplementation("org.testcontainers:junit-jupiter")
testImplementation("org.testcontainers:mysql")
testImplementation("org.testcontainers:testcontainers-junit-jupiter")
testImplementation("org.testcontainers:testcontainers-mysql")
}

tasks.named<Test>("test") {
Expand Down
6 changes: 5 additions & 1 deletion data-domain-events/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
rootProject.name = "data-domain-events"
rootProject.name = "data-domain-events"

dependencies {
runtimeOnly("org.springframework:spring-context:7.0.3")
}
Loading
Loading