diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index c315043..b573bb5 100644 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1 +1 @@ -distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip +distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip diff --git a/pom.xml b/pom.xml index ca0c735..c81e4a7 100644 --- a/pom.xml +++ b/pom.xml @@ -1,326 +1,319 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - org.learning.by.example.reactive.kotlin.microservices - KotlinReactiveMS - 1.0.2 - jar + org.learning.by.example.reactive.kotlin.microservices + KotlinReactiveMS + 1.0.2 + jar - KotlinReactiveMS - This is an example of doing reactive MicroServices using spring 5 functional web framework and spring boot 2 using Kotlin + KotlinReactiveMS + This is an example of doing reactive MicroServices using spring 5 functional web framework and spring + boot 2 using Kotlin + - - org.springframework.boot - spring-boot-starter-parent - 2.0.0.M1 - - + + org.springframework.boot + spring-boot-starter-parent + 2.0.0.RELEASE + + - - true - UTF-8 - UTF-8 - 1.8 - 1.1.2-2 - 5.0.0-M4 - 1.0.0-M4 - 1.0.0-M4 - 2.19.1 - + + true + UTF-8 + UTF-8 + 1.8 + 1.2.30 + 5.1.0 + 1.1.0 + 2.19.1 + - - - org.springframework.boot - spring-boot-starter-webflux - + + + org.springframework.boot + spring-boot-starter-webflux + - - org.jetbrains.kotlin - kotlin-stdlib-jre8 - ${kotlin.version} - + + com.fasterxml.jackson.module + jackson-module-kotlin + - - org.jetbrains.kotlin - kotlin-reflect - ${kotlin.version} - + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + - - io.projectreactor - reactor-kotlin-extensions - 1.0.0.M2 - + + org.jetbrains.kotlin + kotlin-reflect + ${kotlin.version} + - - org.springframework.boot - spring-boot-starter-test - test - + + io.projectreactor + reactor-kotlin-extensions + 1.0.0.M2 + - - com.nhaarman - mockito-kotlin - 1.4.0 - test - + + org.springframework.boot + spring-boot-starter-test + test + - - org.junit.jupiter - junit-jupiter-api - ${junit.jupiter.version} - test - + + com.nhaarman + mockito-kotlin + 1.4.0 + test + - - org.jsoup - jsoup - 1.10.2 - test - + + org.junit.jupiter + junit-jupiter-api + ${junit.jupiter.version} + test + - - org.amshove.kluent - kluent - 1.22 - + + org.jsoup + jsoup + 1.10.2 + test + - + + org.amshove.kluent + kluent + 1.22 + - - - UnitAndIntegrationTests - - true - - - - - maven-surefire-plugin - ${maven.surefire.plugin.version} - - - UnitTest,IntegrationTest - - - - - org.junit.platform - junit-platform-surefire-provider - ${junit.platform.surefire.provider.version} - - - org.junit.jupiter - junit-jupiter-engine - ${junit.jupiter.version} - - - - - - - - IntegrationTests - - - - maven-surefire-plugin - ${maven.surefire.plugin.version} - - - IntegrationTest - - - - - org.junit.platform - junit-platform-surefire-provider - ${junit.platform.surefire.provider.version} - - - org.junit.jupiter - junit-jupiter-engine - ${junit.jupiter.version} - - - - - - - - UnitTests - - - - maven-surefire-plugin - ${maven.surefire.plugin.version} - - - UnitTest - - - - - org.junit.platform - junit-platform-surefire-provider - ${junit.platform.surefire.provider.version} - - - org.junit.jupiter - junit-jupiter-engine - ${junit.jupiter.version} - - - - - - - - SystemTests - - - - maven-surefire-plugin - ${maven.surefire.plugin.version} - - - SystemTest - - - - - org.junit.platform - junit-platform-surefire-provider - ${junit.platform.surefire.provider.version} - - - org.junit.jupiter - junit-jupiter-engine - ${junit.jupiter.version} - - - - - - - + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + test + - - ${project.basedir}/src/main/kotlin - ${project.basedir}/src/test/kotlin - - - org.springframework.boot - spring-boot-maven-plugin - - - kotlin-maven-plugin - org.jetbrains.kotlin - ${kotlin.version} - - - spring - - 1.8 - - - - compile - compile - - compile - - - - test-compile - test-compile - - test-compile - - - - - - org.jetbrains.kotlin - kotlin-maven-allopen - ${kotlin.version} - - - - - org.jacoco - jacoco-maven-plugin - 0.7.9 - - - - prepare-agent - - - - report - test - - report - - - - - - + - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/snapshot - - true - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - jcenter - http://jcenter.bintray.com - - true - never - warn - - - true - warn - - - + + + UnitAndIntegrationTests + + true + + + + + maven-surefire-plugin + ${maven.surefire.plugin.version} + + + UnitTest,IntegrationTest + + + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + + + + + + IntegrationTests + + + + maven-surefire-plugin + ${maven.surefire.plugin.version} + + + IntegrationTest + + + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + + + + + + UnitTests + + + + maven-surefire-plugin + ${maven.surefire.plugin.version} + + + UnitTest + + + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + + + + + + SystemTests + + + + maven-surefire-plugin + ${maven.surefire.plugin.version} + + + SystemTest + + + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + + + + + - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/snapshot - - true - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - + + ${project.basedir}/src/main/kotlin + ${project.basedir}/src/test/kotlin + + + org.springframework.boot + spring-boot-maven-plugin + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + spring + + 1.8 + + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + + org.jetbrains.kotlin + kotlin-maven-allopen + ${kotlin.version} + + + + + org.jacoco + jacoco-maven-plugin + 0.8.1 + + + + prepare-agent + + + + report + test + + report + + + + + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + jcenter + http://jcenter.bintray.com + + true + never + warn + + + true + warn + + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + diff --git a/src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/handlers/ApiHandler.kt b/src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/handlers/ApiHandler.kt index 48486b2..e3062cc 100644 --- a/src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/handlers/ApiHandler.kt +++ b/src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/handlers/ApiHandler.kt @@ -34,7 +34,7 @@ internal class ApiHandler(val geoLocationService: GeoLocationService, val sunris .onErrorResume(errorHandler::throwableError)!! internal fun buildResponse(address: Mono) = - address.transform(geoLocationService::fromAddress).and(this::sunriseSunset, ::LocationResponse) + address.transform(geoLocationService::fromAddress).zipWhen(this::sunriseSunset, ::LocationResponse) internal fun sunriseSunset(geographicCoordinates: GeographicCoordinates) = geographicCoordinates.toMono().transform(sunriseSunsetService::fromGeographicCoordinates) diff --git a/src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/routers/MainRouter.kt b/src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/routers/MainRouter.kt index baf16cf..886209f 100644 --- a/src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/routers/MainRouter.kt +++ b/src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/routers/MainRouter.kt @@ -1,10 +1,9 @@ package org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.routers -import org.springframework.web.reactive.function.server.router - internal class MainRouter(val apiRouter: ApiRouter, val staticRouter: StaticRouter) { - fun doRoute() = router { - routes.addAll(arrayListOf(apiRouter.doRoute(), staticRouter.doRoute())) - } + fun doRoute() = apiRouter.doRoute().andOther(staticRouter.doRoute()) + } + + diff --git a/src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/services/GeoLocationServiceImpl.kt b/src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/services/GeoLocationServiceImpl.kt index 0201dd8..8375c64 100644 --- a/src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/services/GeoLocationServiceImpl.kt +++ b/src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/services/GeoLocationServiceImpl.kt @@ -43,8 +43,7 @@ open internal class GeoLocationServiceImpl(val endPoint: String, var webClient: webClient.get() .uri(it) .accept(MediaType.APPLICATION_JSON) - .retrieve() - .toEntity() + .exchange().flatMap { it.toEntity() } } open internal fun geometryLocation(responseMono: Mono>) = diff --git a/src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/services/SunriseSunsetServiceImpl.kt b/src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/services/SunriseSunsetServiceImpl.kt index 33e706b..6d808a4 100644 --- a/src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/services/SunriseSunsetServiceImpl.kt +++ b/src/main/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/services/SunriseSunsetServiceImpl.kt @@ -41,8 +41,8 @@ open internal class SunriseSunsetServiceImpl(val endPoint: String, var webClient webClient.get() .uri(it) .accept(MediaType.APPLICATION_JSON) - .retrieve() - .toEntity() + .exchange().flatMap { it.toEntity() } + } open internal fun createResult(responseMono: Mono>) = diff --git a/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/application/KotlinReactiveMsApplicationTests.kt b/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/application/KotlinReactiveMsApplicationTest.kt similarity index 95% rename from src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/application/KotlinReactiveMsApplicationTests.kt rename to src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/application/KotlinReactiveMsApplicationTest.kt index 7881053..6bd1a3b 100644 --- a/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/application/KotlinReactiveMsApplicationTests.kt +++ b/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/application/KotlinReactiveMsApplicationTest.kt @@ -13,7 +13,7 @@ import org.springframework.boot.web.server.LocalServerPort @SystemTest @DisplayName("KotlinReactiveMsApplication System Tests") -private class KotlinReactiveMsApplicationTests : BasicIntegrationTest() { +private class KotlinReactiveMsApplicationTest : BasicIntegrationTest() { companion object { const val GOOGLE_ADDRESS = "1600 Amphitheatre Parkway, Mountain View, CA" diff --git a/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/application/mainTests.kt b/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/application/mainTest.kt similarity index 90% rename from src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/application/mainTests.kt rename to src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/application/mainTest.kt index ecc194f..7f760ca 100644 --- a/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/application/mainTests.kt +++ b/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/application/mainTest.kt @@ -7,7 +7,7 @@ import org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.te @UnitTest @DisplayName("main Unit Tests") -private class mainTests : BasicIntegrationTest() { +private class mainTest : BasicIntegrationTest() { @Test fun mainTest() { diff --git a/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/extensions/UtilsExtensionsTests.kt b/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/extensions/UtilsExtensionsTest.kt similarity index 91% rename from src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/extensions/UtilsExtensionsTests.kt rename to src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/extensions/UtilsExtensionsTest.kt index 3adf3cf..ce25528 100644 --- a/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/extensions/UtilsExtensionsTests.kt +++ b/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/extensions/UtilsExtensionsTest.kt @@ -17,8 +17,8 @@ import org.springframework.web.reactive.function.server.ServerResponse.ok import reactor.core.publisher.toMono @UnitTest -@DisplayName("UtilsExtensionsTests Unit Tests") -private class UtilsExtensionsTests : BasicIntegrationTest() { +@DisplayName("UtilsExtensionsTest Unit Tests") +private class UtilsExtensionsTest : BasicIntegrationTest() { private companion object { const val BAR = "BAR" @@ -72,9 +72,9 @@ private class UtilsExtensionsTests : BasicIntegrationTest() { @Test fun getLoggerTest() { - val logger = getLogger() + val logger = getLogger() logger `should not be` null logger `should be instance of` org.slf4j.Logger::class - logger.name `should equal to` UtilsExtensionsTests::class.qualifiedName!! + logger.name `should equal to` UtilsExtensionsTest::class.qualifiedName!! } } diff --git a/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/handlers/ApiHandlerTests.kt b/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/handlers/ApiHandlerTest.kt similarity index 96% rename from src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/handlers/ApiHandlerTests.kt rename to src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/handlers/ApiHandlerTest.kt index 358d67b..0bd2b8f 100644 --- a/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/handlers/ApiHandlerTests.kt +++ b/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/handlers/ApiHandlerTest.kt @@ -24,7 +24,7 @@ import reactor.core.publisher.toMono @UnitTest @DisplayName("ApiHandler Unit Tests") -private class ApiHandlerTests : BasicIntegrationTest() { +private class ApiHandlerTest : BasicIntegrationTest() { private companion object { const val ADDRESS_VARIABLE = "address" @@ -54,9 +54,11 @@ private class ApiHandlerTests : BasicIntegrationTest() { @SpyBean lateinit private var sunriseSunsetService: SunriseSunsetService + fun getData(geographicCoordinates: GeographicCoordinates) = SUNRISE_SUNSET + @Test fun combineTest() { - GOOGLE_LOCATION_MONO.and(SUNRISE_SUNSET, ::LocationResponse) + GOOGLE_LOCATION_MONO.zipWhen(this::getData, ::LocationResponse) .subscribe(this::verifyLocationResponse) } @@ -92,7 +94,7 @@ private class ApiHandlerTests : BasicIntegrationTest() { @Test fun serverResponseTest() { - GOOGLE_LOCATION_MONO.and(SUNRISE_SUNSET, ::LocationResponse) + GOOGLE_LOCATION_MONO.zipWhen(this::getData, ::LocationResponse) .transform(apiHandler::serverResponse) .subscribe(this::verifyServerResponse) } diff --git a/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/services/SunriseSunsetServiceImplTest.kt b/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/services/SunriseSunsetServiceImplTest.kt index aa27931..32737f6 100644 --- a/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/services/SunriseSunsetServiceImplTest.kt +++ b/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/services/SunriseSunsetServiceImplTest.kt @@ -20,7 +20,7 @@ import reactor.core.publisher.Mono import reactor.core.publisher.toMono @UnitTest -@DisplayName("SunriseSunsetServiceImplUnit Tests") +@DisplayName("SunriseSunsetServiceImpl Unit Tests") private class SunriseSunsetServiceImplTest { private companion object { diff --git a/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/test/TestsExtensions.kt b/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/test/TestsExtensions.kt index 186eb68..e96eb83 100644 --- a/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/test/TestsExtensions.kt +++ b/src/test/kotlin/org/learning/by/example/reactive/kotlin/microservices/KotlinReactiveMS/test/TestsExtensions.kt @@ -2,8 +2,10 @@ package org.learning.by.example.reactive.kotlin.microservices.KotlinReactiveMS.t import com.fasterxml.jackson.databind.ObjectMapper import com.nhaarman.mockito_kotlin.* +import org.springframework.core.ParameterizedTypeReference import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity +import org.springframework.web.reactive.function.client.ClientResponse import org.springframework.web.reactive.function.client.WebClient import org.springframework.web.reactive.function.server.EntityResponse import org.springframework.web.reactive.function.server.ServerResponse @@ -31,17 +33,18 @@ internal infix fun T.reset(keyword: MockResponseKeyword) = reset(this) fun mockWebClient(webClient: WebClient, mono: Mono>): WebClient { val client = spy(webClient) - val uriSpec = mock>() + val uriSpec = mock>() (client `will return` uriSpec).get() val headerSpec = mock>() (uriSpec `will return` headerSpec).uri(any()) (headerSpec `will return` headerSpec).accept(any()) - val responseSpec = mock() - val value = mono.block() - (headerSpec `will return` responseSpec).retrieve() - (responseSpec `will return` mono).toEntity(value.body.javaClass) + val clientResponse = mock() + (clientResponse `will return` mono).toEntity(any>()) + + val clientResponseMono = clientResponse.toMono() + (headerSpec `will return` clientResponseMono).exchange() return client }