Improve parity between Java and Kotlin router DSL
This commit adds variants with pattern + predicate to Kotlin router DSLs, and vararg where necessary. Closes gh-23524
This commit is contained in:
@@ -16,10 +16,8 @@
|
||||
|
||||
package org.springframework.web.reactive.function.server
|
||||
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.assertj.core.api.Assertions.assertThatExceptionOfType
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.fail
|
||||
import org.springframework.core.io.ClassPathResource
|
||||
import org.springframework.http.HttpHeaders.*
|
||||
import org.springframework.http.HttpMethod.*
|
||||
@@ -63,6 +61,18 @@ class CoRouterFunctionDslTests {
|
||||
.verifyComplete()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun acceptAndPOSTWithRequestPredicate() {
|
||||
val request = builder()
|
||||
.method(POST)
|
||||
.uri(URI("/api/bar/"))
|
||||
.header(CONTENT_TYPE, APPLICATION_JSON_VALUE)
|
||||
.build()
|
||||
StepVerifier.create(sampleRouter().route(request))
|
||||
.expectNextCount(1)
|
||||
.verifyComplete()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun contentType() {
|
||||
val request = builder().uri(URI("/content")).header(CONTENT_TYPE, APPLICATION_OCTET_STREAM_VALUE).build()
|
||||
@@ -134,6 +144,7 @@ class CoRouterFunctionDslTests {
|
||||
(GET("/foo/") or GET("/foos/")) { req -> handle(req) }
|
||||
"/api".nest {
|
||||
POST("/foo/", ::handleFromClass)
|
||||
POST("/bar/", contentType(APPLICATION_JSON), ::handleFromClass)
|
||||
PUT("/foo/", :: handleFromClass)
|
||||
PATCH("/foo/") {
|
||||
ok().buildAndAwait()
|
||||
@@ -162,10 +173,10 @@ class CoRouterFunctionDslTests {
|
||||
path("/baz", ::handle)
|
||||
GET("/rendering") { RenderingResponse.create("index").buildAndAwait() }
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
private suspend fun handleFromClass(req: ServerRequest) = ServerResponse.ok().buildAndAwait()
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
private suspend fun handleFromClass(req: ServerRequest) = ServerResponse.ok().buildAndAwait()
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
private suspend fun handle(req: ServerRequest) = ServerResponse.ok().buildAndAwait()
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
|
||||
package org.springframework.web.reactive.function.server
|
||||
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.assertj.core.api.Assertions.assertThatExceptionOfType
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.fail
|
||||
import org.springframework.core.io.ClassPathResource
|
||||
import org.springframework.http.HttpHeaders.*
|
||||
import org.springframework.http.HttpMethod.*
|
||||
@@ -64,6 +62,18 @@ class RouterFunctionDslTests {
|
||||
.verifyComplete()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun acceptAndPOSTWithRequestPredicate() {
|
||||
val request = builder()
|
||||
.method(POST)
|
||||
.uri(URI("/api/bar/"))
|
||||
.header(CONTENT_TYPE, APPLICATION_JSON_VALUE)
|
||||
.build()
|
||||
StepVerifier.create(sampleRouter().route(request))
|
||||
.expectNextCount(1)
|
||||
.verifyComplete()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun contentType() {
|
||||
val request = builder().uri(URI("/content")).header(CONTENT_TYPE, APPLICATION_OCTET_STREAM_VALUE).build()
|
||||
@@ -135,6 +145,7 @@ class RouterFunctionDslTests {
|
||||
(GET("/foo/") or GET("/foos/")) { req -> handle(req) }
|
||||
"/api".nest {
|
||||
POST("/foo/", ::handleFromClass)
|
||||
POST("/bar/", contentType(APPLICATION_JSON), ::handleFromClass)
|
||||
PUT("/foo/", :: handleFromClass)
|
||||
PATCH("/foo/") {
|
||||
ok().build()
|
||||
@@ -163,10 +174,10 @@ class RouterFunctionDslTests {
|
||||
path("/baz", ::handle)
|
||||
GET("/rendering") { RenderingResponse.create("index").build() }
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
private fun handleFromClass(req: ServerRequest) = ServerResponse.ok().build()
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
private fun handleFromClass(req: ServerRequest) = ServerResponse.ok().build()
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
private fun handle(req: ServerRequest) = ServerResponse.ok().build()
|
||||
|
||||
Reference in New Issue
Block a user