Support RenderingResponse in RouterFunctionDsl

Issue: SPR-17244
This commit is contained in:
Sebastien Deleuze
2018-09-05 16:46:12 +02:00
parent 259b2ca5f4
commit f8a0e3d084
2 changed files with 51 additions and 39 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,7 +43,7 @@ class RouterFunctionDslTests {
@Test
fun accept() {
val request = builder().header(ACCEPT, APPLICATION_ATOM_XML_VALUE).build()
val request = builder().uri(URI("/content")).header(ACCEPT, APPLICATION_ATOM_XML_VALUE).build()
StepVerifier.create(sampleRouter().route(request))
.expectNextCount(1)
.verifyComplete()
@@ -63,7 +63,7 @@ class RouterFunctionDslTests {
@Test
fun contentType() {
val request = builder().header(CONTENT_TYPE, APPLICATION_OCTET_STREAM_VALUE).build()
val request = builder().uri(URI("/content")).header(CONTENT_TYPE, APPLICATION_OCTET_STREAM_VALUE).build()
StepVerifier.create(sampleRouter().route(request))
.expectNextCount(1)
.verifyComplete()
@@ -112,6 +112,14 @@ class RouterFunctionDslTests {
.verifyComplete()
}
@Test
fun rendering() {
val request = builder().uri(URI("/rendering")).build()
StepVerifier.create(sampleRouter().route(request).flatMap { it.handle(request) })
.expectNextMatches { it is RenderingResponse}
.verifyComplete()
}
private fun sampleRouter() = router {
(GET("/foo/") or GET("/foos/")) { req -> handle(req) }
@@ -123,8 +131,10 @@ class RouterFunctionDslTests {
}
"/foo/" { handleFromClass(it) }
}
accept(APPLICATION_ATOM_XML, ::handle)
contentType(APPLICATION_OCTET_STREAM, ::handle)
"/content".nest {
accept(APPLICATION_ATOM_XML, ::handle)
contentType(APPLICATION_OCTET_STREAM, ::handle)
}
method(PATCH, ::handle)
headers { it.accept().contains(APPLICATION_JSON) }.nest {
GET("/api/foo/", ::handle)
@@ -141,6 +151,7 @@ class RouterFunctionDslTests {
}
}
path("/baz", ::handle)
GET("/rendering") { RenderingResponse.create("index").build() }
}
}