-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- kotest 연동 - cucumber 연동
- Loading branch information
Showing
10 changed files
with
210 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.john.lotto | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication | ||
import org.springframework.boot.runApplication | ||
|
||
@SpringBootApplication | ||
class ApiApplicationTests { | ||
fun main(args: Array<String>) { | ||
runApplication<ApiApplicationTests>(*args) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
api/src/test/kotlin/com/john/lotto/cucumber/feature/RunCucumberTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.john.lotto.cucumber.feature | ||
|
||
import io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME | ||
import io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME | ||
import org.junit.platform.suite.api.ConfigurationParameter | ||
import org.junit.platform.suite.api.IncludeEngines | ||
import org.junit.platform.suite.api.SelectClasspathResource | ||
import org.junit.platform.suite.api.Suite | ||
|
||
/** | ||
* @author yoonho | ||
* @since 2023.06.23 | ||
*/ | ||
@Suite | ||
@IncludeEngines("cucumber") | ||
@SelectClasspathResource("cucumber/feature") | ||
@ConfigurationParameter( | ||
key = GLUE_PROPERTY_NAME, | ||
value = "cucumber.feature" | ||
) | ||
@ConfigurationParameter( | ||
key = PLUGIN_PROPERTY_NAME, | ||
value = "pretty" | ||
) | ||
class RunCucumberTest { | ||
} |
20 changes: 20 additions & 0 deletions
20
api/src/test/kotlin/com/john/lotto/cucumber/feature/SpringIntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.john.lotto.cucumber.feature | ||
|
||
import com.john.lotto.ApiApplicationTests | ||
import io.cucumber.spring.CucumberContextConfiguration | ||
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.test.context.ActiveProfiles | ||
|
||
/** | ||
* @author yoonho | ||
* @since 2023.06.23 | ||
*/ | ||
@SpringBootTest(classes = [ApiApplicationTests::class]) | ||
@CucumberContextConfiguration | ||
@AutoConfigureMockMvc | ||
@AutoConfigureWebTestClient | ||
@ActiveProfiles("api-test") | ||
class SpringIntegrationTest { | ||
} |
69 changes: 69 additions & 0 deletions
69
api/src/test/kotlin/com/john/lotto/cucumber/feature/step/number/NumberStep.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.john.lotto.cucumber.feature.step.number | ||
|
||
import com.john.lotto.common.handler.WebFluxExceptionHandler | ||
import com.john.lotto.number.adapter.`in`.web.NumberRouter | ||
import io.cucumber.java.Before | ||
import io.cucumber.java.ko.그러면 | ||
import io.cucumber.java.ko.만약 | ||
import io.cucumber.java.ko.먼저 | ||
import io.kotest.assertions.print.print | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.http.HttpMethod | ||
import org.springframework.http.MediaType | ||
import org.springframework.test.web.reactive.server.WebTestClient | ||
import org.springframework.web.reactive.function.server.HandlerStrategies | ||
import org.springframework.web.util.UriComponentsBuilder | ||
|
||
/** | ||
* @author yoonho | ||
* @since 2023.06.23 | ||
*/ | ||
class NumberStep { | ||
private val log = LoggerFactory.getLogger(this::class.java) | ||
|
||
@Autowired | ||
private lateinit var router: NumberRouter | ||
|
||
private lateinit var webTestClient: WebTestClient | ||
private lateinit var result: WebTestClient.ResponseSpec | ||
|
||
private var drwtNo: Int = 0 | ||
|
||
@Before(value = "@number") | ||
fun init() { | ||
webTestClient = WebTestClient.bindToRouterFunction(router.numberRouterFunction()) | ||
.handlerStrategies( | ||
HandlerStrategies.builder() | ||
.exceptionHandler(WebFluxExceptionHandler()) | ||
.build() | ||
) | ||
.build() | ||
} | ||
|
||
@먼저("로또번호조회API 호출을 위한 {int} 있다") | ||
fun 로또번호조회API_호출을_위한_있다(drwtNo: Int) { | ||
this.drwtNo = drwtNo | ||
} | ||
|
||
@만약("로또번호조회API {string} 요청하면") | ||
fun 로또번호조회API_요청하면(url: String) { | ||
val uriComponents = UriComponentsBuilder | ||
.fromUriString(url) | ||
.queryParam("drwtNo", drwtNo) | ||
.build(false) | ||
|
||
result = webTestClient | ||
.method(HttpMethod.GET) | ||
.uri(uriComponents.toUriString()) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.exchange() | ||
} | ||
|
||
@그러면("로또번호조회API 호출결과 {int} 확인한다") | ||
fun 로또번호조회API_호출결과_확인한다(statusCode: Int) { | ||
result | ||
.expectStatus().isEqualTo(statusCode) | ||
.print() | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
api/src/test/kotlin/com/john/lotto/number/application/NumberServiceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.john.lotto.number.application | ||
|
||
import com.john.lotto.ApiApplicationTests | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.kotest.matchers.shouldNotBe | ||
import org.junit.jupiter.api.Assertions.* | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.test.context.ActiveProfiles | ||
|
||
@SpringBootTest(classes = [ApiApplicationTests::class]) | ||
@ActiveProfiles("api-test") | ||
class NumberServiceTest( | ||
private val numberService: NumberService | ||
): BehaviorSpec({ | ||
val log = LoggerFactory.getLogger(this::class.java) | ||
|
||
Given("먼저, 특정 로또번호 조회를 위한 파라미터가 세팅되어 있다.") { | ||
val drwtNo = 1072L | ||
|
||
When("만약, 특정 로또번호 조회를 요청하면") { | ||
val result = numberService.findLottoNumber(drwtNo = drwtNo).block() | ||
|
||
Then("그러면, 특정 로또번호 조회 결과를 확인한다.") { | ||
log.info(" >>> [findLottoNumber] result: $result") | ||
result shouldNotBe null | ||
} | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
spring: | ||
config: | ||
activate: | ||
on-profile: api-test | ||
jpa: | ||
show-sql: true | ||
hibernate: | ||
ddl-auto: create-drop | ||
generate-ddl: true | ||
datasource: | ||
hikari: | ||
connection-timeout: 5000 | ||
minimum-idle: 10 | ||
maximum-pool-size: 100 | ||
|
||
hibernate: | ||
show_sql: false | ||
format_sql: false | ||
physical_naming_strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl | ||
|
||
vault: | ||
uri: http://localhost:8200 | ||
token: admin | ||
app-role: | ||
role-id: | ||
secret-id: | ||
secret: | ||
appconfig: oauth2-app/local |
14 changes: 14 additions & 0 deletions
14
api/src/test/resources/cucumber/feature/number/로또번호조회_API를_호출하다.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# language: ko | ||
기능: 로또번호 조회 API 통합테스트 | ||
모든 사용자는 로또번호 조회 API를 호출할 수 있다. | ||
|
||
@number | ||
시나리오 개요: 로또번호조회 API를 호출한다. | ||
먼저 로또번호조회API 호출을 위한 <drwtNo> 있다 | ||
만약 로또번호조회API "<url>" 요청하면 | ||
그러면 로또번호조회API 호출결과 <statusCode> 확인한다 | ||
|
||
예: | ||
| drwtNo | url | statusCode | | ||
| 1072 | /api/number | 200 | | ||
| 9999 | /api/number | 400 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters