use of cn.taketoday.http.ReactiveHttpInputMessage in project today-framework by TAKETODAY.
the class BodyExtractorsTests method toMonoVoidAsClientShouldConsumeAndCancel.
@Test
public void toMonoVoidAsClientShouldConsumeAndCancel() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
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.emit(dataBuffer);
}).verifyComplete();
body.assertCancelled();
}
use of cn.taketoday.http.ReactiveHttpInputMessage in project today-framework by TAKETODAY.
the class BodyExtractorsTests method toFluxWithHints.
@Test
public void toFluxWithHints() {
BodyExtractor<Flux<User>, ReactiveHttpInputMessage> extractor = BodyExtractors.toFlux(User.class);
this.hints.put(JSON_VIEW_HINT, SafeToDeserialize.class);
String text = "[{\"username\":\"foo\",\"password\":\"bar\"},{\"username\":\"bar\",\"password\":\"baz\"}]";
byte[] bytes = text.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);
Flux<User> result = extractor.extract(request, this.context);
StepVerifier.create(result).consumeNextWith(user -> {
assertThat(user.getUsername()).isEqualTo("foo");
assertThat(user.getPassword()).isNull();
}).consumeNextWith(user -> {
assertThat(user.getUsername()).isEqualTo("bar");
assertThat(user.getPassword()).isNull();
}).expectComplete().verify();
}
use of cn.taketoday.http.ReactiveHttpInputMessage in project today-framework by TAKETODAY.
the class BodyExtractorsTests method toMonoParameterizedTypeReference.
@Test
public void toMonoParameterizedTypeReference() {
BodyExtractor<Mono<Map<String, String>>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(new TypeReference<Map<String, String>>() {
});
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<Map<String, String>> result = extractor.extract(request, this.context);
Map<String, String> expected = new LinkedHashMap<>();
expected.put("username", "foo");
expected.put("password", "bar");
StepVerifier.create(result).expectNext(expected).expectComplete().verify();
}
use of cn.taketoday.http.ReactiveHttpInputMessage in project today-framework 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();
}
use of cn.taketoday.http.ReactiveHttpInputMessage in project today-framework by TAKETODAY.
the class BodyExtractorsTests method toMonoWithEmptyBodyAndNoContentType.
// SPR-15758
@Test
public void toMonoWithEmptyBodyAndNoContentType() {
BodyExtractor<Mono<Map<String, String>>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(new TypeReference<Map<String, String>>() {
});
MockServerHttpRequest request = MockServerHttpRequest.post("/").body(Flux.empty());
Mono<Map<String, String>> result = extractor.extract(request, this.context);
StepVerifier.create(result).expectComplete().verify();
}
Aggregations