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

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

Introduction

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

Prototype

TestRestTemplate

Source Link

Usage

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

@Test
public void patchOnSelfViaSimpleHostRoutingFilter() {
    assumeThat(supportsPatch(), is(true));

    this.routes.addRoute("/self/**", "http://localhost:" + this.port + "/local");
    this.endpoint.reset();

    ResponseEntity<String> result = new TestRestTemplate().exchange("http://localhost:" + this.port + "/self/1",
            HttpMethod.PATCH, new HttpEntity<>("TestPatch"), String.class);
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals("Patched 1!", result.getBody());
}

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

@SuppressWarnings("deprecation")
@Test// w w  w.ja va 2  s.co m
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());
}