Improve parity between Java and Kotlin router DSL
This commit adds following functions to the Kotlin DSL: add, filter, before, after and onError. Closes gh-23524
This commit is contained in:
@@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test
|
||||
import org.springframework.core.io.ClassPathResource
|
||||
import org.springframework.http.HttpHeaders.*
|
||||
import org.springframework.http.HttpMethod.*
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.MediaType.*
|
||||
import org.springframework.web.reactive.function.server.MockServerRequest.builder
|
||||
import reactor.test.StepVerifier
|
||||
@@ -172,6 +173,28 @@ class CoRouterFunctionDslTests {
|
||||
}
|
||||
path("/baz", ::handle)
|
||||
GET("/rendering") { RenderingResponse.create("index").buildAndAwait() }
|
||||
add(otherRouter)
|
||||
}
|
||||
|
||||
private val otherRouter = router {
|
||||
"/other" {
|
||||
ok().build()
|
||||
}
|
||||
filter { request, next ->
|
||||
next(request)
|
||||
}
|
||||
before {
|
||||
it
|
||||
}
|
||||
after { _, response ->
|
||||
response
|
||||
}
|
||||
onError({it is IllegalStateException}) { _, _ ->
|
||||
ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).build()
|
||||
}
|
||||
onError<IllegalStateException> { _, _ ->
|
||||
ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).build()
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test
|
||||
import org.springframework.core.io.ClassPathResource
|
||||
import org.springframework.http.HttpHeaders.*
|
||||
import org.springframework.http.HttpMethod.*
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.MediaType.*
|
||||
import org.springframework.web.reactive.function.server.MockServerRequest.builder
|
||||
import reactor.core.publisher.Mono
|
||||
@@ -173,6 +174,28 @@ class RouterFunctionDslTests {
|
||||
}
|
||||
path("/baz", ::handle)
|
||||
GET("/rendering") { RenderingResponse.create("index").build() }
|
||||
add(otherRouter)
|
||||
}
|
||||
|
||||
private val otherRouter = router {
|
||||
"/other" {
|
||||
ok().build()
|
||||
}
|
||||
filter { request, next ->
|
||||
next(request)
|
||||
}
|
||||
before {
|
||||
it
|
||||
}
|
||||
after { _, response ->
|
||||
response
|
||||
}
|
||||
onError({it is IllegalStateException}) { _, _ ->
|
||||
ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).build()
|
||||
}
|
||||
onError<IllegalStateException> { _, _ ->
|
||||
ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).build()
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
|
||||
Reference in New Issue
Block a user