@ -1,5 +1,5 @@
@@ -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" ) ;
* you may not use this file except in compliance with the License .
@ -85,7 +85,7 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
@@ -85,7 +85,7 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
@Test
public void supportsReturnTypes ( ) throws Exception {
public void supportsReturnTypes ( ) {
assertThat ( this . handler . supportsReturnType (
on ( TestController . class ) . resolveReturnType ( ResponseBodyEmitter . class ) ) ) . isTrue ( ) ;
@ -105,7 +105,7 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
@@ -105,7 +105,7 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
}
@Test
public void doesNotSupportReturnTypes ( ) throws Exception {
public void doesNotSupportReturnTypes ( ) {
assertThat ( this . handler . supportsReturnType (
on ( TestController . class ) . resolveReturnType ( ResponseEntity . class , String . class ) ) ) . isFalse ( ) ;
@ -142,9 +142,10 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
@@ -142,9 +142,10 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
bean . setName ( "Jason" ) ;
emitter . send ( bean ) ;
assertThat ( this . response . getContentAsString ( ) ) . isEqualTo ( ( "{\"id\":1,\"name\":\"Joe\"}\n" +
"{\"id\":2,\"name\":\"John\"}\n" +
"{\"id\":3,\"name\":\"Jason\"}" ) ) ;
assertThat ( this . response . getContentAsString ( ) ) . isEqualTo ( ( "" "
{ "id" : 1 , "name" : "Joe" }
{ "id" : 2 , "name" : "John" }
{ "id" : 3 , "name" : "Jason" } "" " ) ) ;
MockAsyncContext asyncContext = ( MockAsyncContext ) this . request . getAsyncContext ( ) ;
assertThat ( asyncContext . getDispatchedPath ( ) ) . isNull ( ) ;
@ -212,13 +213,15 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
@@ -212,13 +213,15 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
comment ( "a test" ) . name ( "update" ) . id ( "1" ) . reconnectTime ( 5000L ) . data ( bean1 ) . data ( bean2 ) ) ;
assertThat ( this . response . getContentType ( ) ) . isEqualTo ( "text/event-stream" ) ;
assertThat ( this . response . getContentAsString ( ) ) . isEqualTo ( ( ":a test\n" +
"event:update\n" +
"id:1\n" +
"retry:5000\n" +
"data:{\"id\":1,\"name\":\"Joe\"}\n" +
"data:{\"id\":2,\"name\":\"John\"}\n" +
"\n" ) ) ;
assertThat ( this . response . getContentAsString ( ) ) . isEqualTo ( ( "" "
: a test
event : update
id : 1
retry : 5000
data : { "id" : 1 , "name" : "Joe" }
data : { "id" : 2 , "name" : "John" }
"" " ) ) ;
}
@Test
@ -227,17 +230,11 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
@@ -227,17 +230,11 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
this . request . addHeader ( "Accept" , "text/event-stream" ) ;
MethodParameter type = on ( TestController . class ) . resolveReturnType ( Flux . class , String . class ) ;
Sinks . Many < String > sink = Sinks . many ( ) . unicast ( ) . onBackpressureBuffer ( ) ;
this . handler . handleReturnValue ( sink . asFlux ( ) , type , this . mavContainer , this . webRequest ) ;
this . handler . handleReturnValue ( Flux . just ( "foo" , "bar" , "baz" ) , type , this . mavContainer , this . webRequest ) ;
assertThat ( this . request . isAsyncStarted ( ) ) . isTrue ( ) ;
assertThat ( this . response . getStatus ( ) ) . isEqualTo ( 200 ) ;
sink . tryEmitNext ( "foo" ) ;
sink . tryEmitNext ( "bar" ) ;
sink . tryEmitNext ( "baz" ) ;
sink . tryEmitComplete ( ) ;
assertThat ( this . response . getContentType ( ) ) . isEqualTo ( "text/event-stream" ) ;
assertThat ( this . response . getContentAsString ( ) ) . isEqualTo ( "data:foo\n\ndata:bar\n\ndata:baz\n\n" ) ;
}
@ -247,16 +244,12 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
@@ -247,16 +244,12 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
this . request . addHeader ( "Accept" , "text/event-stream" ) ;
IllegalStateException ex = new IllegalStateException ( "wah wah" ) ;
MethodParameter type = on ( TestController . class ) . resolveReturnType ( Flux . class , String . class ) ;
Sinks . Many < String > sink = Sinks . many ( ) . unicast ( ) . onBackpressureBuffer ( ) ;
this . handler . handleReturnValue ( sink . asFlux ( ) , type , this . mavContainer , this . webRequest ) ;
this . handler . handleReturnValue ( Flux . error ( ex ) , type , this . mavContainer , this . webRequest ) ;
assertThat ( this . request . isAsyncStarted ( ) ) . isTrue ( ) ;
IllegalStateException ex = new IllegalStateException ( "wah wah" ) ;
sink . tryEmitError ( ex ) ;
sink . tryEmitComplete ( ) ;
WebAsyncManager asyncManager = WebAsyncUtils . getAsyncManager ( this . webRequest ) ;
assertThat ( asyncManager . getConcurrentResult ( ) ) . isSameAs ( ex ) ;
assertThat ( this . response . getContentType ( ) ) . isNull ( ) ;
@ -290,8 +283,7 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
@@ -290,8 +283,7 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
@Test
public void responseEntityFlux ( ) throws Exception {
Sinks . Many < String > sink = Sinks . many ( ) . unicast ( ) . onBackpressureBuffer ( ) ;
ResponseEntity < Flux < String > > entity = ResponseEntity . ok ( ) . body ( sink . asFlux ( ) ) ;
ResponseEntity < Flux < String > > entity = ResponseEntity . ok ( ) . body ( Flux . just ( "foo" , "bar" , "baz" ) ) ;
ResolvableType bodyType = forClassWithGenerics ( Flux . class , String . class ) ;
MethodParameter type = on ( TestController . class ) . resolveReturnType ( ResponseEntity . class , bodyType ) ;
this . handler . handleReturnValue ( entity , type , this . mavContainer , this . webRequest ) ;
@ -299,11 +291,6 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
@@ -299,11 +291,6 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
assertThat ( this . request . isAsyncStarted ( ) ) . isTrue ( ) ;
assertThat ( this . response . getStatus ( ) ) . isEqualTo ( 200 ) ;
sink . tryEmitNext ( "foo" ) ;
sink . tryEmitNext ( "bar" ) ;
sink . tryEmitNext ( "baz" ) ;
sink . tryEmitComplete ( ) ;
assertThat ( this . response . getContentType ( ) ) . isEqualTo ( "text/plain" ) ;
assertThat ( this . response . getContentAsString ( ) ) . isEqualTo ( "foobarbaz" ) ;
}
@ -324,7 +311,7 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
@@ -324,7 +311,7 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
}
@SuppressWarnings ( "unused" )
@SuppressWarnings ( { "unused" , "ConstantConditions" } )
private static class TestController {
private ResponseBodyEmitter h1 ( ) { return null ; }