File tree Expand file tree Collapse file tree 8 files changed +113
-15
lines changed
test/kotlin/com/expedia/authentication Expand file tree Collapse file tree 8 files changed +113
-15
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,8 @@ repositories {
1919dependencies {
2020 implementation(" org.springframework.boot:spring-boot-starter-web:2.6.6" )
2121 implementation(" org.springframework.boot:spring-boot-starter-actuator:2.6.6" )
22- implementation(" org.springframework.boot:spring-boot-starter-data-jdbc:2.6.6" )
22+ implementation(" org.springframework.boot:spring-boot-starter-webflux:2.6.6" )
23+ implementation(" org.springframework.boot:spring-boot-starter-data-jpa:2.6.6" )
2324 implementation(" org.springframework.boot:spring-boot-starter-security:2.6.6" )
2425 implementation(" org.springframework.boot:spring-boot-starter-validation:2.6.6" )
2526 implementation(" com.fasterxml.jackson.module:jackson-module-kotlin:2.13.2" )
@@ -30,9 +31,11 @@ dependencies {
3031 implementation(" io.jsonwebtoken:jjwt-jackson:0.11.2" )
3132 implementation(" io.jsonwebtoken:jjwt-api:0.11.2" )
3233 implementation(" net.rakugakibox.spring.boot:logback-access-spring-boot-starter:2.7.1" )
34+ implementation(" com.google.guava:guava:31.1-jre" )
3335 annotationProcessor(" org.springframework.boot:spring-boot-configuration-processor:2.6.6" )
3436 developmentOnly(" org.springframework.boot:spring-boot-devtools:2.6.6" )
3537 runtimeOnly(" mysql:mysql-connector-java:8.0.28" )
38+ runtimeOnly(" com.h2database:h2" )
3639
3740 // Spring Rest Docs
3841 testImplementation(" org.springframework.restdocs:spring-restdocs-restassured:2.0.6.RELEASE" )
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ spring :
2+ jpa :
3+ properties :
4+ hibernate :
5+ show_sql : true
6+ format_sql : true
7+
8+ security :
9+ jwt :
10+ token :
11+ secret-key : expedia-secret-key
12+ expire-length : 3600000
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ package com.expedia.authentication.acceptance
2+
3+ import com.expedia.authentication.support.DatabaseCleanup
4+ import io.restassured.RestAssured
5+ import org.junit.jupiter.api.BeforeEach
6+ import org.springframework.beans.factory.annotation.Autowired
7+ import org.springframework.boot.test.context.SpringBootTest
8+ import org.springframework.boot.web.server.LocalServerPort
9+
10+ @SpringBootTest(webEnvironment = SpringBootTest .WebEnvironment .RANDOM_PORT )
11+ class AcceptanceTest {
12+
13+ @Autowired lateinit var databaseCleanup: DatabaseCleanup
14+
15+ @LocalServerPort
16+ lateinit var port: String
17+
18+ @BeforeEach
19+ fun setUp () {
20+ RestAssured .port = port.toInt()
21+ databaseCleanup.execute()
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ package com.expedia.authentication.acceptance.user
2+
3+ import com.expedia.authentication.acceptance.AcceptanceTest
4+ import org.junit.jupiter.api.Test
5+
6+ internal class UserAcceptanceTest : AcceptanceTest () {
7+
8+ @Test
9+ fun `회원 가입을 한다` () {
10+ val response
= `회원 생성 요청`(
" [email protected] " ,
" jungho" )
11+ `회원이 생성 됨`(response)
12+ }
13+ }
Original file line number Diff line number Diff line change 1+ package com.expedia.authentication.acceptance.user
2+
3+ import io.restassured.RestAssured
4+ import io.restassured.response.ExtractableResponse
5+ import io.restassured.response.Response
6+ import org.assertj.core.api.Assertions.assertThat
7+ import org.springframework.http.HttpStatus
8+ import org.springframework.http.MediaType
9+
10+
11+ internal fun `회원 생성 요청` (email : String , password : String ): ExtractableResponse <Response > {
12+ val params: MutableMap <String , String > = HashMap ()
13+ params[" email" ] = email
14+ params[" password" ] = password
15+
16+ return RestAssured
17+ .given().log().all()
18+ .contentType(MediaType .APPLICATION_JSON_VALUE )
19+ .body(params)
20+ .`when `().post(" /users" )
21+ .then().log().all().extract()
22+ }
23+
24+ internal fun `회원이 생성 됨` (response : ExtractableResponse <Response >) =
25+ assertThat(response.statusCode()).isEqualTo(HttpStatus .CREATED .value())
Original file line number Diff line number Diff line change 1+ package com.expedia.authentication.support
2+
3+ import com.google.common.base.CaseFormat
4+ import org.springframework.stereotype.Service
5+ import javax.annotation.PostConstruct
6+ import javax.persistence.Entity
7+ import javax.persistence.EntityManager
8+ import javax.persistence.PersistenceContext
9+ import javax.transaction.Transactional
10+
11+ @Service
12+ class DatabaseCleanup (
13+ @PersistenceContext val entityManager : EntityManager
14+ ) {
15+
16+ private var tableNames: List <String >? = null
17+
18+ @PostConstruct
19+ fun afterPropertiesSet () {
20+ tableNames = entityManager.metamodel.entities.asSequence()
21+ .filter { e -> e.javaType.getAnnotation(Entity ::class .java) != null }
22+ .map { e -> CaseFormat .UPPER_CAMEL .to(CaseFormat .LOWER_UNDERSCORE , e.name) }
23+ .toList()
24+ }
25+
26+ @Transactional
27+ fun execute () {
28+ entityManager.flush()
29+ entityManager.createNativeQuery(" SET REFERENTIAL_INTEGRITY FALSE" ).executeUpdate()
30+ for (tableName in tableNames!! ) {
31+ entityManager.createNativeQuery(" TRUNCATE TABLE $tableName " ).executeUpdate()
32+ entityManager.createNativeQuery(" ALTER TABLE $tableName ALTER COLUMN ID RESTART WITH 1" ).executeUpdate()
33+ }
34+ entityManager.createNativeQuery(" SET REFERENTIAL_INTEGRITY TRUE" ).executeUpdate()
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments