|
| 1 | +package org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.routers |
| 2 | + |
| 3 | +import com.natpryce.hamkrest.assertion.assert |
| 4 | +import com.natpryce.hamkrest.isEmptyString |
| 5 | +import com.nhaarman.mockito_kotlin.any |
| 6 | +import com.nhaarman.mockito_kotlin.doReturn |
| 7 | +import com.nhaarman.mockito_kotlin.reset |
| 8 | +import com.nhaarman.mockito_kotlin.whenever |
| 9 | +import org.junit.jupiter.api.BeforeEach |
| 10 | +import org.junit.jupiter.api.DisplayName |
| 11 | +import org.junit.jupiter.api.Test |
| 12 | +import org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.extensions.toMono |
| 13 | +import org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.model.GeographicCoordinates |
| 14 | +import org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.model.LocationResponse |
| 15 | +import org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.model.SunriseSunset |
| 16 | +import org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.services.GeoLocationService |
| 17 | +import org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.services.SunriseSunsetService |
| 18 | +import org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.test.BasicIntegrationTest |
| 19 | +import org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.test.isNull |
| 20 | +import org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.test.tags.IntegrationTest |
| 21 | +import org.springframework.beans.factory.annotation.Autowired |
| 22 | +import org.springframework.boot.test.mock.mockito.SpyBean |
| 23 | + |
| 24 | +@IntegrationTest |
| 25 | +@DisplayName("MainRouter Integration Tests") |
| 26 | +internal class MainRouterTest : BasicIntegrationTest() { |
| 27 | + |
| 28 | + companion object { |
| 29 | + const val GOOGLE_ADDRESS = "1600 Amphitheatre Parkway, Mountain View, CA" |
| 30 | + const val API_LOCATION = "/api/location" |
| 31 | + const val SUNRISE_TIME = "2017-05-21T12:53:56+00:00" |
| 32 | + const val SUNSET_TIME = "2017-05-22T03:16:05+00:00" |
| 33 | + const val GOOGLE_LAT = 37.4224082 |
| 34 | + const val GOOGLE_LNG = -122.0856086 |
| 35 | + private val GOOGLE_LOCATION = GeographicCoordinates(GOOGLE_LAT, GOOGLE_LNG).toMono() |
| 36 | + private val SUNRISE_SUNSET = SunriseSunset(SUNRISE_TIME, SUNSET_TIME).toMono() |
| 37 | + private val STATIC_PATH = "/index.html" |
| 38 | + } |
| 39 | + |
| 40 | + @Autowired |
| 41 | + lateinit var mainRouter : MainRouter |
| 42 | + |
| 43 | + @SpyBean |
| 44 | + lateinit private var geoLocationService: GeoLocationService |
| 45 | + |
| 46 | + @SpyBean |
| 47 | + lateinit private var sunriseSunsetService: SunriseSunsetService |
| 48 | + |
| 49 | + @BeforeEach |
| 50 | + fun setup() = bindToRouterFunction(mainRouter.doRoute()) |
| 51 | + |
| 52 | + @Test |
| 53 | + fun staticRouterTest() { |
| 54 | + val html : String = get(STATIC_PATH) |
| 55 | + assert.that(html, !isEmptyString) |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + fun apiRouterTest() { |
| 60 | + doReturn(GOOGLE_LOCATION).whenever(geoLocationService).fromAddress(any()) |
| 61 | + doReturn(SUNRISE_SUNSET).whenever(sunriseSunsetService).fromGeographicCoordinates(any()) |
| 62 | + |
| 63 | + val locationResponse : LocationResponse = get(url = "${API_LOCATION}/${GOOGLE_ADDRESS}") |
| 64 | + assert.that(locationResponse.geographicCoordinates, !isNull()) |
| 65 | + |
| 66 | + reset(geoLocationService) |
| 67 | + reset(sunriseSunsetService) |
| 68 | + } |
| 69 | + |
| 70 | +} |
0 commit comments