Skip to content
Draft
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
17 changes: 14 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ apply from: 'lint.gradle'
allprojects {
group = "${projectGroup}"
version = "${applicationVersion}"
sourceCompatibility = project.javaVersion

repositories {
mavenCentral()
Expand All @@ -31,7 +30,19 @@ subprojects {
}

dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
testImplementation 'org.springframework.boot:spring-boot-test'
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.mockito:mockito-core'
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(project.javaVersion)
}
}

bootJar.enabled = false
Expand Down Expand Up @@ -71,7 +82,7 @@ subprojects {
}
}

tasks.named('asciidoctor') {
tasks.named('asciidoctor').configure {
dependsOn restDocsTest
}
}
2 changes: 1 addition & 1 deletion core/core-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ dependencies {

testImplementation project(":tests:api-docs")

implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webmvc'
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.dodn.springboot.core.api.controller.v1;

import io.dodn.springboot.core.api.controller.v1.request.ExampleRequestDto;
import io.dodn.springboot.core.api.controller.v1.response.ExampleItemResponseDto;
import io.dodn.springboot.core.api.controller.v1.response.ExampleResponseDto;
import io.dodn.springboot.core.domain.ExampleData;
import io.dodn.springboot.core.domain.ExampleResult;
Expand All @@ -14,6 +15,9 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;

@RestController
public class ExampleController {

Expand All @@ -27,13 +31,15 @@ public ExampleController(ExampleService exampleExampleService) {
public ApiResponse<ExampleResponseDto> exampleGet(@PathVariable String exampleValue,
@RequestParam String exampleParam) {
ExampleResult result = exampleExampleService.processExample(new ExampleData(exampleValue, exampleParam));
return ApiResponse.success(new ExampleResponseDto(result.data()));
return ApiResponse.success(new ExampleResponseDto(result.data(), LocalDate.now(), LocalDateTime.now(),
ExampleItemResponseDto.build()));
}

@PostMapping("/post")
public ApiResponse<ExampleResponseDto> examplePost(@RequestBody ExampleRequestDto request) {
ExampleResult result = exampleExampleService.processExample(request.toExampleData());
return ApiResponse.success(new ExampleResponseDto(result.data()));
return ApiResponse.success(new ExampleResponseDto(result.data(), LocalDate.now(), LocalDateTime.now(),
ExampleItemResponseDto.build()));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.dodn.springboot.core.api.controller.v1.response;

import java.util.List;

public record ExampleItemResponseDto(String key) {
public static List<ExampleItemResponseDto> build() {
return List.of(new ExampleItemResponseDto("1"), new ExampleItemResponseDto("2"));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
package io.dodn.springboot.core.api.controller.v1.response;

public record ExampleResponseDto(String result) {
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

public record ExampleResponseDto(String result, LocalDate date, LocalDateTime datetime,
List<ExampleItemResponseDto> items) {
}
Original file line number Diff line number Diff line change
@@ -1,74 +1,79 @@
package io.dodn.springboot.core.api.controller.v1;

import static io.dodn.springboot.test.api.RestDocsUtils.requestPreprocessor;
import static io.dodn.springboot.test.api.RestDocsUtils.responsePreprocessor;
import io.dodn.springboot.core.api.controller.v1.request.ExampleRequestDto;
import io.dodn.springboot.core.domain.ExampleResult;
import io.dodn.springboot.core.domain.ExampleService;
import io.dodn.springboot.test.api.RestDocsTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.restdocs.operation.preprocess.Preprocessors;
import org.springframework.restdocs.payload.JsonFieldType;
import tools.jackson.databind.json.JsonMapper;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
import static org.springframework.restdocs.request.RequestDocumentation.queryParameters;

import io.dodn.springboot.core.api.controller.v1.request.ExampleRequestDto;
import io.dodn.springboot.core.domain.ExampleResult;
import io.dodn.springboot.core.domain.ExampleService;
import io.dodn.springboot.test.api.RestDocsTest;
import io.restassured.http.ContentType;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
import org.springframework.restdocs.payload.JsonFieldType;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class ExampleControllerTest extends RestDocsTest {

private ExampleService exampleService;

private ExampleController controller;

@BeforeEach
public void setUp() {
exampleService = mock(ExampleService.class);
controller = new ExampleController(exampleService);
mockMvc = mockController(controller);
mockMvc = mockController(new ExampleController(exampleService));
}

@Test
public void exampleGet() {
public void exampleGet() throws Exception {
when(exampleService.processExample(any())).thenReturn(new ExampleResult("BYE"));

given().contentType(ContentType.JSON)
.queryParam("exampleParam", "HELLO_PARAM")
.get("/get/{exampleValue}", "HELLO_PATH")
.then()
.status(HttpStatus.OK)
.apply(document("exampleGet", requestPreprocessor(), responsePreprocessor(),
mockMvc
.perform(get("/get/{exampleValue}", "HELLO_PATH").param("exampleParam", "HELLO_PARAM")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(document("exampleGet", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
Preprocessors.preprocessResponse(Preprocessors.prettyPrint()),
pathParameters(parameterWithName("exampleValue").description("ExampleValue")),
queryParameters(parameterWithName("exampleParam").description("ExampleParam")),
responseFields(fieldWithPath("result").type(JsonFieldType.STRING).description("ResultType"),
fieldWithPath("data.result").type(JsonFieldType.STRING).description("Result Date"),
fieldWithPath("data.result").type(JsonFieldType.STRING).description("Result Data"),
fieldWithPath("data.date").type(JsonFieldType.STRING).description("Result Date"),
fieldWithPath("data.datetime").type(JsonFieldType.STRING).description("Result Datetime"),
fieldWithPath("data.items").type(JsonFieldType.ARRAY).description("Result Items"),
fieldWithPath("data.items[].key").type(JsonFieldType.STRING).description("Result Item"),
fieldWithPath("error").type(JsonFieldType.NULL).ignored())));
}

@Test
public void examplePost() {
public void examplePost() throws Exception {
when(exampleService.processExample(any())).thenReturn(new ExampleResult("BYE"));

given().contentType(ContentType.JSON)
.body(new ExampleRequestDto("HELLO_BODY"))
.post("/post")
.then()
.status(HttpStatus.OK)
.apply(document("examplePost", requestPreprocessor(), responsePreprocessor(),
mockMvc
.perform(post("/post").contentType(MediaType.APPLICATION_JSON)
.content(JsonMapper.builder().build().writeValueAsString(new ExampleRequestDto("HELLO_BODY"))))
.andExpect(status().isOk())
.andDo(document("examplePost", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
Preprocessors.preprocessResponse(Preprocessors.prettyPrint()),
requestFields(
fieldWithPath("data").type(JsonFieldType.STRING).description("ExampleBody Data Field")),
responseFields(fieldWithPath("result").type(JsonFieldType.STRING).description("ResultType"),
fieldWithPath("data.result").type(JsonFieldType.STRING).description("Result Date"),
fieldWithPath("data.result").type(JsonFieldType.STRING).description("Result Data"),
fieldWithPath("data.date").type(JsonFieldType.STRING).description("Result Date"),
fieldWithPath("data.datetime").type(JsonFieldType.STRING).description("Result Datetime"),
fieldWithPath("data.items").type(JsonFieldType.ARRAY).description("Result Items"),
fieldWithPath("data.items[].key").type(JsonFieldType.STRING).description("Result Item"),
fieldWithPath("error").type(JsonFieldType.STRING).ignored())));
}

Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ applicationVersion=0.0.1-SNAPSHOT

### Project configs ###
projectGroup=io.dodn.springboot
javaVersion=21
javaVersion=25

### Plugin dependency versions ###
asciidoctorConvertVersion=3.3.2
asciidoctorConvertVersion=4.0.5
springJavaFormatVersion=0.0.47

### Spring dependency versions ###
springBootVersion=3.5.3
springBootVersion=4.0.0
springDependencyManagementVersion=1.1.7
springCloudDependenciesVersion=2025.0.0
springCloudDependenciesVersion=2025.1.0

### External dependency versions ###
sentryVersion=8.17.0
sentryVersion=8.27.1
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
9 changes: 4 additions & 5 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -115,7 +114,7 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
CLASSPATH="\\\"\\\""


# Determine the Java command to use to start the JVM.
Expand Down Expand Up @@ -206,15 +205,15 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"

# Stop when "xargs" is not available.
Expand Down
4 changes: 2 additions & 2 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ goto fail
:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
set CLASSPATH=


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.dodn.springboot.storage.db.core.config;

import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.persistence.autoconfigure.EntityScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;
Expand Down
2 changes: 1 addition & 1 deletion support/logging/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dependencies {
implementation 'io.micrometer:micrometer-tracing-bridge-brave'
implementation 'org.springframework.boot:spring-boot-starter-opentelemetry'
implementation "io.sentry:sentry-logback:${property("sentryVersion")}"
}
4 changes: 3 additions & 1 deletion support/logging/src/main/resources/logging.yml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
logging.config: classpath:logback/logback-${spring.profiles.active}.xml
logging.config: classpath:logback/logback-${spring.profiles.active}.xml

management.otlp.metrics.export.enabled: false
2 changes: 1 addition & 1 deletion support/monitoring/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'
runtimeOnly 'io.micrometer:micrometer-registry-prometheus'
}
7 changes: 2 additions & 5 deletions tests/api-docs/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
dependencies {
compileOnly 'jakarta.servlet:jakarta.servlet-api'
compileOnly 'org.springframework.boot:spring-boot-starter-test'
compileOnly 'com.fasterxml.jackson.core:jackson-databind'
api 'org.springframework.boot:spring-boot-restdocs'
api 'org.springframework.restdocs:spring-restdocs-mockmvc'
api 'org.springframework.restdocs:spring-restdocs-restassured'
api 'io.rest-assured:spring-mock-mvc'
compileOnly 'org.junit.jupiter:junit-jupiter-api'
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
package io.dodn.springboot.test.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

import io.restassured.module.mockmvc.RestAssuredMockMvc;
import io.restassured.module.mockmvc.specification.MockMvcRequestSpecification;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.restdocs.RestDocumentationContextProvider;
import org.springframework.restdocs.RestDocumentationExtension;
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
Expand All @@ -20,7 +13,7 @@
@ExtendWith(RestDocumentationExtension.class)
public abstract class RestDocsTest {

protected MockMvcRequestSpecification mockMvc;
protected MockMvc mockMvc;

private RestDocumentationContextProvider restDocumentation;

Expand All @@ -29,28 +22,10 @@ public void setUp(RestDocumentationContextProvider restDocumentation) {
this.restDocumentation = restDocumentation;
}

protected MockMvcRequestSpecification given() {
return mockMvc;
}

protected MockMvcRequestSpecification mockController(Object controller) {
MockMvc mockMvc = createMockMvc(controller);
return RestAssuredMockMvc.given().mockMvc(mockMvc);
}

private MockMvc createMockMvc(Object controller) {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(objectMapper());

protected MockMvc mockController(Object controller) {
return MockMvcBuilders.standaloneSetup(controller)
.apply(MockMvcRestDocumentation.documentationConfiguration(restDocumentation))
.setMessageConverters(converter)
.build();
}

private ObjectMapper objectMapper() {
return new ObjectMapper().findAndRegisterModules()
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.disable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS);
}

}
Loading
Loading