From 3133ea99927219ba3e210cb8777968dffa625ab6 Mon Sep 17 00:00:00 2001 From: gahee99 Date: Mon, 11 Mar 2024 09:55:11 +0900 Subject: [PATCH] feat: test environment --- build.gradle | 10 ++++-- src/main/resources/application.yml | 8 ++++- .../java/com/gam/api/ApiApplicationTests.java | 2 ++ .../controller/HealthCheckControllerTest.java | 32 +++++++++++++++++++ 4 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 src/test/java/com/gam/api/controller/HealthCheckControllerTest.java diff --git a/build.gradle b/build.gradle index 3378ed41..786ce1c5 100644 --- a/build.gradle +++ b/build.gradle @@ -31,6 +31,7 @@ dependencies { implementation('software.amazon.awssdk:s3:2.17.285') + //jwt implementation 'io.jsonwebtoken:jjwt-api:0.11.2' runtimeOnly "io.jsonwebtoken:jjwt-impl:0.11.2" runtimeOnly "io.jsonwebtoken:jjwt-jackson:0.11.2" @@ -39,15 +40,20 @@ dependencies { compileOnly 'org.projectlombok:lombok' runtimeOnly 'org.postgresql:postgresql' annotationProcessor 'org.projectlombok:lombok' - testImplementation 'org.springframework.boot:spring-boot-starter-test' - testImplementation 'org.springframework.security:spring-security-test' implementation 'io.hypersistence:hypersistence-utils-hibernate-5:3.5.0' implementation 'org.springframework.boot:spring-boot-starter-data-redis' + //swagger implementation 'io.springfox:springfox-boot-starter:3.0.0' implementation 'io.springfox:springfox-swagger-ui:3.0.0' + + //test + runtimeOnly('com.h2database:h2') + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.springframework.security:spring-security-test' + } tasks.named('test') { diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 1bf7299a..6fb63238 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -6,4 +6,10 @@ spring: spring: profiles: - active: dev \ No newline at end of file + active: dev + +--- + +spring: + profiles: + active: test \ No newline at end of file diff --git a/src/test/java/com/gam/api/ApiApplicationTests.java b/src/test/java/com/gam/api/ApiApplicationTests.java index 8f69c63b..0cfabc57 100644 --- a/src/test/java/com/gam/api/ApiApplicationTests.java +++ b/src/test/java/com/gam/api/ApiApplicationTests.java @@ -2,8 +2,10 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; @SpringBootTest +@ActiveProfiles("test") class ApiApplicationTests { @Test diff --git a/src/test/java/com/gam/api/controller/HealthCheckControllerTest.java b/src/test/java/com/gam/api/controller/HealthCheckControllerTest.java new file mode 100644 index 00000000..e57c6fe3 --- /dev/null +++ b/src/test/java/com/gam/api/controller/HealthCheckControllerTest.java @@ -0,0 +1,32 @@ +package com.gam.api.controller; + +import com.gam.api.config.WebMvcConfig; +import com.gam.api.config.json.CustomObjectMapper; +import com.gam.api.domain.test.controller.TestController; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.test.web.servlet.MockMvc; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@AutoConfigureMockMvc +@WebMvcTest(controllers = TestController.class) +public class HealthCheckControllerTest { + @Autowired + private MockMvc mvc; + + @Test + public void healthCheckReturn() throws Exception { + String WELCOME_STRING = "Hello gam Server!"; + + mvc.perform(get("/health")) + .andExpect(status().isOk()) + .andExpect(content().string(WELCOME_STRING)); + } +}