Search in sources :

Example 16 with ReactiveHttpInputMessage

use of cn.taketoday.http.ReactiveHttpInputMessage in project today-infrastructure by TAKETODAY.

the class BodyExtractorsTests method toDataBuffers.

@Test
public void toDataBuffers() {
    BodyExtractor<Flux<DataBuffer>, ReactiveHttpInputMessage> extractor = BodyExtractors.toDataBuffers();
    byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
    DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
    Flux<DataBuffer> body = Flux.just(dataBuffer);
    MockServerHttpRequest request = MockServerHttpRequest.post("/").body(body);
    Flux<DataBuffer> result = extractor.extract(request, this.context);
    StepVerifier.create(result).expectNext(dataBuffer).expectComplete().verify();
}
Also used : DefaultDataBuffer(cn.taketoday.core.io.buffer.DefaultDataBuffer) MockServerHttpRequest(cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpRequest) Flux(reactor.core.publisher.Flux) ReactiveHttpInputMessage(cn.taketoday.http.ReactiveHttpInputMessage) NettyDataBuffer(cn.taketoday.core.io.buffer.NettyDataBuffer) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) DefaultDataBuffer(cn.taketoday.core.io.buffer.DefaultDataBuffer) Test(org.junit.jupiter.api.Test)

Example 17 with ReactiveHttpInputMessage

use of cn.taketoday.http.ReactiveHttpInputMessage in project today-infrastructure by TAKETODAY.

the class BodyExtractorsTests method toMonoWithHints.

@Test
public void toMonoWithHints() {
    BodyExtractor<Mono<User>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(User.class);
    this.hints.put(JSON_VIEW_HINT, SafeToDeserialize.class);
    byte[] bytes = "{\"username\":\"foo\",\"password\":\"bar\"}".getBytes(StandardCharsets.UTF_8);
    DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
    Flux<DataBuffer> body = Flux.just(dataBuffer);
    MockServerHttpRequest request = MockServerHttpRequest.post("/").contentType(MediaType.APPLICATION_JSON).body(body);
    Mono<User> result = extractor.extract(request, this.context);
    StepVerifier.create(result).consumeNextWith(user -> {
        assertThat(user.getUsername()).isEqualTo("foo");
        assertThat(user.getPassword()).isNull();
    }).expectComplete().verify();
}
Also used : DefaultDataBuffer(cn.taketoday.core.io.buffer.DefaultDataBuffer) MockServerHttpRequest(cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpRequest) Mono(reactor.core.publisher.Mono) ReactiveHttpInputMessage(cn.taketoday.http.ReactiveHttpInputMessage) NettyDataBuffer(cn.taketoday.core.io.buffer.NettyDataBuffer) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) DefaultDataBuffer(cn.taketoday.core.io.buffer.DefaultDataBuffer) Test(org.junit.jupiter.api.Test)

Example 18 with ReactiveHttpInputMessage

use of cn.taketoday.http.ReactiveHttpInputMessage in project today-infrastructure by TAKETODAY.

the class BodyExtractorsTests method toMonoVoidAsClientWithEmptyBody.

@Test
public void toMonoVoidAsClientWithEmptyBody() {
    TestPublisher<DataBuffer> body = TestPublisher.create();
    BodyExtractor<Mono<Void>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(Void.class);
    MockClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK);
    response.setBody(body.flux());
    StepVerifier.create(extractor.extract(response, this.context)).then(() -> {
        body.assertWasSubscribed();
        body.complete();
    }).verifyComplete();
}
Also used : Mono(reactor.core.publisher.Mono) ReactiveHttpInputMessage(cn.taketoday.http.ReactiveHttpInputMessage) NettyDataBuffer(cn.taketoday.core.io.buffer.NettyDataBuffer) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) DefaultDataBuffer(cn.taketoday.core.io.buffer.DefaultDataBuffer) MockClientHttpResponse(cn.taketoday.web.testfixture.http.client.reactive.MockClientHttpResponse) Test(org.junit.jupiter.api.Test)

Example 19 with ReactiveHttpInputMessage

use of cn.taketoday.http.ReactiveHttpInputMessage in project today-infrastructure by TAKETODAY.

the class BodyExtractorsTests method toFlux.

@Test
public void toFlux() {
    BodyExtractor<Flux<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toFlux(String.class);
    byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
    DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
    Flux<DataBuffer> body = Flux.just(dataBuffer);
    MockServerHttpRequest request = MockServerHttpRequest.post("/").body(body);
    Flux<String> result = extractor.extract(request, this.context);
    StepVerifier.create(result).expectNext("foo").expectComplete().verify();
}
Also used : DefaultDataBuffer(cn.taketoday.core.io.buffer.DefaultDataBuffer) MockServerHttpRequest(cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpRequest) Flux(reactor.core.publisher.Flux) ReactiveHttpInputMessage(cn.taketoday.http.ReactiveHttpInputMessage) NettyDataBuffer(cn.taketoday.core.io.buffer.NettyDataBuffer) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) DefaultDataBuffer(cn.taketoday.core.io.buffer.DefaultDataBuffer) Test(org.junit.jupiter.api.Test)

Example 20 with ReactiveHttpInputMessage

use of cn.taketoday.http.ReactiveHttpInputMessage in project today-infrastructure by TAKETODAY.

the class BodyExtractorsTests method toMono.

@Test
public void toMono() {
    BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
    DefaultDataBufferFactory factory = DefaultDataBufferFactory.sharedInstance;
    DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
    Flux<DataBuffer> body = Flux.just(dataBuffer);
    MockServerHttpRequest request = MockServerHttpRequest.post("/").body(body);
    Mono<String> result = extractor.extract(request, this.context);
    StepVerifier.create(result).expectNext("foo").expectComplete().verify();
}
Also used : DefaultDataBuffer(cn.taketoday.core.io.buffer.DefaultDataBuffer) MockServerHttpRequest(cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpRequest) DefaultDataBufferFactory(cn.taketoday.core.io.buffer.DefaultDataBufferFactory) Mono(reactor.core.publisher.Mono) ReactiveHttpInputMessage(cn.taketoday.http.ReactiveHttpInputMessage) NettyDataBuffer(cn.taketoday.core.io.buffer.NettyDataBuffer) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) DefaultDataBuffer(cn.taketoday.core.io.buffer.DefaultDataBuffer) Test(org.junit.jupiter.api.Test)

Aggregations

ReactiveHttpInputMessage (cn.taketoday.http.ReactiveHttpInputMessage)22 Test (org.junit.jupiter.api.Test)22 DataBuffer (cn.taketoday.core.io.buffer.DataBuffer)20 DefaultDataBuffer (cn.taketoday.core.io.buffer.DefaultDataBuffer)20 NettyDataBuffer (cn.taketoday.core.io.buffer.NettyDataBuffer)20 MockServerHttpRequest (cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpRequest)18 Mono (reactor.core.publisher.Mono)16 Flux (reactor.core.publisher.Flux)10 MultiValueMap (cn.taketoday.core.MultiValueMap)8 MockClientHttpResponse (cn.taketoday.web.testfixture.http.client.reactive.MockClientHttpResponse)8 HashMap (java.util.HashMap)8 LinkedHashMap (java.util.LinkedHashMap)8 Map (java.util.Map)8 DefaultDataBufferFactory (cn.taketoday.core.io.buffer.DefaultDataBufferFactory)6 DecoderHttpMessageReader (cn.taketoday.http.codec.DecoderHttpMessageReader)6 FormHttpMessageReader (cn.taketoday.http.codec.FormHttpMessageReader)6 HttpMessageReader (cn.taketoday.http.codec.HttpMessageReader)6 DefaultPartHttpMessageReader (cn.taketoday.http.codec.multipart.DefaultPartHttpMessageReader)6 MultipartHttpMessageReader (cn.taketoday.http.codec.multipart.MultipartHttpMessageReader)6 ServerHttpResponse (cn.taketoday.http.server.reactive.ServerHttpResponse)6