|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2020 the original author or authors. |
|
|
|
* Copyright 2002-2022 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -16,6 +16,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.web.reactive.function.server |
|
|
|
package org.springframework.web.reactive.function.server |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.assertj.core.api.Assertions.assertThat |
|
|
|
import org.assertj.core.api.Assertions.assertThatExceptionOfType |
|
|
|
import org.assertj.core.api.Assertions.assertThatExceptionOfType |
|
|
|
import org.junit.jupiter.api.Test |
|
|
|
import org.junit.jupiter.api.Test |
|
|
|
import org.springframework.core.io.ClassPathResource |
|
|
|
import org.springframework.core.io.ClassPathResource |
|
|
|
@ -25,6 +26,7 @@ import org.springframework.http.HttpStatus |
|
|
|
import org.springframework.http.MediaType.* |
|
|
|
import org.springframework.http.MediaType.* |
|
|
|
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest.* |
|
|
|
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest.* |
|
|
|
import org.springframework.web.testfixture.server.MockServerWebExchange |
|
|
|
import org.springframework.web.testfixture.server.MockServerWebExchange |
|
|
|
|
|
|
|
import org.springframework.web.reactive.function.server.AttributesTestVisitor |
|
|
|
import reactor.core.publisher.Mono |
|
|
|
import reactor.core.publisher.Mono |
|
|
|
import reactor.test.StepVerifier |
|
|
|
import reactor.test.StepVerifier |
|
|
|
|
|
|
|
|
|
|
|
@ -153,6 +155,19 @@ class RouterFunctionDslTests { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
fun attributes() { |
|
|
|
|
|
|
|
val visitor = AttributesTestVisitor() |
|
|
|
|
|
|
|
attributesRouter.accept(visitor) |
|
|
|
|
|
|
|
assertThat(visitor.routerFunctionsAttributes()).containsExactly( |
|
|
|
|
|
|
|
listOf(mapOf("foo" to "bar", "baz" to "qux")), |
|
|
|
|
|
|
|
listOf(mapOf("foo" to "bar", "baz" to "qux")), |
|
|
|
|
|
|
|
listOf(mapOf("foo" to "bar"), mapOf("foo" to "n1")), |
|
|
|
|
|
|
|
listOf(mapOf("baz" to "qux"), mapOf("foo" to "n1")), |
|
|
|
|
|
|
|
listOf(mapOf("foo" to "n3"), mapOf("foo" to "n2"), mapOf("foo" to "n1")) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
assertThat(visitor.visitCount()).isEqualTo(7); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun sampleRouter() = router { |
|
|
|
private fun sampleRouter() = router { |
|
|
|
(GET("/foo/") or GET("/foos/")) { req -> handle(req) } |
|
|
|
(GET("/foo/") or GET("/foos/")) { req -> handle(req) } |
|
|
|
@ -210,6 +225,39 @@ class RouterFunctionDslTests { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val attributesRouter = router { |
|
|
|
|
|
|
|
GET("/atts/1") { |
|
|
|
|
|
|
|
ok().build() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
withAttribute("foo", "bar") |
|
|
|
|
|
|
|
withAttribute("baz", "qux") |
|
|
|
|
|
|
|
GET("/atts/2") { |
|
|
|
|
|
|
|
ok().build() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
withAttributes { atts -> |
|
|
|
|
|
|
|
atts["foo"] = "bar" |
|
|
|
|
|
|
|
atts["baz"] = "qux" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
"/atts".nest { |
|
|
|
|
|
|
|
GET("/3") { |
|
|
|
|
|
|
|
ok().build() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
withAttribute("foo", "bar") |
|
|
|
|
|
|
|
GET("/4") { |
|
|
|
|
|
|
|
ok().build() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
withAttribute("baz", "qux") |
|
|
|
|
|
|
|
"/5".nest { |
|
|
|
|
|
|
|
GET { |
|
|
|
|
|
|
|
ok().build() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
withAttribute("foo", "n3") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
withAttribute("foo", "n2") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
withAttribute("foo", "n1") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Suppress("UNUSED_PARAMETER") |
|
|
|
@Suppress("UNUSED_PARAMETER") |
|
|
|
private fun handleFromClass(req: ServerRequest) = ServerResponse.ok().build() |
|
|
|
private fun handleFromClass(req: ServerRequest) = ServerResponse.ok().build() |
|
|
|
} |
|
|
|
} |
|
|
|
|