Skip to content

Commit

Permalink
Merge branch 'master' of github.com:micronaut-projects/micronaut-core
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Oct 8, 2018
2 parents bb8ffa4 + 2447c21 commit cb27ee9
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.micronaut.http.server.netty.stream

import io.micronaut.core.io.buffer.ByteBuffer
import io.reactivex.Flowable
import io.micronaut.context.ApplicationContext
import io.micronaut.http.HttpRequest
Expand All @@ -24,7 +25,9 @@ import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.micronaut.http.client.RxStreamingHttpClient
import io.micronaut.runtime.server.EmbeddedServer
import io.reactivex.Single
import spock.lang.AutoCleanup
import spock.lang.Ignore
import spock.lang.Shared
import spock.lang.Specification

Expand Down Expand Up @@ -54,12 +57,32 @@ class JsonStreamSpec extends Specification {
RxStreamingHttpClient streamingHttpClient = embeddedServer.applicationContext.createBean(RxStreamingHttpClient, embeddedServer.getURL())

HttpResponse response = streamingHttpClient.exchangeStream(HttpRequest.GET('/json/stream/custom')).blockingFirst()
List<Book> books = streamingHttpClient.jsonStream(HttpRequest.GET('/json/stream/custom'), Book).toList().blockingGet()

expect:
response.contentType.isPresent()
response.contentType.get() == MediaType.APPLICATION_JSON_STREAM_TYPE
response.header("Server") == "JsonStreamSpec"
response.header("Date")
response.header("X-MyHeader") == "42"
books[0].title == "The Stand"
books[1].title == "The Shining"
}

void "test json stream response content type with a response return single body"() {
given:
RxStreamingHttpClient streamingHttpClient = embeddedServer.applicationContext.createBean(RxStreamingHttpClient, embeddedServer.getURL())

HttpResponse response = streamingHttpClient.exchangeStream(HttpRequest.GET('/json/stream/single')).blockingFirst()
Book book = streamingHttpClient.jsonStream(HttpRequest.GET('/json/stream/single'), Book).blockingFirst()

expect:
response.contentType.isPresent()
response.contentType.get() == MediaType.APPLICATION_JSON_STREAM_TYPE
response.header("Server") == "JsonStreamSpec"
response.header("Date")
response.header("X-MyHeader") == "42"
book.title == "The Stand"
}

@Controller("/json/stream")
Expand All @@ -72,7 +95,12 @@ class JsonStreamSpec extends Specification {

@Get(uri = "/custom", produces = MediaType.APPLICATION_JSON_STREAM)
HttpResponse<Flowable<Book>> streamResponse() {
return HttpResponse.ok(Flowable.just(new Book(title: "The Stand"), new Book(title: "The Shining")))
return HttpResponse.ok(Flowable.just(new Book(title: "The Stand"), new Book(title: "The Shining"))).header("X-MyHeader", "42")
}

@Get(uri = "/single", produces = MediaType.APPLICATION_JSON_STREAM)
HttpResponse<Single<Book>> streamSingleResponse() {
return HttpResponse.ok(Single.just(new Book(title: "The Stand"))).header("X-MyHeader", "42")
}

}
Expand Down

0 comments on commit cb27ee9

Please sign in to comment.