Last active
January 12, 2020 04:10
-
-
Save billydh/2237a86460438b817be993cb007c4150 to your computer and use it in GitHub Desktop.
RouteTest.kt with Open Weather API response loaded and WebTestClient auto configuration annotation
This file contains hidden or 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
| package io.codebrews.wiremockdemo | |
| import com.github.tomakehurst.wiremock.client.WireMock.* | |
| import com.github.tomakehurst.wiremock.junit.WireMockRule | |
| import org.junit.ClassRule | |
| import org.junit.Test | |
| import org.junit.runner.RunWith | |
| import org.slf4j.Logger | |
| import org.slf4j.LoggerFactory | |
| import org.springframework.beans.factory.annotation.Autowired | |
| import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient | |
| import org.springframework.boot.test.context.SpringBootTest | |
| import org.springframework.http.HttpHeaders | |
| import org.springframework.http.HttpStatus | |
| import org.springframework.http.MediaType | |
| import org.springframework.test.context.junit4.SpringRunner | |
| import org.springframework.test.web.reactive.server.WebTestClient | |
| @SpringBootTest | |
| @RunWith(SpringRunner::class) | |
| @AutoConfigureWebTestClient | |
| class RouteTest { | |
| private val logger: Logger = LoggerFactory.getLogger(javaClass) | |
| @Autowired | |
| private lateinit var client: WebTestClient | |
| companion object { | |
| @ClassRule | |
| @JvmField | |
| val wireMockRule = WireMockRule(8089) | |
| } | |
| private fun stubResponse(url: String, responseBody: String, responseStatus: Int = HttpStatus.OK.value()) { | |
| stubFor(get(url) | |
| .willReturn(aResponse() | |
| .withStatus(responseStatus) | |
| .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) | |
| .withBody(responseBody)) | |
| ) | |
| } | |
| private val apiResponseFileName = "openweather-api-response.json" | |
| private val openWeatherApiResponse: String? = this::class.java.classLoader.getResource(apiResponseFileName)?.readText() | |
| @Test | |
| fun `test open weather api response is loaded`(){ | |
| logger.info(openWeatherApiResponse) | |
| assert(openWeatherApiResponse != null) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment