Skip to content

Commit

Permalink
add TestRestClient
Browse files Browse the repository at this point in the history
  • Loading branch information
cmonkey committed Mar 8, 2018
1 parent 685cc70 commit 394877b
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/test/java/com/github/cmonkey/webflux/TestRestClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.github.cmonkey.webflux;

import com.github.cmonkey.webflux.entity.User;
import org.junit.Test;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

public class TestRestClient {

@Test
public void testRest(){
final User user = new User();
user.setId(10L);
user.setName("cmonkey");

final WebClient client = WebClient.create("http://localhost:8080/users");

final Mono<User> mono = client.post()
.uri("")
.accept(MediaType.APPLICATION_JSON)
.body(Mono.just(user), User.class)
.exchange()
.flatMap(response -> response.bodyToMono(User.class));

System.out.println(mono.block());
}
}

0 comments on commit 394877b

Please sign in to comment.