Java 类org.springframework.boot.test.TestRestTemplate 实例源码

项目:spring_boot    文件:TomcatSSLApplicationTests.java   
@Test
public void testHome() throws Exception {
    SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
            new SSLContextBuilder()
                    .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());

    HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory)
            .build();

    TestRestTemplate testRestTemplate = new TestRestTemplate();
    ((HttpComponentsClientHttpRequestFactory) testRestTemplate.getRequestFactory())
            .setHttpClient(httpClient);
    ResponseEntity<String> entity = testRestTemplate
            .getForEntity("https://localhost:" + this.port, String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertTrue( "Result is not Matched with Server Response",entity.getBody().contains("welcome to the application"));
}
项目:spring-cloud-samples    文件:ApplicationTests.java   
@Test
public void envPostAvailable() {
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().postForEntity(
            "http://localhost:" + port + "/admin/env", form, Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
}
项目:spring_boot    文件:JettyApplicationTests.java   
@Test
public void testCompression() throws Exception {
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Accept-Encoding", "gzip");
    HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);

    RestTemplate restTemplate = new TestRestTemplate();

    ResponseEntity<byte[]> entity = restTemplate.exchange(
            "http://localhost:" + this.port, HttpMethod.GET, requestEntity,
            byte[].class);

    assertEquals(HttpStatus.OK, entity.getStatusCode());

    GZIPInputStream inflater = new GZIPInputStream(
            new ByteArrayInputStream(entity.getBody()));
    try {
        assertEquals("welcome to the application "+System.getProperty("user.name"),
                StreamUtils.copyToString(inflater, Charset.forName("UTF-8")));
    }
    finally {
        inflater.close();
    }
}
项目:spring_boot    文件:TomcatApplicationTests.java   
@Test
public void testCompression() throws Exception {
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Accept-Encoding", "gzip");
    HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);

    RestTemplate restTemplate = new TestRestTemplate();

    ResponseEntity<byte[]> entity = restTemplate.exchange(
            "http://localhost:" + this.port, HttpMethod.GET, requestEntity,
            byte[].class);

    assertEquals(HttpStatus.OK, entity.getStatusCode());

    GZIPInputStream inflater = new GZIPInputStream(
            new ByteArrayInputStream(entity.getBody()));
    try {
        assertEquals("welcome to the application Adarsh",
                StreamUtils.copyToString(inflater, Charset.forName("UTF-8")));
    }
    finally {
        inflater.close();
    }
}
项目:spring_boot    文件:JettyApplicationTests.java   
@Test
public void testWelcome() throws Exception {
    SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
            new SSLContextBuilder()
                    .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());

    HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory)
            .build();

    TestRestTemplate testRestTemplate = new TestRestTemplate();
    ((HttpComponentsClientHttpRequestFactory) testRestTemplate.getRequestFactory())
            .setHttpClient(httpClient);
    ResponseEntity<String> entity = testRestTemplate
            .getForEntity("https://localhost:" + this.port, String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertEquals("welcome to the application "+System.getProperty("user.name"), entity.getBody());
}
项目:tcserver-spring-boot-samples    文件:SampleTomcatSslApplicationTests.java   
@Test
public void testHome() throws Exception {
    SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
            new SSLContextBuilder()
                    .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());

    HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory)
            .build();

    TestRestTemplate testRestTemplate = new TestRestTemplate();
    ((HttpComponentsClientHttpRequestFactory) testRestTemplate.getRequestFactory())
            .setHttpClient(httpClient);
    ResponseEntity<String> entity = testRestTemplate
            .getForEntity("https://localhost:" + this.port, String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertEquals("Hello, world", entity.getBody());
}
项目:tcserver-spring-boot-samples    文件:SampleTomcatSslApplicationTests.java   
@Test
public void testHome() throws Exception {
    SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
            new SSLContextBuilder()
                    .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());

    HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory)
            .build();

    TestRestTemplate testRestTemplate = new TestRestTemplate();
    ((HttpComponentsClientHttpRequestFactory) testRestTemplate.getRequestFactory())
            .setHttpClient(httpClient);
    ResponseEntity<String> entity = testRestTemplate
            .getForEntity("https://localhost:" + this.port, String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertEquals("Hello, world", entity.getBody());
}
项目:contestparser    文件:SampleJettyApplicationTests.java   
@Test
public void testCompression() throws Exception {
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Accept-Encoding", "gzip");
    HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);

    RestTemplate restTemplate = new TestRestTemplate();

    ResponseEntity<byte[]> entity = restTemplate.exchange(
            "http://localhost:" + this.port, HttpMethod.GET, requestEntity,
            byte[].class);

    assertEquals(HttpStatus.OK, entity.getStatusCode());

    GZIPInputStream inflater = new GZIPInputStream(
            new ByteArrayInputStream(entity.getBody()));
    try {
        assertEquals("Hello World",
                StreamUtils.copyToString(inflater, Charset.forName("UTF-8")));
    }
    finally {
        inflater.close();
    }
}
项目:contestparser    文件:SampleMethodSecurityApplicationTests.java   
@Test
public void testDenied() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.set("username", "user");
    form.set("password", "user");
    getCsrf(form, headers);
    ResponseEntity<String> entity = new TestRestTemplate().exchange(
            "http://localhost:" + this.port + "/login", HttpMethod.POST,
            new HttpEntity<MultiValueMap<String, String>>(form, headers),
            String.class);
    assertEquals(HttpStatus.FOUND, entity.getStatusCode());
    String cookie = entity.getHeaders().getFirst("Set-Cookie");
    headers.set("Cookie", cookie);
    ResponseEntity<String> page = new TestRestTemplate().exchange(
            entity.getHeaders().getLocation(), HttpMethod.GET,
            new HttpEntity<Void>(headers), String.class);
    assertEquals(HttpStatus.FORBIDDEN, page.getStatusCode());
    assertTrue("Wrong body (message doesn't match):\n" + entity.getBody(),
            page.getBody().contains("Access denied"));
}
项目:contestparser    文件:SampleJettySslApplicationTests.java   
@Test
public void testHome() throws Exception {
    SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
            new SSLContextBuilder()
                    .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());

    HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory)
            .build();

    TestRestTemplate testRestTemplate = new TestRestTemplate();
    ((HttpComponentsClientHttpRequestFactory) testRestTemplate.getRequestFactory())
            .setHttpClient(httpClient);
    ResponseEntity<String> entity = testRestTemplate
            .getForEntity("https://localhost:" + this.port, String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertEquals("Hello World", entity.getBody());
}
项目:contestparser    文件:SampleJetty93ApplicationTests.java   
@Test
public void testCompression() throws Exception {
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Accept-Encoding", "gzip");
    HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);
    RestTemplate restTemplate = new TestRestTemplate();
    ResponseEntity<byte[]> entity = restTemplate.exchange(
            "http://localhost:" + this.port, HttpMethod.GET, requestEntity,
            byte[].class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    GZIPInputStream inflater = new GZIPInputStream(
            new ByteArrayInputStream(entity.getBody()));
    try {
        assertEquals("Hello World",
                StreamUtils.copyToString(inflater, Charset.forName("UTF-8")));
    }
    finally {
        inflater.close();
    }
}
项目:tcserver-spring-boot-samples    文件:SampleTomcatApplicationTests.java   
@Test
public void testCompression() throws Exception {
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Accept-Encoding", "gzip");
    HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);
    RestTemplate restTemplate = new TestRestTemplate();
    ResponseEntity<byte[]> entity = restTemplate.exchange(
            "http://localhost:" + this.port, HttpMethod.GET, requestEntity,
            byte[].class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    GZIPInputStream inflater = new GZIPInputStream(
            new ByteArrayInputStream(entity.getBody()));
    try {
        assertEquals("Hello World",
                StreamUtils.copyToString(inflater, Charset.forName("UTF-8")));
    }
    finally {
        inflater.close();
    }
}
项目:contestparser    文件:SampleActuatorApplicationTests.java   
@Test
public void testMetricsIsSecure() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate()
            .getForEntity("http://localhost:" + this.port + "/metrics", Map.class);
    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
    entity = new TestRestTemplate()
            .getForEntity("http://localhost:" + this.port + "/metrics/", Map.class);
    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
    entity = new TestRestTemplate().getForEntity(
            "http://localhost:" + this.port + "/metrics/foo", Map.class);
    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
    entity = new TestRestTemplate().getForEntity(
            "http://localhost:" + this.port + "/metrics.json", Map.class);
    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
}
项目:java-webapp-security-examples    文件:WebSecurityTests.java   
@Test
public void testDenied() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Collections.singletonList(MediaType.TEXT_HTML));
    MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
    form.set("username", "admin");
    form.set("password", "admin");
    getCsrf(form, headers);
    ResponseEntity<String> entity = new TestRestTemplate().exchange(
            "http://localhost:" + this.port + "/login", HttpMethod.POST,
            new HttpEntity<>(form, headers),
            String.class);
    assertEquals(HttpStatus.FOUND, entity.getStatusCode());
    String cookie = entity.getHeaders().getFirst("Set-Cookie");
    headers.set("Cookie", cookie);
    ResponseEntity<String> page = new TestRestTemplate().exchange(entity.getHeaders()
                    .getLocation(), HttpMethod.GET, new HttpEntity<Void>(headers),
            String.class);
    assertEquals(HttpStatus.OK, page.getStatusCode());
    cookie = entity.getHeaders().getFirst("Set-Cookie");
    assertTrue(cookie.contains("remember-me"));
    assertTrue("Wrong body (message doesn't match):\n" + entity.getBody(), page
            .getBody().contains("Invalid username and password"));
}
项目:contestparser    文件:SampleActuatorApplicationTests.java   
@Test
public void testTrace() throws Exception {
    new TestRestTemplate().getForEntity("http://localhost:" + this.port + "/health",
            String.class);
    @SuppressWarnings("rawtypes")
    ResponseEntity<List> entity = new TestRestTemplate("user", getPassword())
            .getForEntity("http://localhost:" + this.port + "/trace", List.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    @SuppressWarnings("unchecked")
    List<Map<String, Object>> list = entity.getBody();
    Map<String, Object> trace = list.get(list.size() - 1);
    @SuppressWarnings("unchecked")
    Map<String, Object> map = (Map<String, Object>) ((Map<String, Object>) ((Map<String, Object>) trace
            .get("info")).get("headers")).get("response");
    assertEquals("200", map.get("status"));
}
项目:spring-cloud-samples    文件:ApplicationTests.java   
@Test
public void configurationAvailable() {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
            "http://localhost:" + port + "/app/cloud", Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
}
项目:spring-cloud-samples    文件:ApplicationTests.java   
@Test
public void envPostAvailable() {
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().postForEntity(
            "http://localhost:" + port + "/admin/env", form, Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
}
项目:spring-cloud-samples    文件:ApplicationTests.java   
@Test
public void configurationAvailable() {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
            "http://localhost:" + port + "/app/cloud", Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
}
项目:spring-cloud-samples    文件:ApplicationTests.java   
@Test
public void envPostAvailable() {
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().postForEntity(
            "http://localhost:" + port + "/admin/env", form, Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
}
项目:spring-cloud-samples    文件:ApplicationTests.java   
@Test
public void configurationAvailable() {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
            "http://localhost:" + port + "/app/cloud", Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
}
项目:spring-cloud-samples    文件:ApplicationTests.java   
@Test
public void envPostAvailable() {
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().postForEntity(
            "http://localhost:" + port + "/admin/env", form, Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
}
项目:spring-cloud-samples    文件:ApplicationTests.java   
@Test
public void configurationAvailable() {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
            "http://localhost:" + port + "/app/cloud", Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
}
项目:spring-cloud-samples    文件:ApplicationTests.java   
@Test
public void envPostAvailable() {
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().postForEntity(
            "http://localhost:" + port + "/admin/env", form, Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
}
项目:spring-cloud-samples    文件:ApplicationTests.java   
@Test
public void configurationAvailable() {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
            "http://localhost:" + port + "/app/cloud", Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
}
项目:stateless-shiro    文件:UserControllerTest.java   
@Test
public void test_authenticate_success() throws JsonProcessingException {
    // authenticate
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    headers.setContentType(MediaType.APPLICATION_JSON);
    final String json = new ObjectMapper().writeValueAsString(
            new UsernamePasswordToken(USER_EMAIL, USER_PWD));
    System.out.println(json);
    final ResponseEntity<String> response = new TestRestTemplate(
            HttpClientOption.ENABLE_COOKIES).exchange(BASE_URL.concat("/auth"),
            HttpMethod.POST, new HttpEntity<>(json, headers), String.class);
    assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
}
项目:stateless-shiro    文件:UserControllerTest.java   
@Test
public void test_authenticate_failure() throws JsonProcessingException {
    // authenticate
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    headers.setContentType(MediaType.APPLICATION_JSON);
    final String json = new ObjectMapper().writeValueAsString(
            new UsernamePasswordToken(USER_EMAIL, "wrong password"));
    System.out.println(json);
    final ResponseEntity<String> response = new TestRestTemplate(
            HttpClientOption.ENABLE_COOKIES).exchange(BASE_URL.concat("/auth"),
            HttpMethod.POST, new HttpEntity<>(json, headers), String.class);
    assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
}
项目:referenceapp    文件:ApplicationTests.java   
@Test
public void loginSucceeds() {
    RestTemplate template = new TestRestTemplate("user", "foo");
    ResponseEntity<String> response = template.getForEntity("http://localhost:" + port
            + "/user", String.class);
    assertEquals(HttpStatus.OK, response.getStatusCode());
}
项目:spring_boot    文件:JettyApplicationTests.java   
@Test
public void testHome() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate()
            .getForEntity("http://localhost:" + this.port, String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertEquals("welcome to the application "+System.getProperty("user.name"), entity.getBody());
}
项目:spring_boot    文件:TomcatApplicationTests.java   
@Test
public void testHome() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate()
            .getForEntity("http://localhost:" + this.port, String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertEquals("welcome to the application Adarsh", entity.getBody());
}
项目:spring_boot    文件:NonAutoConfigurationTomcatApplicationDriverTests.java   
@Test
public void testHome() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate()
            .getForEntity("http://localhost:" + this.port, String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertEquals("welcome to the application Adarsh", entity.getBody());
}
项目:acme-solution    文件:ProfileApplicationTest.java   
@Before
public void setup() {

    try {
        this.base = new URL("http://" + this.hostname + ":" + this.port + "/");
        this.restTemplate = new TestRestTemplate();

    } catch (MalformedURLException exception) {
        log.error("Could not open a test server socket based on the hostname and port provided");
        log.trace("Test server socket couldn't be formed", exception);
        Assert.fail();
    }
}
项目:katharsis-framework    文件:SpringBootSimpleExampleApplicationTests.java   
@Test
public void testTestEndpointWithQueryParams() throws Exception {
    TestRestTemplate testRestTemplate = new TestRestTemplate();
    ResponseEntity<String> response = testRestTemplate
            .getForEntity("http://localhost:" + this.port + "/api/tasks?filter[tasks][name]=John", String.class);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertThatJson(response.getBody()).node("data[0].attributes.name").isStringEqualTo("John");
    assertThatJson(response.getBody()).node("data[0].links.self").isStringEqualTo("http://localhost:8080/api/tasks/1");
    assertThatJson(response.getBody()).node("meta.name").isStringEqualTo("meta information");
}
项目:katharsis-framework    文件:SpringBootSimpleExampleApplicationTests.java   
@Test
public void testTestCustomEndpoint() throws Exception {
    TestRestTemplate testRestTemplate = new TestRestTemplate();
    ResponseEntity<String> response = testRestTemplate
            .getForEntity("http://localhost:" + this.port + "/api/custom", String.class);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertEquals(response.getBody(), "hello");
}
项目:spring-boot-jsp-hot-reload-demo    文件:ApplicationTests.java   
@Test
public void slashFooReturnsFoo() {
    ResponseEntity<String> entity = new TestRestTemplate()
            .getForEntity("http://localhost:" + this.port + "/amigos", String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertEquals("si", entity.getBody());
}
项目:jim    文件:TopicServiceTest.java   
@Before
public void init() throws TopicRpcException {
    restTemplate = new TestRestTemplate();
    request = TopicRequest.build(operatorId, "sfa", "hengda", TopicOwnerType.GROUP, TopicType.values());

    // 自定义数据
    Map<String, List<String>> headers = Maps.newHashMap();
    headers.put("appId", Lists.newArrayList("sfa"));
    headers.put("tenantId", Lists.newArrayList("hengda"));
    headers.put("operatorId", Lists.newArrayList(operatorId.toString()));
    CommHeaderInterceptor headerInterceptor = new CommHeaderInterceptor(headers);
    restTemplate.getInterceptors().add(headerInterceptor);

    this.testDeleteTopics();
}
项目:jim    文件:OfflineMgServiceTest.java   
@Before
public void init() {
    restTemplate = new TestRestTemplate();

    // 自定义数据
    Map<String, List<String>> headers = Maps.newHashMap();
    headers.put("appId", Lists.newArrayList("sfa"));
    headers.put("tenantId", Lists.newArrayList("hengda"));
    headers.put("operatorId", Lists.newArrayList("1"));
    CommHeaderInterceptor headerInterceptor = new CommHeaderInterceptor(headers);
    restTemplate.getInterceptors().add(headerInterceptor);
}
项目:xmltype-jpa    文件:ApplicationTest.java   
@Test
public void persist_order_successfully() throws IOException {
    Order order = JAXB.unmarshal(new ClassPathResource("order.xml").getFile(), Order.class);

    RestTemplate restTemplate = new TestRestTemplate();
    ResponseEntity<OrderEntity> response = restTemplate.postForEntity(
            format("http://localhost:%d/orders", port),
            order,
            OrderEntity.class);

    assertThat("Placing order did not return 200 OK", response.getStatusCode(), equalTo(OK));
    assertNotNull("Persisted order Id cannot be null", response.getBody().getId());
}
项目:api-ai-java-webhook    文件:HelloWorldConfigurationTests.java   
@Test
public void testInfo() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
            "http://localhost:" + this.mgt + "/info", Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
}
项目:cassandra-unit-spring-demo    文件:AbstractEmbeddedCassandraTest.java   
@PostConstruct
public void init() {
    DefaultUriTemplateHandler handler = new DefaultUriTemplateHandler();
    handler.setBaseUrl(url + ":" + port);
    handler.setParsePath(true);

    client = new TestRestTemplate();
    client.setUriTemplateHandler(handler);
}
项目:spring-boot-jade    文件:AutoApplicationTests.java   
@Test
public void testHomePage() throws Exception {
    String body = new TestRestTemplate().getForObject("http://localhost:" + port,
            String.class);
    assertTrue(body.contains("<title>Hello App</title>"));
    assertTrue(body.contains("<p>Hello World</p>"));
}