Fix indentation to use tabs in Kotlin source files
Closes gh-33840
This commit is contained in:
committed by
Sébastien Deleuze
parent
6bd4687706
commit
0beb56a58c
@@ -66,4 +66,4 @@ suspend fun ServerWebExchange.awaitSession(): WebSession =
|
||||
* @since 6.1
|
||||
*/
|
||||
fun ServerWebExchange.Builder.principal(supplier: suspend () -> Principal): ServerWebExchange.Builder
|
||||
= principal(mono(Dispatchers.Unconfined) { supplier.invoke() })
|
||||
= principal(mono(Dispatchers.Unconfined) { supplier.invoke() })
|
||||
|
||||
@@ -49,139 +49,139 @@ import java.util.*
|
||||
*/
|
||||
class KotlinRestTemplateHttpServiceProxyTests {
|
||||
|
||||
private lateinit var server: MockWebServer
|
||||
private lateinit var server: MockWebServer
|
||||
|
||||
private lateinit var testService: TestService
|
||||
private lateinit var testService: TestService
|
||||
|
||||
private lateinit var anotherServer: MockWebServer
|
||||
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
server = MockWebServer()
|
||||
prepareResponse()
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
server = MockWebServer()
|
||||
prepareResponse()
|
||||
anotherServer = anotherServer()
|
||||
testService = initTestService()
|
||||
}
|
||||
testService = initTestService()
|
||||
}
|
||||
|
||||
private fun initTestService(): TestService {
|
||||
val restTemplate = RestTemplate()
|
||||
restTemplate.uriTemplateHandler = DefaultUriBuilderFactory(server.url("/").toString())
|
||||
return HttpServiceProxyFactory.builder()
|
||||
.exchangeAdapter(RestTemplateAdapter.create(restTemplate))
|
||||
.build()
|
||||
.createClient(TestService::class.java)
|
||||
}
|
||||
private fun initTestService(): TestService {
|
||||
val restTemplate = RestTemplate()
|
||||
restTemplate.uriTemplateHandler = DefaultUriBuilderFactory(server.url("/").toString())
|
||||
return HttpServiceProxyFactory.builder()
|
||||
.exchangeAdapter(RestTemplateAdapter.create(restTemplate))
|
||||
.build()
|
||||
.createClient(TestService::class.java)
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
fun shutDown() {
|
||||
server.shutdown()
|
||||
@AfterEach
|
||||
fun shutDown() {
|
||||
server.shutdown()
|
||||
anotherServer.shutdown()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(InterruptedException::class)
|
||||
fun getRequest() {
|
||||
val response = testService.request
|
||||
@Test
|
||||
@Throws(InterruptedException::class)
|
||||
fun getRequest() {
|
||||
val response = testService.request
|
||||
|
||||
val request = server.takeRequest()
|
||||
assertThat(response).isEqualTo("Hello Spring!")
|
||||
assertThat(request.method).isEqualTo("GET")
|
||||
assertThat(request.path).isEqualTo("/test")
|
||||
}
|
||||
val request = server.takeRequest()
|
||||
assertThat(response).isEqualTo("Hello Spring!")
|
||||
assertThat(request.method).isEqualTo("GET")
|
||||
assertThat(request.path).isEqualTo("/test")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(InterruptedException::class)
|
||||
fun getRequestWithPathVariable() {
|
||||
val response = testService.getRequestWithPathVariable("456")
|
||||
@Test
|
||||
@Throws(InterruptedException::class)
|
||||
fun getRequestWithPathVariable() {
|
||||
val response = testService.getRequestWithPathVariable("456")
|
||||
|
||||
val request = server.takeRequest()
|
||||
assertThat(response.statusCode).isEqualTo(HttpStatus.OK)
|
||||
assertThat(response.body).isEqualTo("Hello Spring!")
|
||||
assertThat(request.method).isEqualTo("GET")
|
||||
assertThat(request.path).isEqualTo("/test/456")
|
||||
}
|
||||
val request = server.takeRequest()
|
||||
assertThat(response.statusCode).isEqualTo(HttpStatus.OK)
|
||||
assertThat(response.body).isEqualTo("Hello Spring!")
|
||||
assertThat(request.method).isEqualTo("GET")
|
||||
assertThat(request.path).isEqualTo("/test/456")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(InterruptedException::class)
|
||||
fun getRequestWithDynamicUri() {
|
||||
val dynamicUri = server.url("/greeting/123").uri()
|
||||
@Test
|
||||
@Throws(InterruptedException::class)
|
||||
fun getRequestWithDynamicUri() {
|
||||
val dynamicUri = server.url("/greeting/123").uri()
|
||||
|
||||
val response = testService.getRequestWithDynamicUri(dynamicUri, "456")
|
||||
val response = testService.getRequestWithDynamicUri(dynamicUri, "456")
|
||||
|
||||
val request = server.takeRequest()
|
||||
assertThat(response.orElse("empty")).isEqualTo("Hello Spring!")
|
||||
assertThat(request.method).isEqualTo("GET")
|
||||
assertThat(request.requestUrl.uri()).isEqualTo(dynamicUri)
|
||||
}
|
||||
val request = server.takeRequest()
|
||||
assertThat(response.orElse("empty")).isEqualTo("Hello Spring!")
|
||||
assertThat(request.method).isEqualTo("GET")
|
||||
assertThat(request.requestUrl.uri()).isEqualTo(dynamicUri)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(InterruptedException::class)
|
||||
fun postWithRequestHeader() {
|
||||
testService.postRequestWithHeader("testHeader", "testBody")
|
||||
@Test
|
||||
@Throws(InterruptedException::class)
|
||||
fun postWithRequestHeader() {
|
||||
testService.postRequestWithHeader("testHeader", "testBody")
|
||||
|
||||
val request = server.takeRequest()
|
||||
assertThat(request.method).isEqualTo("POST")
|
||||
assertThat(request.path).isEqualTo("/test")
|
||||
assertThat(request.headers["testHeaderName"]).isEqualTo("testHeader")
|
||||
assertThat(request.body.readUtf8()).isEqualTo("testBody")
|
||||
}
|
||||
val request = server.takeRequest()
|
||||
assertThat(request.method).isEqualTo("POST")
|
||||
assertThat(request.path).isEqualTo("/test")
|
||||
assertThat(request.headers["testHeaderName"]).isEqualTo("testHeader")
|
||||
assertThat(request.body.readUtf8()).isEqualTo("testBody")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun formData() {
|
||||
val map: MultiValueMap<String, String> = LinkedMultiValueMap()
|
||||
map.add("param1", "value 1")
|
||||
map.add("param2", "value 2")
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun formData() {
|
||||
val map: MultiValueMap<String, String> = LinkedMultiValueMap()
|
||||
map.add("param1", "value 1")
|
||||
map.add("param2", "value 2")
|
||||
|
||||
testService.postForm(map)
|
||||
testService.postForm(map)
|
||||
|
||||
val request = server.takeRequest()
|
||||
assertThat(request.headers["Content-Type"])
|
||||
.isEqualTo("application/x-www-form-urlencoded;charset=UTF-8")
|
||||
assertThat(request.body.readUtf8()).isEqualTo("param1=value+1¶m2=value+2")
|
||||
}
|
||||
val request = server.takeRequest()
|
||||
assertThat(request.headers["Content-Type"])
|
||||
.isEqualTo("application/x-www-form-urlencoded;charset=UTF-8")
|
||||
assertThat(request.body.readUtf8()).isEqualTo("param1=value+1¶m2=value+2")
|
||||
}
|
||||
|
||||
// gh-30342
|
||||
@Test
|
||||
@Throws(InterruptedException::class)
|
||||
fun multipart() {
|
||||
val fileName = "testFileName"
|
||||
val originalFileName = "originalTestFileName"
|
||||
val file: MultipartFile = MockMultipartFile(fileName, originalFileName, MediaType.APPLICATION_JSON_VALUE,
|
||||
"test".toByteArray())
|
||||
// gh-30342
|
||||
@Test
|
||||
@Throws(InterruptedException::class)
|
||||
fun multipart() {
|
||||
val fileName = "testFileName"
|
||||
val originalFileName = "originalTestFileName"
|
||||
val file: MultipartFile = MockMultipartFile(fileName, originalFileName, MediaType.APPLICATION_JSON_VALUE,
|
||||
"test".toByteArray())
|
||||
|
||||
testService.postMultipart(file, "test2")
|
||||
testService.postMultipart(file, "test2")
|
||||
|
||||
val request = server.takeRequest()
|
||||
assertThat(request.headers["Content-Type"]).startsWith("multipart/form-data;boundary=")
|
||||
assertThat(request.body.readUtf8()).containsSubsequence(
|
||||
"Content-Disposition: form-data; name=\"file\"; filename=\"originalTestFileName\"",
|
||||
"Content-Type: application/json", "Content-Length: 4", "test",
|
||||
"Content-Disposition: form-data; name=\"anotherPart\"", "Content-Type: text/plain;charset=UTF-8",
|
||||
"Content-Length: 5", "test2")
|
||||
}
|
||||
val request = server.takeRequest()
|
||||
assertThat(request.headers["Content-Type"]).startsWith("multipart/form-data;boundary=")
|
||||
assertThat(request.body.readUtf8()).containsSubsequence(
|
||||
"Content-Disposition: form-data; name=\"file\"; filename=\"originalTestFileName\"",
|
||||
"Content-Type: application/json", "Content-Length: 4", "test",
|
||||
"Content-Disposition: form-data; name=\"anotherPart\"", "Content-Type: text/plain;charset=UTF-8",
|
||||
"Content-Length: 5", "test2")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(InterruptedException::class)
|
||||
fun putRequestWithCookies() {
|
||||
testService.putRequestWithCookies("test1", "test2")
|
||||
@Test
|
||||
@Throws(InterruptedException::class)
|
||||
fun putRequestWithCookies() {
|
||||
testService.putRequestWithCookies("test1", "test2")
|
||||
|
||||
val request = server.takeRequest()
|
||||
assertThat(request.method).isEqualTo("PUT")
|
||||
assertThat(request.getHeader("Cookie"))
|
||||
.isEqualTo("firstCookie=test1; secondCookie=test2")
|
||||
}
|
||||
val request = server.takeRequest()
|
||||
assertThat(request.method).isEqualTo("PUT")
|
||||
assertThat(request.getHeader("Cookie"))
|
||||
.isEqualTo("firstCookie=test1; secondCookie=test2")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(InterruptedException::class)
|
||||
fun putRequestWithSameNameCookies() {
|
||||
testService.putRequestWithSameNameCookies("test1", "test2")
|
||||
@Test
|
||||
@Throws(InterruptedException::class)
|
||||
fun putRequestWithSameNameCookies() {
|
||||
testService.putRequestWithSameNameCookies("test1", "test2")
|
||||
|
||||
val request = server.takeRequest()
|
||||
assertThat(request.method).isEqualTo("PUT")
|
||||
assertThat(request.getHeader("Cookie"))
|
||||
.isEqualTo("testCookie=test1; testCookie=test2")
|
||||
}
|
||||
val request = server.takeRequest()
|
||||
assertThat(request.method).isEqualTo("PUT")
|
||||
assertThat(request.getHeader("Cookie"))
|
||||
.isEqualTo("testCookie=test1; testCookie=test2")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(InterruptedException::class)
|
||||
@@ -237,11 +237,11 @@ class KotlinRestTemplateHttpServiceProxyTests {
|
||||
}
|
||||
|
||||
|
||||
private fun prepareResponse() {
|
||||
val response = MockResponse()
|
||||
response.setHeader("Content-Type", "text/plain").setBody("Hello Spring!")
|
||||
server.enqueue(response)
|
||||
}
|
||||
private fun prepareResponse() {
|
||||
val response = MockResponse()
|
||||
response.setHeader("Content-Type", "text/plain").setBody("Hello Spring!")
|
||||
server.enqueue(response)
|
||||
}
|
||||
|
||||
private fun anotherServer(): MockWebServer {
|
||||
val anotherServer = MockWebServer()
|
||||
@@ -251,34 +251,34 @@ class KotlinRestTemplateHttpServiceProxyTests {
|
||||
return anotherServer
|
||||
}
|
||||
|
||||
private interface TestService {
|
||||
private interface TestService {
|
||||
|
||||
@get:GetExchange("/test")
|
||||
val request: String
|
||||
@get:GetExchange("/test")
|
||||
val request: String
|
||||
|
||||
@GetExchange("/test/{id}")
|
||||
fun getRequestWithPathVariable(@PathVariable id: String): ResponseEntity<String>
|
||||
@GetExchange("/test/{id}")
|
||||
fun getRequestWithPathVariable(@PathVariable id: String): ResponseEntity<String>
|
||||
|
||||
@GetExchange("/test/{id}")
|
||||
fun getRequestWithDynamicUri(@Nullable uri: URI, @PathVariable id: String): Optional<String>
|
||||
@GetExchange("/test/{id}")
|
||||
fun getRequestWithDynamicUri(@Nullable uri: URI, @PathVariable id: String): Optional<String>
|
||||
|
||||
@PostExchange("/test")
|
||||
fun postRequestWithHeader(@RequestHeader("testHeaderName") testHeader: String,
|
||||
@RequestBody requestBody: String)
|
||||
@PostExchange("/test")
|
||||
fun postRequestWithHeader(@RequestHeader("testHeaderName") testHeader: String,
|
||||
@RequestBody requestBody: String)
|
||||
|
||||
@PostExchange(contentType = "application/x-www-form-urlencoded")
|
||||
fun postForm(@RequestParam params: MultiValueMap<String, String>)
|
||||
@PostExchange(contentType = "application/x-www-form-urlencoded")
|
||||
fun postForm(@RequestParam params: MultiValueMap<String, String>)
|
||||
|
||||
@PostExchange
|
||||
fun postMultipart(file: MultipartFile, @RequestPart anotherPart: String)
|
||||
@PostExchange
|
||||
fun postMultipart(file: MultipartFile, @RequestPart anotherPart: String)
|
||||
|
||||
@PutExchange
|
||||
fun putRequestWithCookies(@CookieValue firstCookie: String,
|
||||
@CookieValue secondCookie: String)
|
||||
@PutExchange
|
||||
fun putRequestWithCookies(@CookieValue firstCookie: String,
|
||||
@CookieValue secondCookie: String)
|
||||
|
||||
@PutExchange
|
||||
fun putRequestWithSameNameCookies(@CookieValue("testCookie") firstCookie: String,
|
||||
@CookieValue("testCookie") secondCookie: String)
|
||||
@PutExchange
|
||||
fun putRequestWithSameNameCookies(@CookieValue("testCookie") firstCookie: String,
|
||||
@CookieValue("testCookie") secondCookie: String)
|
||||
|
||||
@GetExchange("/greeting")
|
||||
fun getWithUriBuilderFactory(uriBuilderFactory: UriBuilderFactory?): ResponseEntity<String>
|
||||
@@ -289,6 +289,6 @@ class KotlinRestTemplateHttpServiceProxyTests {
|
||||
|
||||
@GetExchange("/greeting")
|
||||
fun getWithIgnoredUriBuilderFactory(uri: URI?, uriBuilderFactory: UriBuilderFactory?): ResponseEntity<String>
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -69,43 +69,43 @@ class KotlinHttpServiceMethodTests {
|
||||
verifyClientInvocation("exchangeForEntityFlux", object : ParameterizedTypeReference<String>() {})
|
||||
}
|
||||
|
||||
@Test
|
||||
fun blockingServiceWithExchangeResponseFunction() {
|
||||
val service = proxyFactory.createClient(BlockingFunctionsService::class.java)
|
||||
@Test
|
||||
fun blockingServiceWithExchangeResponseFunction() {
|
||||
val service = proxyFactory.createClient(BlockingFunctionsService::class.java)
|
||||
|
||||
val stringBody = service.stringBodyBlocking()
|
||||
assertThat(stringBody).isEqualTo("exchangeForBody")
|
||||
verifyTemplateInvocation("exchangeForBody", object : ParameterizedTypeReference<String>() {})
|
||||
val stringBody = service.stringBodyBlocking()
|
||||
assertThat(stringBody).isEqualTo("exchangeForBody")
|
||||
verifyTemplateInvocation("exchangeForBody", object : ParameterizedTypeReference<String>() {})
|
||||
|
||||
val listBody = service.listBodyBlocking()
|
||||
assertThat(listBody.size).isEqualTo(1)
|
||||
verifyTemplateInvocation("exchangeForBody", object : ParameterizedTypeReference<MutableList<String>>() {})
|
||||
val listBody = service.listBodyBlocking()
|
||||
assertThat(listBody.size).isEqualTo(1)
|
||||
verifyTemplateInvocation("exchangeForBody", object : ParameterizedTypeReference<MutableList<String>>() {})
|
||||
|
||||
val stringEntity = service.stringEntityBlocking()
|
||||
assertThat(stringEntity).isEqualTo(ResponseEntity.ok<String>("exchangeForEntity"))
|
||||
verifyTemplateInvocation("exchangeForEntity", object : ParameterizedTypeReference<String>() {})
|
||||
val stringEntity = service.stringEntityBlocking()
|
||||
assertThat(stringEntity).isEqualTo(ResponseEntity.ok<String>("exchangeForEntity"))
|
||||
verifyTemplateInvocation("exchangeForEntity", object : ParameterizedTypeReference<String>() {})
|
||||
|
||||
service.listEntityBlocking()
|
||||
verifyTemplateInvocation("exchangeForEntity", object : ParameterizedTypeReference<MutableList<String>>() {})
|
||||
}
|
||||
service.listEntityBlocking()
|
||||
verifyTemplateInvocation("exchangeForEntity", object : ParameterizedTypeReference<MutableList<String>>() {})
|
||||
}
|
||||
|
||||
@Test
|
||||
fun coroutineServiceWithExchangeResponseFunction() {
|
||||
assertThatIllegalStateException().isThrownBy {
|
||||
proxyFactory.createClient(FunctionsService::class.java)
|
||||
}
|
||||
@Test
|
||||
fun coroutineServiceWithExchangeResponseFunction() {
|
||||
assertThatIllegalStateException().isThrownBy {
|
||||
proxyFactory.createClient(FunctionsService::class.java)
|
||||
}
|
||||
|
||||
assertThatIllegalStateException().isThrownBy {
|
||||
proxyFactory.createClient(SuspendingFunctionsService::class.java)
|
||||
}
|
||||
}
|
||||
assertThatIllegalStateException().isThrownBy {
|
||||
proxyFactory.createClient(SuspendingFunctionsService::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
private fun verifyTemplateInvocation(methodReference: String, expectedBodyType: ParameterizedTypeReference<*>) {
|
||||
assertThat(exchangeAdapter.invokedMethodName).isEqualTo(methodReference)
|
||||
assertThat(exchangeAdapter.bodyType).isEqualTo(expectedBodyType)
|
||||
}
|
||||
private fun verifyTemplateInvocation(methodReference: String, expectedBodyType: ParameterizedTypeReference<*>) {
|
||||
assertThat(exchangeAdapter.invokedMethodName).isEqualTo(methodReference)
|
||||
assertThat(exchangeAdapter.bodyType).isEqualTo(expectedBodyType)
|
||||
}
|
||||
|
||||
private fun verifyClientInvocation(methodReference: String, expectedBodyType: ParameterizedTypeReference<*>) {
|
||||
private fun verifyClientInvocation(methodReference: String, expectedBodyType: ParameterizedTypeReference<*>) {
|
||||
assertThat(reactorExchangeAdapter.invokedMethodName).isEqualTo(methodReference)
|
||||
assertThat(reactorExchangeAdapter.bodyType).isEqualTo(expectedBodyType)
|
||||
}
|
||||
@@ -119,35 +119,35 @@ class KotlinHttpServiceMethodTests {
|
||||
fun flowEntity(): ResponseEntity<Flow<String>>
|
||||
}
|
||||
|
||||
private interface SuspendingFunctionsService : BlockingFunctionsService {
|
||||
private interface SuspendingFunctionsService : BlockingFunctionsService {
|
||||
|
||||
@GetExchange
|
||||
suspend fun stringBody(): String
|
||||
@GetExchange
|
||||
suspend fun stringBody(): String
|
||||
|
||||
@GetExchange
|
||||
suspend fun listBody(): MutableList<String>
|
||||
@GetExchange
|
||||
suspend fun listBody(): MutableList<String>
|
||||
|
||||
@GetExchange
|
||||
suspend fun stringEntity(): ResponseEntity<String>
|
||||
@GetExchange
|
||||
suspend fun stringEntity(): ResponseEntity<String>
|
||||
|
||||
@GetExchange
|
||||
suspend fun listEntity(): ResponseEntity<MutableList<String>>
|
||||
}
|
||||
@GetExchange
|
||||
suspend fun listEntity(): ResponseEntity<MutableList<String>>
|
||||
}
|
||||
|
||||
private interface BlockingFunctionsService {
|
||||
private interface BlockingFunctionsService {
|
||||
|
||||
@GetExchange
|
||||
fun stringBodyBlocking(): String
|
||||
@GetExchange
|
||||
fun stringBodyBlocking(): String
|
||||
|
||||
@GetExchange
|
||||
fun listBodyBlocking(): MutableList<String>
|
||||
@GetExchange
|
||||
fun listBodyBlocking(): MutableList<String>
|
||||
|
||||
@GetExchange
|
||||
fun stringEntityBlocking(): ResponseEntity<String>
|
||||
@GetExchange
|
||||
fun stringEntityBlocking(): ResponseEntity<String>
|
||||
|
||||
@GetExchange
|
||||
fun listEntityBlocking(): ResponseEntity<MutableList<String>>
|
||||
@GetExchange
|
||||
fun listEntityBlocking(): ResponseEntity<MutableList<String>>
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user