Search in sources :

Example 1 with ServerHttpResponse

use of cn.taketoday.http.server.reactive.ServerHttpResponse 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)

Example 2 with ServerHttpResponse

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

the class BodyExtractorsTests method toFluxUnacceptable.

@Test
public void toFluxUnacceptable() {
    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("/").contentType(MediaType.APPLICATION_JSON).body(body);
    BodyExtractor.Context emptyContext = new BodyExtractor.Context() {

        @Override
        public List<HttpMessageReader<?>> messageReaders() {
            return Collections.emptyList();
        }

        @Override
        public Optional<ServerHttpResponse> serverResponse() {
            return Optional.empty();
        }

        @Override
        public Map<String, Object> hints() {
            return Collections.emptyMap();
        }
    };
    Flux<String> result = extractor.extract(request, emptyContext);
    StepVerifier.create(result).expectError(UnsupportedMediaTypeException.class).verify();
}
Also used : DefaultDataBuffer(cn.taketoday.core.io.buffer.DefaultDataBuffer) Flux(reactor.core.publisher.Flux) ServerHttpResponse(cn.taketoday.http.server.reactive.ServerHttpResponse) DefaultPartHttpMessageReader(cn.taketoday.http.codec.multipart.DefaultPartHttpMessageReader) FormHttpMessageReader(cn.taketoday.http.codec.FormHttpMessageReader) MultipartHttpMessageReader(cn.taketoday.http.codec.multipart.MultipartHttpMessageReader) DecoderHttpMessageReader(cn.taketoday.http.codec.DecoderHttpMessageReader) HttpMessageReader(cn.taketoday.http.codec.HttpMessageReader) MockServerHttpRequest(cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpRequest) 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 3 with ServerHttpResponse

use of cn.taketoday.http.server.reactive.ServerHttpResponse in project today-framework 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)

Example 4 with ServerHttpResponse

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

the class BodyExtractorsTests method toFluxUnacceptable.

@Test
public void toFluxUnacceptable() {
    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("/").contentType(MediaType.APPLICATION_JSON).body(body);
    BodyExtractor.Context emptyContext = new BodyExtractor.Context() {

        @Override
        public List<HttpMessageReader<?>> messageReaders() {
            return Collections.emptyList();
        }

        @Override
        public Optional<ServerHttpResponse> serverResponse() {
            return Optional.empty();
        }

        @Override
        public Map<String, Object> hints() {
            return Collections.emptyMap();
        }
    };
    Flux<String> result = extractor.extract(request, emptyContext);
    StepVerifier.create(result).expectError(UnsupportedMediaTypeException.class).verify();
}
Also used : DefaultDataBuffer(cn.taketoday.core.io.buffer.DefaultDataBuffer) Flux(reactor.core.publisher.Flux) ServerHttpResponse(cn.taketoday.http.server.reactive.ServerHttpResponse) DefaultPartHttpMessageReader(cn.taketoday.http.codec.multipart.DefaultPartHttpMessageReader) FormHttpMessageReader(cn.taketoday.http.codec.FormHttpMessageReader) MultipartHttpMessageReader(cn.taketoday.http.codec.multipart.MultipartHttpMessageReader) DecoderHttpMessageReader(cn.taketoday.http.codec.DecoderHttpMessageReader) HttpMessageReader(cn.taketoday.http.codec.HttpMessageReader) MockServerHttpRequest(cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpRequest) 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

ServerHttpResponse (cn.taketoday.http.server.reactive.ServerHttpResponse)4 Test (org.junit.jupiter.api.Test)4 Flux (reactor.core.publisher.Flux)4 DataBuffer (cn.taketoday.core.io.buffer.DataBuffer)2 DefaultDataBuffer (cn.taketoday.core.io.buffer.DefaultDataBuffer)2 NettyDataBuffer (cn.taketoday.core.io.buffer.NettyDataBuffer)2 ReactiveHttpInputMessage (cn.taketoday.http.ReactiveHttpInputMessage)2 DecoderHttpMessageReader (cn.taketoday.http.codec.DecoderHttpMessageReader)2 FormHttpMessageReader (cn.taketoday.http.codec.FormHttpMessageReader)2 HttpMessageReader (cn.taketoday.http.codec.HttpMessageReader)2 ServerSentEvent (cn.taketoday.http.codec.ServerSentEvent)2 DefaultPartHttpMessageReader (cn.taketoday.http.codec.multipart.DefaultPartHttpMessageReader)2 MultipartHttpMessageReader (cn.taketoday.http.codec.multipart.MultipartHttpMessageReader)2 MockServerHttpRequest (cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpRequest)2 MockServerHttpResponse (cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpResponse)2