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();
}
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();
}
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();
}
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();
}
Aggregations