@ -28,14 +28,19 @@ import reactor.core.publisher.Mono;
@@ -28,14 +28,19 @@ import reactor.core.publisher.Mono;
import reactor.test.StepVerifier ;
import org.springframework.http.HttpHeaders ;
import org.springframework.http.MediaType ;
import org.springframework.http.ResponseCookie ;
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest ;
import org.springframework.mock.web.test.server.MockServerWebExchange ;
import org.springframework.util.LinkedMultiValueMap ;
import org.springframework.util.MultiValueMap ;
import org.springframework.web.reactive.result.view.AbstractView ;
import org.springframework.web.reactive.result.view.View ;
import org.springframework.web.reactive.result.view.ViewResolver ;
import org.springframework.web.reactive.result.view.ViewResolverSupport ;
import org.springframework.web.server.ServerWebExchange ;
import static org.junit.Assert.assertEquals ;
import static org.mockito.Mockito.* ;
/ * *
@ -143,4 +148,37 @@ public class DefaultRenderingResponseTests {
@@ -143,4 +148,37 @@ public class DefaultRenderingResponseTests {
. verify ( ) ;
}
@Test
public void defaultContentType ( ) throws Exception {
Mono < RenderingResponse > result = RenderingResponse . create ( "view" ) . build ( ) ;
MockServerWebExchange exchange = MockServerWebExchange . from ( MockServerHttpRequest . get ( "http://localhost" ) ) ;
TestView view = new TestView ( ) ;
ViewResolver viewResolver = mock ( ViewResolver . class ) ;
when ( viewResolver . resolveViewName ( any ( ) , any ( ) ) ) . thenReturn ( Mono . just ( view ) ) ;
List < ViewResolver > viewResolvers = new ArrayList < > ( ) ;
viewResolvers . add ( viewResolver ) ;
ServerResponse . Context context = mock ( ServerResponse . Context . class ) ;
when ( context . viewResolvers ( ) ) . thenReturn ( viewResolvers ) ;
StepVerifier . create ( result . flatMap ( response - > response . writeTo ( exchange , context ) ) )
. verifyComplete ( ) ;
assertEquals ( ViewResolverSupport . DEFAULT_CONTENT_TYPE , exchange . getResponse ( ) . getHeaders ( ) . getContentType ( ) ) ;
}
private static class TestView extends AbstractView {
@Override
protected Mono < Void > renderInternal ( Map < String , Object > renderAttributes ,
MediaType contentType , ServerWebExchange exchange ) {
return Mono . empty ( ) ;
}
}
}