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 stripPrefixFalseAppendsPath() {
    this.routes.addRoute(new ZuulProperties.ZuulRoute("strip", "/strip/**", "strip",
            "http://localhost:" + this.port + "/local", false, false, null));
    this.endpoint.reset();
    ResponseEntity<String> result = new TestRestTemplate().exchange("http://localhost:" + this.port + "/strip",
            HttpMethod.GET, new HttpEntity<>((Void) null), String.class);
    assertEquals(HttpStatus.OK, result.getStatusCode());
    // Prefix not stripped to it goes to /local/strip
    assertEquals("Gotten strip!", result.getBody());
}

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

@Test
public void testNotFoundFromApp() {
    ResponseEntity<String> result = new TestRestTemplate().exchange(
            "http://localhost:" + this.port + "/simple/local/notfound", HttpMethod.GET,
            new HttpEntity<>((Void) null), String.class);
    assertEquals(HttpStatus.NOT_FOUND, result.getStatusCode());
}

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

@Test
public void testNotFoundOnProxy() {
    ResponseEntity<String> result = new TestRestTemplate().exchange(
            "http://localhost:" + this.port + "/myinvalidpath", HttpMethod.GET, new HttpEntity<>((Void) null),
            String.class);
    assertEquals(HttpStatus.NOT_FOUND, result.getStatusCode());
}

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

@Test
public void getSecondLevel() {
    ResponseEntity<String> result = new TestRestTemplate().exchange(
            "http://localhost:" + this.port + "/another/twolevel/local/1", HttpMethod.GET,
            new HttpEntity<>((Void) null), String.class);
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals("Gotten 1!", result.getBody());
}

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

@Test
public void ribbonRouteWithSpace() {
    String uri = "/simple/spa ce";
    this.myErrorController.setUriToMatch(uri);
    ResponseEntity<String> result = new TestRestTemplate().exchange("http://localhost:" + this.port + uri,
            HttpMethod.GET, new HttpEntity<>((Void) null), String.class);
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals("Hello space", result.getBody());
    assertFalse(myErrorController.wasControllerUsed());
}

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

@Test
public void ribbonDeleteWithBody() {
    this.endpoint.reset();
    ResponseEntity<String> result = new TestRestTemplate().exchange(
            "http://localhost:" + this.port + "/simple/deletewithbody", HttpMethod.DELETE,
            new HttpEntity<>("deleterequestbody"), String.class);
    assertEquals(HttpStatus.OK, result.getStatusCode());
    if (supportsDeleteWithBody()) {
        assertEquals("Deleted deleterequestbody", result.getBody());
    } else {//  ww w.j  a v a2 s.  com
        assertEquals("Deleted null", result.getBody());
    }
}

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

@Test
public void ribbonRouteWithNonExistentUri() {
    String uri = "/simple/nonExistent";
    this.myErrorController.setUriToMatch(uri);
    ResponseEntity<String> result = new TestRestTemplate().exchange("http://localhost:" + this.port + uri,
            HttpMethod.GET, new HttpEntity<>((Void) null), String.class);
    assertEquals(HttpStatus.NOT_FOUND, result.getStatusCode());
    assertFalse(myErrorController.wasControllerUsed());
}

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

@Test
public void simpleHostRouteWithSpace() {
    this.routes.addRoute("/self/**", "http://localhost:" + this.port);
    this.endpoint.reset();

    ResponseEntity<String> result = new TestRestTemplate().exchange(
            "http://localhost:" + this.port + "/self/spa ce", HttpMethod.GET, new HttpEntity<>((Void) null),
            String.class);
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals("Hello space", result.getBody());
}

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

@Test
public void simpleHostRouteWithOriginalQueryString() {
    this.routes.addRoute("/self/**", "http://localhost:" + this.port);
    this.endpoint.reset();

    ResponseEntity<String> result = new TestRestTemplate().exchange(
            "http://localhost:" + this.port + "/self/qstring?original=value1&original=value2", HttpMethod.GET,
            new HttpEntity<>((Void) null), String.class);
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals("Received {original=[value1, value2]}", result.getBody());
}

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

@Test
public void simpleHostRouteWithOverriddenQString() {
    this.routes.addRoute("/self/**", "http://localhost:" + this.port);
    this.endpoint.reset();

    ResponseEntity<String> result = new TestRestTemplate().exchange(
            "http://localhost:" + this.port + "/self/qstring?override=true&different=key", HttpMethod.GET,
            new HttpEntity<>((Void) null), String.class);
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals("Received {key=[overridden]}", result.getBody());
}