Search in sources :

Example 1 with MockServerHttpResponse

use of cn.taketoday.http.server.reactive.MockServerHttpResponse in project today-infrastructure by TAKETODAY.

the class ServerSentEventHttpMessageWriterTests method writeMultiLineString.

@ParameterizedDataBufferAllocatingTest
void writeMultiLineString(String displayName, DataBufferFactory bufferFactory) {
    super.bufferFactory = bufferFactory;
    MockServerHttpResponse outputMessage = new MockServerHttpResponse(super.bufferFactory);
    Flux<String> source = Flux.just("foo\nbar", "foo\nbaz");
    testWrite(source, outputMessage, String.class);
    StepVerifier.create(outputMessage.getBody()).consumeNextWith(stringConsumer("data:foo\ndata:bar\n\n")).consumeNextWith(stringConsumer("data:foo\ndata:baz\n\n")).expectComplete().verify();
}
Also used : MockServerHttpResponse(cn.taketoday.http.server.reactive.MockServerHttpResponse)

Example 2 with MockServerHttpResponse

use of cn.taketoday.http.server.reactive.MockServerHttpResponse in project today-infrastructure by TAKETODAY.

the class ServerSentEventHttpMessageWriterTests method writeServerSentEvent.

@ParameterizedDataBufferAllocatingTest
void writeServerSentEvent(String displayName, DataBufferFactory bufferFactory) {
    super.bufferFactory = bufferFactory;
    ServerSentEvent<?> event = ServerSentEvent.builder().data("bar").id("c42").event("foo").comment("bla\nbla bla\nbla bla bla").retry(Duration.ofMillis(123L)).build();
    MockServerHttpResponse outputMessage = new MockServerHttpResponse(super.bufferFactory);
    Mono<ServerSentEvent> source = Mono.just(event);
    testWrite(source, outputMessage, ServerSentEvent.class);
    StepVerifier.create(outputMessage.getBody()).consumeNextWith(stringConsumer("id:c42\nevent:foo\nretry:123\n:bla\n:bla bla\n:bla bla bla\ndata:bar\n\n")).expectComplete().verify();
}
Also used : MockServerHttpResponse(cn.taketoday.http.server.reactive.MockServerHttpResponse)

Example 3 with MockServerHttpResponse

use of cn.taketoday.http.server.reactive.MockServerHttpResponse in project today-framework by TAKETODAY.

the class ServerSentEventHttpMessageWriterTests method writePojoWithPrettyPrint.

@ParameterizedDataBufferAllocatingTest
// SPR-14899
void writePojoWithPrettyPrint(String displayName, DataBufferFactory bufferFactory) {
    super.bufferFactory = bufferFactory;
    ObjectMapper mapper = Jackson2ObjectMapperBuilder.json().indentOutput(true).build();
    this.messageWriter = new ServerSentEventHttpMessageWriter(new Jackson2JsonEncoder(mapper));
    MockServerHttpResponse outputMessage = new MockServerHttpResponse(super.bufferFactory);
    Flux<Pojo> source = Flux.just(new Pojo("foofoo", "barbar"), new Pojo("foofoofoo", "barbarbar"));
    testWrite(source, outputMessage, Pojo.class);
    StepVerifier.create(outputMessage.getBody()).consumeNextWith(stringConsumer("data:")).consumeNextWith(stringConsumer("{\n" + "data:  \"foo\" : \"foofoo\",\n" + "data:  \"bar\" : \"barbar\"\n" + "data:}")).consumeNextWith(stringConsumer("\n\n")).consumeNextWith(stringConsumer("data:")).consumeNextWith(stringConsumer("{\n" + "data:  \"foo\" : \"foofoofoo\",\n" + "data:  \"bar\" : \"barbarbar\"\n" + "data:}")).consumeNextWith(stringConsumer("\n\n")).expectComplete().verify();
}
Also used : MockServerHttpResponse(cn.taketoday.http.server.reactive.MockServerHttpResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Jackson2JsonEncoder(cn.taketoday.http.codec.json.Jackson2JsonEncoder)

Example 4 with MockServerHttpResponse

use of cn.taketoday.http.server.reactive.MockServerHttpResponse in project today-framework by TAKETODAY.

the class ServerSentEventHttpMessageWriterTests method writeString.

@ParameterizedDataBufferAllocatingTest
void writeString(String displayName, DataBufferFactory bufferFactory) {
    super.bufferFactory = bufferFactory;
    MockServerHttpResponse outputMessage = new MockServerHttpResponse(super.bufferFactory);
    Flux<String> source = Flux.just("foo", "bar");
    testWrite(source, outputMessage, String.class);
    StepVerifier.create(outputMessage.getBody()).consumeNextWith(stringConsumer("data:foo\n\n")).consumeNextWith(stringConsumer("data:bar\n\n")).expectComplete().verify();
}
Also used : MockServerHttpResponse(cn.taketoday.http.server.reactive.MockServerHttpResponse)

Example 5 with MockServerHttpResponse

use of cn.taketoday.http.server.reactive.MockServerHttpResponse in project today-framework by TAKETODAY.

the class ServerSentEventHttpMessageWriterTests method writeMultiLineString.

@ParameterizedDataBufferAllocatingTest
void writeMultiLineString(String displayName, DataBufferFactory bufferFactory) {
    super.bufferFactory = bufferFactory;
    MockServerHttpResponse outputMessage = new MockServerHttpResponse(super.bufferFactory);
    Flux<String> source = Flux.just("foo\nbar", "foo\nbaz");
    testWrite(source, outputMessage, String.class);
    StepVerifier.create(outputMessage.getBody()).consumeNextWith(stringConsumer("data:foo\ndata:bar\n\n")).consumeNextWith(stringConsumer("data:foo\ndata:baz\n\n")).expectComplete().verify();
}
Also used : MockServerHttpResponse(cn.taketoday.http.server.reactive.MockServerHttpResponse)

Aggregations

MockServerHttpResponse (cn.taketoday.http.server.reactive.MockServerHttpResponse)16 MediaType (cn.taketoday.http.MediaType)4 Charset (java.nio.charset.Charset)4 DefaultMultiValueMap (cn.taketoday.core.DefaultMultiValueMap)2 HttpHeaders (cn.taketoday.http.HttpHeaders)2 Jackson2JsonEncoder (cn.taketoday.http.codec.json.Jackson2JsonEncoder)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Test (org.junit.jupiter.api.Test)2