2018년 3월 9일 금요일

WireMock 사용법



import com.github.kittinunf.fuel.httpPost
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock.aResponse
import com.github.tomakehurst.wiremock.client.WireMock.configureFor
import com.github.tomakehurst.wiremock.client.WireMock.post
import com.github.tomakehurst.wiremock.client.WireMock.stubFor
import com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.springframework.http.HttpStatus

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
internal class WireMockTest {

    private lateinit var wireMock:WireMockServer

    @BeforeAll
    fun beforeAll(){
        wireMock = WireMockServer(7300)
        wireMock.start()
    }

    @AfterAll
    fun afterAll(){
        wireMock.stop()
    }

    @Test
    fun confirm() {
        //Given
        configureFor("localhost",7300)
        stubFor(post(urlEqualTo("/cp/payment")).willReturn(aResponse().withBody("ok").withStatus(HttpStatus.CREATED.value())))

        val (_, res, result) = "http://localhost:7300/cp/payment".httpPost().responseString()

        println(res.httpStatusCode)
        println(result)
    }
}

댓글 없음:

댓글 쓰기