@ -128,24 +128,6 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
@@ -128,24 +128,6 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
assertEquals ( expected , performGet ( "/raw-observable" , null , String . class ) . getBody ( ) ) ;
}
@Test
public void handleWithThrownException ( ) throws Exception {
String expected = "Recovered from error: Boo" ;
assertEquals ( expected , performGet ( "/thrown-exception" , null , String . class ) . getBody ( ) ) ;
}
@Test
public void handleWithErrorSignal ( ) throws Exception {
String expected = "Recovered from error: Boo" ;
assertEquals ( expected , performGet ( "/error-signal" , null , String . class ) . getBody ( ) ) ;
}
@Test
public void streamResult ( ) throws Exception {
String [ ] expected = { "0" , "1" , "2" , "3" , "4" } ;
assertArrayEquals ( expected , performGet ( "/stream-result" , null , String [ ] . class ) . getBody ( ) ) ;
}
@Test
public void serializeAsPojo ( ) throws Exception {
Person expected = new Person ( "Robert" ) ;
@ -158,12 +140,6 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
@@ -158,12 +140,6 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
assertEquals ( expected , performGet ( "/completable-future" , JSON , Person . class ) . getBody ( ) ) ;
}
@Test
public void serializeAsMonoResponseEntity ( ) throws Exception {
Person expected = new Person ( "Robert" ) ;
assertEquals ( expected , performGet ( "/monoResponseEntity" , JSON , Person . class ) . getBody ( ) ) ;
}
@Test
public void serializeAsMono ( ) throws Exception {
Person expected = new Person ( "Robert" ) ;
@ -176,6 +152,12 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
@@ -176,6 +152,12 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
assertEquals ( expected , performGet ( "/single" , JSON , Person . class ) . getBody ( ) ) ;
}
@Test
public void serializeAsMonoResponseEntity ( ) throws Exception {
Person expected = new Person ( "Robert" ) ;
assertEquals ( expected , performGet ( "/monoResponseEntity" , JSON , Person . class ) . getBody ( ) ) ;
}
@Test
public void serializeAsList ( ) throws Exception {
List < ? > expected = asList ( new Person ( "Robert" ) , new Person ( "Marie" ) ) ;
@ -201,30 +183,14 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
@@ -201,30 +183,14 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
}
@Test
public void serializeAsReactorStream ( ) throws Exception {
List < ? > expected = asList ( new Person ( "Robert" ) , new Person ( "Marie" ) ) ;
assertEquals ( expected , performGet ( "/stream" , JSON , PERSON_LIST ) . getBody ( ) ) ;
}
@Test
public void publisherCapitalize ( ) throws Exception {
List < ? > req = asList ( new Person ( "Robert" ) , new Person ( "Marie" ) ) ;
List < ? > res = asList ( new Person ( "ROBERT" ) , new Person ( "MARIE" ) ) ;
assertEquals ( res , performPost ( "/publisher-capitalize" , JSON , req , JSON , PERSON_LIST ) . getBody ( ) ) ;
}
@Test
public void fluxCapitalize ( ) throws Exception {
List < ? > req = asList ( new Person ( "Robert" ) , new Person ( "Marie" ) ) ;
List < ? > res = asList ( new Person ( "ROBERT" ) , new Person ( "MARIE" ) ) ;
assertEquals ( res , performPost ( "/flux-capitalize" , JSON , req , JSON , PERSON_LIST ) . getBody ( ) ) ;
}
public void resource ( ) throws Exception {
ResponseEntity < byte [ ] > response = performGet ( "/resource" , null , byte [ ] . class ) ;
@Test
public void observableCapitalize ( ) throws Exception {
List < ? > req = asList ( new Person ( "Robert" ) , new Person ( "Marie" ) ) ;
List < ? > res = asList ( new Person ( "ROBERT" ) , new Person ( "MARIE" ) ) ;
assertEquals ( res , performPost ( "/observable-capitalize" , JSON , req , JSON , PERSON_LIST ) . getBody ( ) ) ;
assertEquals ( HttpStatus . OK , response . getStatusCode ( ) ) ;
assertTrue ( response . hasBody ( ) ) ;
assertEquals ( 951 , response . getHeaders ( ) . getContentLength ( ) ) ;
assertEquals ( 951 , response . getBody ( ) . length ) ;
assertEquals ( new MediaType ( "image" , "x-png" ) , response . getHeaders ( ) . getContentType ( ) ) ;
}
@Test
@ -233,7 +199,7 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
@@ -233,7 +199,7 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
performPost ( "/person-capitalize" , JSON , new Person ( "Robert" ) ,
JSON , Person . class ) . getBody ( ) ) ;
}
@Test
public void completableFutureCapitalize ( ) throws Exception {
assertEquals ( new Person ( "ROBERT" ) ,
@ -255,6 +221,27 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
@@ -255,6 +221,27 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
JSON , Person . class ) . getBody ( ) ) ;
}
@Test
public void publisherCapitalize ( ) throws Exception {
List < ? > req = asList ( new Person ( "Robert" ) , new Person ( "Marie" ) ) ;
List < ? > res = asList ( new Person ( "ROBERT" ) , new Person ( "MARIE" ) ) ;
assertEquals ( res , performPost ( "/publisher-capitalize" , JSON , req , JSON , PERSON_LIST ) . getBody ( ) ) ;
}
@Test
public void fluxCapitalize ( ) throws Exception {
List < ? > req = asList ( new Person ( "Robert" ) , new Person ( "Marie" ) ) ;
List < ? > res = asList ( new Person ( "ROBERT" ) , new Person ( "MARIE" ) ) ;
assertEquals ( res , performPost ( "/flux-capitalize" , JSON , req , JSON , PERSON_LIST ) . getBody ( ) ) ;
}
@Test
public void observableCapitalize ( ) throws Exception {
List < ? > req = asList ( new Person ( "Robert" ) , new Person ( "Marie" ) ) ;
List < ? > res = asList ( new Person ( "ROBERT" ) , new Person ( "MARIE" ) ) ;
assertEquals ( res , performPost ( "/observable-capitalize" , JSON , req , JSON , PERSON_LIST ) . getBody ( ) ) ;
}
@Test
public void publisherCreate ( ) throws Exception {
ResponseEntity < Void > entity = performPost ( "/publisher-create" , JSON ,
@ -310,20 +297,27 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
@@ -310,20 +297,27 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
}
@Test
public void html ( ) throws Exception {
String expected = "<html><body>Hello: Jason!</body></html>" ;
assertEquals ( expected , performGet ( "/html?name=Jason" , MediaType . TEXT_HTML , String . class ) . getBody ( ) ) ;
public void streamResult ( ) throws Exception {
String [ ] expected = { "0" , "1" , "2" , "3" , "4" } ;
assertArray Equals ( expected , performGet ( "/stream-result" , null , String [ ] . class ) . getBody ( ) ) ;
}
@Test
public void resource ( ) throws Exception {
ResponseEntity < byte [ ] > response = performGet ( "/resource" , null , byte [ ] . class ) ;
public void handleWithThrownException ( ) throws Exception {
String expected = "Recovered from error: Boo" ;
assertEquals ( expected , performGet ( "/thrown-exception" , null , String . class ) . getBody ( ) ) ;
}
assertEquals ( HttpStatus . OK , response . getStatusCode ( ) ) ;
assertTrue ( response . hasBody ( ) ) ;
assertEquals ( 951 , response . getHeaders ( ) . getContentLength ( ) ) ;
assertEquals ( 951 , response . getBody ( ) . length ) ;
assertEquals ( new MediaType ( "image" , "x-png" ) , response . getHeaders ( ) . getContentType ( ) ) ;
@Test
public void handleWithErrorSignal ( ) throws Exception {
String expected = "Recovered from error: Boo" ;
assertEquals ( expected , performGet ( "/error-signal" , null , String . class ) . getBody ( ) ) ;
}
@Test
public void html ( ) throws Exception {
String expected = "<html><body>Hello: Jason!</body></html>" ;
assertEquals ( expected , performGet ( "/html?name=Jason" , MediaType . TEXT_HTML , String . class ) . getBody ( ) ) ;
}
@ -410,15 +404,7 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
@@ -410,15 +404,7 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
return Flux . just ( "Hello " , name , "!" ) ;
}
@RequestMapping ( "/person" )
public Person personResponseBody ( ) {
return new Person ( "Robert" ) ;
}
@RequestMapping ( "/completable-future" )
public CompletableFuture < Person > completableFutureResponseBody ( ) {
return CompletableFuture . completedFuture ( new Person ( "Robert" ) ) ;
}
// Response body with "raw" data (DataBuffer)
@RequestMapping ( "/raw" )
public Publisher < ByteBuffer > rawResponseBody ( ) {
@ -428,11 +414,6 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
@@ -428,11 +414,6 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
ResolvableType . forClass ( Person . class ) , JSON ) . map ( DataBuffer : : asByteBuffer ) ;
}
@RequestMapping ( "/stream-result" )
public Publisher < Long > stringStreamResponseBody ( ) {
return Flux . interval ( 100 ) . take ( 5 ) ;
}
@RequestMapping ( "/raw-flux" )
public Flux < ByteBuffer > rawFluxResponseBody ( ) {
return Flux . just ( ByteBuffer . wrap ( "Hello!" . getBytes ( ) ) ) ;
@ -443,10 +424,16 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
@@ -443,10 +424,16 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
return Observable . just ( ByteBuffer . wrap ( "Hello!" . getBytes ( ) ) ) ;
}
@RequestMapping ( "/monoResponseEntity" )
public ResponseEntity < Mono < Person > > monoResponseEntity ( ) {
Mono < Person > body = Mono . just ( new Person ( "Robert" ) ) ;
return ResponseEntity . ok ( body ) ;
// Response body with Person Object(s) to "serialize"
@RequestMapping ( "/person" )
public Person personResponseBody ( ) {
return new Person ( "Robert" ) ;
}
@RequestMapping ( "/completable-future" )
public CompletableFuture < Person > completableFutureResponseBody ( ) {
return CompletableFuture . completedFuture ( new Person ( "Robert" ) ) ;
}
@RequestMapping ( "/mono" )
@ -459,6 +446,12 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
@@ -459,6 +446,12 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
return Single . just ( new Person ( "Robert" ) ) ;
}
@RequestMapping ( "/monoResponseEntity" )
public ResponseEntity < Mono < Person > > monoResponseEntity ( ) {
Mono < Person > body = Mono . just ( new Person ( "Robert" ) ) ;
return ResponseEntity . ok ( body ) ;
}
@RequestMapping ( "/list" )
public List < Person > listResponseBody ( ) {
return asList ( new Person ( "Robert" ) , new Person ( "Marie" ) ) ;
@ -479,38 +472,21 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
@@ -479,38 +472,21 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
return Observable . just ( new Person ( "Robert" ) , new Person ( "Marie" ) ) ;
}
@RequestMapping ( "/stream" )
public Flux < Person > reactorStreamResponseBody ( ) {
return Flux . just ( new Person ( "Robert" ) , new Person ( "Marie" ) ) ;
}
@RequestMapping ( "/publisher-capitalize" )
public Publisher < Person > publisherCapitalize ( @RequestBody Publisher < Person > persons ) {
return Flux
. from ( persons )
. map ( person - > new Person ( person . getName ( ) . toUpperCase ( ) ) ) ;
}
// ResponseBody with Resource
@RequestMapping ( "/flux-capitalize" )
public Flux < Person > fluxCapitalize ( @RequestBody Flux < Person > persons ) {
return persons . map ( person - > new Person ( person . getName ( ) . toUpperCase ( ) ) ) ;
}
@RequestMapping ( "/observable-capitalize" )
public Observable < Person > observableCapitalize ( @RequestBody Observable < Person > persons ) {
return persons . map ( person - > new Person ( person . getName ( ) . toUpperCase ( ) ) ) ;
@RequestMapping ( "/resource" )
@ResponseBody
public Resource resource ( ) {
return new ClassPathResource ( "spring.png" , ZeroCopyIntegrationTests . class ) ;
}
@RequestMapping ( "/stream-create" )
public Publisher < Void > streamCreate ( @RequestBody Flux < Person > personStream ) {
return personStream . collectList ( ) . doOnSuccess ( persons : : addAll ) . then ( ) ;
}
// RequestBody -> ResponseBody with Person "capitalize" name transformation
@RequestMapping ( "/person-capitalize" )
public Person personCapitalize ( @RequestBody Person person ) {
return new Person ( person . getName ( ) . toUpperCase ( ) ) ;
}
@RequestMapping ( "/completable-future-capitalize" )
public CompletableFuture < Person > completableFutureCapitalize (
@RequestBody CompletableFuture < Person > personFuture ) {
@ -527,6 +503,30 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
@@ -527,6 +503,30 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
return personFuture . map ( person - > new Person ( person . getName ( ) . toUpperCase ( ) ) ) ;
}
@RequestMapping ( "/publisher-capitalize" )
public Publisher < Person > publisherCapitalize ( @RequestBody Publisher < Person > persons ) {
return Flux
. from ( persons )
. map ( person - > new Person ( person . getName ( ) . toUpperCase ( ) ) ) ;
}
@RequestMapping ( "/flux-capitalize" )
public Flux < Person > fluxCapitalize ( @RequestBody Flux < Person > persons ) {
return persons . map ( person - > new Person ( person . getName ( ) . toUpperCase ( ) ) ) ;
}
@RequestMapping ( "/observable-capitalize" )
public Observable < Person > observableCapitalize ( @RequestBody Observable < Person > persons ) {
return persons . map ( person - > new Person ( person . getName ( ) . toUpperCase ( ) ) ) ;
}
// Request body with Objects to "create"
@RequestMapping ( "/stream-create" )
public Publisher < Void > streamCreate ( @RequestBody Flux < Person > personStream ) {
return personStream . collectList ( ) . doOnSuccess ( persons : : addAll ) . then ( ) ;
}
@RequestMapping ( "/publisher-create" )
public Publisher < Void > publisherCreate ( @RequestBody Publisher < Person > personStream ) {
return Flux . from ( personStream ) . doOnNext ( persons : : add ) . then ( ) ;
@ -542,6 +542,15 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
@@ -542,6 +542,15 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
return personStream . toList ( ) . doOnNext ( persons : : addAll ) . flatMap ( document - > Observable . empty ( ) ) ;
}
// Async stream
@RequestMapping ( "/stream-result" )
public Publisher < Long > stringStreamResponseBody ( ) {
return Flux . interval ( 100 ) . take ( 5 ) ;
}
// Error handling
@RequestMapping ( "/thrown-exception" )
public Publisher < String > handleAndThrowException ( ) {
throw new IllegalStateException ( "Boo" ) ;
@ -557,12 +566,6 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
@@ -557,12 +566,6 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
return Mono . just ( "Recovered from error: " + ex . getMessage ( ) ) ;
}
@RequestMapping ( "/resource" )
@ResponseBody
public Resource resource ( ) {
return new ClassPathResource ( "spring.png" , ZeroCopyIntegrationTests . class ) ;
}
//TODO add mixed and T request mappings tests
}