Search in sources :

Example 1 with MockServerHttpResponse

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

the class BodyInsertersTests method ofObject.

@Test
public void ofObject() {
    User body = new User("foo", "bar");
    BodyInserter<User, ReactiveHttpOutputMessage> inserter = BodyInserters.fromValue(body);
    MockServerHttpResponse response = new MockServerHttpResponse();
    Mono<Void> result = inserter.insert(response, this.context);
    StepVerifier.create(result).expectComplete().verify();
    StepVerifier.create(response.getBodyAsString()).expectNext("{\"username\":\"foo\",\"password\":\"bar\"}").expectComplete().verify();
}
Also used : ReactiveHttpOutputMessage(cn.taketoday.http.ReactiveHttpOutputMessage) MockServerHttpResponse(cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpResponse) Test(org.junit.jupiter.api.Test)

Example 2 with MockServerHttpResponse

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

the class BodyInsertersTests method ofObjectWithHints.

@Test
public void ofObjectWithHints() {
    User body = new User("foo", "bar");
    BodyInserter<User, ReactiveHttpOutputMessage> inserter = BodyInserters.fromValue(body);
    this.hints.put(JSON_VIEW_HINT, SafeToSerialize.class);
    MockServerHttpResponse response = new MockServerHttpResponse();
    Mono<Void> result = inserter.insert(response, this.context);
    StepVerifier.create(result).expectComplete().verify();
    StepVerifier.create(response.getBodyAsString()).expectNext("{\"username\":\"foo\"}").expectComplete().verify();
}
Also used : ReactiveHttpOutputMessage(cn.taketoday.http.ReactiveHttpOutputMessage) MockServerHttpResponse(cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpResponse) Test(org.junit.jupiter.api.Test)

Example 3 with MockServerHttpResponse

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

the class BodyInsertersTests method ofPublisher.

@Test
public void ofPublisher() {
    Flux<String> body = Flux.just("foo");
    BodyInserter<Flux<String>, ReactiveHttpOutputMessage> inserter = BodyInserters.fromPublisher(body, String.class);
    MockServerHttpResponse response = new MockServerHttpResponse();
    Mono<Void> result = inserter.insert(response, this.context);
    StepVerifier.create(result).expectComplete().verify();
    StepVerifier.create(response.getBody()).consumeNextWith(buf -> {
        String actual = buf.toString(UTF_8);
        assertThat(actual).isEqualTo("foo");
    }).expectComplete().verify();
}
Also used : ReactiveHttpOutputMessage(cn.taketoday.http.ReactiveHttpOutputMessage) Flux(reactor.core.publisher.Flux) MockServerHttpResponse(cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpResponse) Test(org.junit.jupiter.api.Test)

Example 4 with MockServerHttpResponse

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

the class BodyInsertersTests method ofProducerWithMono.

@Test
public void ofProducerWithMono() {
    Mono<User> body = Mono.just(new User("foo", "bar"));
    BodyInserter<?, ReactiveHttpOutputMessage> inserter = BodyInserters.fromProducer(body, User.class);
    MockServerHttpResponse response = new MockServerHttpResponse();
    Mono<Void> result = inserter.insert(response, this.context);
    StepVerifier.create(result).expectComplete().verify();
    StepVerifier.create(response.getBodyAsString()).expectNext("{\"username\":\"foo\",\"password\":\"bar\"}").expectComplete().verify();
}
Also used : ReactiveHttpOutputMessage(cn.taketoday.http.ReactiveHttpOutputMessage) MockServerHttpResponse(cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpResponse) Test(org.junit.jupiter.api.Test)

Example 5 with MockServerHttpResponse

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

the class BodyInsertersTests method ofServerSentEventFlux.

@Test
public void ofServerSentEventFlux() {
    ServerSentEvent<String> event = ServerSentEvent.builder("foo").build();
    Flux<ServerSentEvent<String>> body = Flux.just(event);
    BodyInserter<Flux<ServerSentEvent<String>>, ServerHttpResponse> inserter = BodyInserters.fromServerSentEvents(body);
    MockServerHttpResponse response = new MockServerHttpResponse();
    Mono<Void> result = inserter.insert(response, this.context);
    StepVerifier.create(result).expectNextCount(0).expectComplete().verify();
}
Also used : ServerSentEvent(cn.taketoday.http.codec.ServerSentEvent) Flux(reactor.core.publisher.Flux) MockServerHttpResponse(cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpResponse) ServerHttpResponse(cn.taketoday.http.server.reactive.ServerHttpResponse) MockServerHttpResponse(cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

MockServerHttpResponse (cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpResponse)22 Test (org.junit.jupiter.api.Test)22 ReactiveHttpOutputMessage (cn.taketoday.http.ReactiveHttpOutputMessage)18 Flux (reactor.core.publisher.Flux)6 ClassPathResource (cn.taketoday.core.io.ClassPathResource)4 Resource (cn.taketoday.core.io.Resource)4 LinkedMultiValueMap (cn.taketoday.core.LinkedMultiValueMap)2 MultiValueMap (cn.taketoday.core.MultiValueMap)2 DataBuffer (cn.taketoday.core.io.buffer.DataBuffer)2 DefaultDataBuffer (cn.taketoday.core.io.buffer.DefaultDataBuffer)2 ResourceHttpMessageWriter (cn.taketoday.http.codec.ResourceHttpMessageWriter)2 ServerSentEvent (cn.taketoday.http.codec.ServerSentEvent)2 ServerHttpResponse (cn.taketoday.http.server.reactive.ServerHttpResponse)2 MockServerHttpRequest (cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpRequest)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2