Example usage for org.springframework.boot.test.web.client TestRestTemplate postForEntity

List of usage examples for org.springframework.boot.test.web.client TestRestTemplate postForEntity

Introduction

In this page you can find the example usage for org.springframework.boot.test.web.client TestRestTemplate postForEntity.

Prototype

public <T> ResponseEntity<T> postForEntity(URI url, Object request, Class<T> responseType)
        throws RestClientException 

Source Link

Document

Create a new resource by POSTing the given object to the URL, and returns the response as ResponseEntity .

Usage

From source file:org.springframework.cloud.netflix.zuul.filters.route.support.ZuulProxyTestBase.java

@SuppressWarnings("deprecation")
@Test/*from   w w w.  j  a  v  a2s  .  com*/
public void javascriptEncodedFormParams() {
    TestRestTemplate testRestTemplate = new TestRestTemplate();
    ArrayList<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters
            .addAll(Arrays.asList(new StringHttpMessageConverter(), new NoEncodingFormHttpMessageConverter()));
    testRestTemplate.getRestTemplate().setMessageConverters(converters);

    MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
    map.add("foo", "(bar)");
    ResponseEntity<String> result = testRestTemplate
            .postForEntity("http://localhost:" + this.port + "/simple/local", map, String.class);
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals("Posted [(bar)] and Content-Length was: 13!", result.getBody());
}